|
| 1 | +const chai = require("chai"); |
| 2 | +const { expect } = chai; |
| 3 | +const cleanDb = require("../../utils/cleanDb"); |
| 4 | +const profileDiffsQuery = require("../../../models/profileDiffs"); |
| 5 | +const getProfileDiffs = require("../../fixtures/profileDiffs/profileDiffs"); |
| 6 | + |
| 7 | +describe("profileDiffs", function () { |
| 8 | + afterEach(async function () { |
| 9 | + await cleanDb(); |
| 10 | + }); |
| 11 | + |
| 12 | + describe("fetchProfileDiffUnobfuscated", function () { |
| 13 | + it("should successfully return profileDiffs", async function () { |
| 14 | + const profileDiffs = getProfileDiffs(); |
| 15 | + const profileDiffId = await profileDiffsQuery.add(profileDiffs[1]); |
| 16 | + const diff = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId); |
| 17 | + expect(diff).haveOwnProperty("id"); |
| 18 | + expect(diff.profileDiffExists).to.equal(true); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should not return profileDiffs for invalid id", async function () { |
| 22 | + const profileDiffs = getProfileDiffs(); |
| 23 | + await profileDiffsQuery.add(profileDiffs[0]); |
| 24 | + const profileDiffId = "invalid-id"; |
| 25 | + const diff = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId); |
| 26 | + expect(diff.profileDiffExists).to.equal(false); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should return profileDiffs with unobfuscated email and phone", async function () { |
| 30 | + const profileDiffs = getProfileDiffs(); |
| 31 | + const profileDiffId = await profileDiffsQuery.add(profileDiffs[0]); |
| 32 | + const diff = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId); |
| 33 | + expect(diff.phone).to.equal(profileDiffs[0].phone); |
| 34 | + expect(diff.email).to.equal(profileDiffs[0].email); |
| 35 | + }); |
| 36 | + |
| 37 | + it("it should throw an error on undefined profileDiff Id", async function () { |
| 38 | + const profileDiffs = getProfileDiffs(); |
| 39 | + await profileDiffsQuery.add(profileDiffs[0]); |
| 40 | + let error = ""; |
| 41 | + try { |
| 42 | + await profileDiffsQuery.fetchProfileDiffUnobfuscated(undefined); |
| 43 | + } catch (err) { |
| 44 | + error = err; |
| 45 | + } |
| 46 | + Object.freeze(error); |
| 47 | + expect(error).to.be.an("Error"); |
| 48 | + expect(error.message).to.be.equal( |
| 49 | + 'Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string.' |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + it("it should throw an error on null profileDiff Id", async function () { |
| 54 | + const profileDiffs = getProfileDiffs(); |
| 55 | + await profileDiffsQuery.add(profileDiffs[0]); |
| 56 | + let error = ""; |
| 57 | + try { |
| 58 | + await profileDiffsQuery.fetchProfileDiffUnobfuscated(null); |
| 59 | + } catch (err) { |
| 60 | + error = err; |
| 61 | + } |
| 62 | + Object.freeze(error); |
| 63 | + expect(error).to.be.an("Error"); |
| 64 | + expect(error.message).to.be.equal( |
| 65 | + 'Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string.' |
| 66 | + ); |
| 67 | + }); |
| 68 | + |
| 69 | + it("it should throw an error on passing profileDiff Id as empty string", async function () { |
| 70 | + const profileDiffs = getProfileDiffs(); |
| 71 | + await profileDiffsQuery.add(profileDiffs[0]); |
| 72 | + let error = ""; |
| 73 | + try { |
| 74 | + await profileDiffsQuery.fetchProfileDiffUnobfuscated(""); |
| 75 | + } catch (err) { |
| 76 | + error = err; |
| 77 | + } |
| 78 | + Object.freeze(error); |
| 79 | + expect(error).to.be.an("Error"); |
| 80 | + expect(error.message).to.be.equal( |
| 81 | + 'Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string.' |
| 82 | + ); |
| 83 | + }); |
| 84 | + |
| 85 | + it("it should correctly fetch deeply nested profileDiff", async function () { |
| 86 | + const profileDiff = { |
| 87 | + level1: { |
| 88 | + level2: { |
| 89 | + level3: { |
| 90 | + level4: { |
| 91 | + level5: { |
| 92 | + level6: { |
| 93 | + level7: { |
| 94 | + level8: { |
| 95 | + level9: { |
| 96 | + level10: "nested-random-diff", |
| 97 | + }, |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + }, |
| 102 | + }, |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + }; |
| 107 | + const profileDiffId = await profileDiffsQuery.add(profileDiff); |
| 108 | + const diff = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId); |
| 109 | + expect(diff) |
| 110 | + .to.have.nested.property("level1.level2.level3.level4.level5.level6.level7.level8.level9.level10") |
| 111 | + .that.equals("nested-random-diff"); |
| 112 | + }); |
| 113 | + }); |
| 114 | +}); |
0 commit comments