@htilabs/platform-common-models 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -1
- package/dist/{index-Pt82NxQg.d.cts → index-BTqHP4DM.d.cts} +1 -1
- package/dist/{index-ClTjjJ_S.d.ts → index-Dr6GBCoY.d.ts} +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/models/index.d.cts +2 -2
- package/dist/models/index.d.ts +2 -2
- package/dist/points-of-contact/index.cjs +135 -16
- package/dist/points-of-contact/index.cjs.map +1 -1
- package/dist/points-of-contact/index.d.cts +128 -5
- package/dist/points-of-contact/index.d.ts +128 -5
- package/dist/points-of-contact/index.js +134 -16
- package/dist/points-of-contact/index.js.map +1 -1
- package/dist/schemas/index.d.cts +25 -25
- package/dist/schemas/index.d.ts +25 -25
- package/package.json +1 -1
- package/src/pointsOfContact/__tests__/pointsOfContact.test.ts +447 -0
- package/src/pointsOfContact/__tests__/reader.mongo.test.ts +211 -0
- package/src/pointsOfContact/index.ts +3 -1
- package/src/pointsOfContact/readRules.ts +8 -1
- package/src/pointsOfContact/reader.ts +353 -37
- package/src/pointsOfContact/vocabulary.ts +4 -1
- package/dist/{cvcEntry-Asg7mxjB.d.cts → cvcEntry-BqAGctqK.d.cts} +8 -8
- package/dist/{cvcEntry-Asg7mxjB.d.ts → cvcEntry-BqAGctqK.d.ts} +8 -8
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* three views, the strict row parse, and the raw-driver reads over an
|
|
5
5
|
* in-memory double, including the Referrals (magic link) partner rollup.
|
|
6
6
|
*/
|
|
7
|
+
import { inspect } from "node:util";
|
|
7
8
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
8
9
|
|
|
9
10
|
import preferredContactMethodSot from "../../cvcs/preferredContactMethod.v1.0.0.json" with { type: "json" };
|
|
@@ -43,6 +44,7 @@ import {
|
|
|
43
44
|
preferredContactEntry,
|
|
44
45
|
preferredEmail,
|
|
45
46
|
preferredPhone,
|
|
47
|
+
resolveMagicLinkRecipients,
|
|
46
48
|
toNetworkView,
|
|
47
49
|
toOwnerView,
|
|
48
50
|
toStewardView,
|
|
@@ -433,6 +435,14 @@ describe("reads", () => {
|
|
|
433
435
|
status: "confirmed",
|
|
434
436
|
is_confidential: { $ne: true },
|
|
435
437
|
},
|
|
438
|
+
// pl-iza: the confidential holders' own query, issued after the visible one.
|
|
439
|
+
{
|
|
440
|
+
$or: [{ agency_id: "agency-a" }, { org_id: "org-a" }],
|
|
441
|
+
purposes: REF,
|
|
442
|
+
active: true,
|
|
443
|
+
status: "confirmed",
|
|
444
|
+
is_confidential: true,
|
|
445
|
+
},
|
|
436
446
|
{
|
|
437
447
|
subject_type: "program",
|
|
438
448
|
subject_id: "prog-1",
|
|
@@ -825,3 +835,440 @@ describe("listReferralContactsForPartner: the adder's own pending adds (Nate 202
|
|
|
825
835
|
).rejects.toThrow(TypeError);
|
|
826
836
|
});
|
|
827
837
|
});
|
|
838
|
+
|
|
839
|
+
describe("confidential Referrals (magic link) holders (pl-iza, CVC-338)", () => {
|
|
840
|
+
const ADVOCATE = "auth0|advocate";
|
|
841
|
+
/** A confidential, confirmed, tagged holder on agency-a. */
|
|
842
|
+
const conf = (over: Partial<PointOfContactDoc> & { email?: string | null }) =>
|
|
843
|
+
doc({ is_confidential: true, purposes: [REF], display_name: "Hidden", ...over });
|
|
844
|
+
const SECRETS = [
|
|
845
|
+
"hidden-agency@a.org",
|
|
846
|
+
"hidden-prog@a.org",
|
|
847
|
+
"hidden-team@a.org",
|
|
848
|
+
"hidden-loc@a.org",
|
|
849
|
+
"hidden-svc@a.org",
|
|
850
|
+
"hidden-org@a.org",
|
|
851
|
+
"seat@a.org",
|
|
852
|
+
];
|
|
853
|
+
const BOTH = { agency_id: "agency-a", org_id: "org-a" };
|
|
854
|
+
|
|
855
|
+
function putEverySubject() {
|
|
856
|
+
put(
|
|
857
|
+
doc({ id: "poc-visible", purposes: [REF], email: "visible@a.org", display_name: "Visible" }),
|
|
858
|
+
conf({ id: "poc-c-agency", email: "hidden-agency@a.org" }),
|
|
859
|
+
conf({ id: "poc-c-prog", subject_type: "program", subject_id: "prog-1", email: "hidden-prog@a.org" }),
|
|
860
|
+
conf({ id: "poc-c-team", subject_type: "team", subject_id: "intake", email: "hidden-team@a.org" }),
|
|
861
|
+
conf({ id: "poc-c-loc", subject_type: "location", subject_id: "loc-1", email: "hidden-loc@a.org" }),
|
|
862
|
+
conf({ id: "poc-c-svc", subject_type: "service", subject_id: "svc-1", email: "hidden-svc@a.org" }),
|
|
863
|
+
conf({ id: "poc-c-org", subject_type: "org", subject_id: "org-a", agency_id: null, email: "hidden-org@a.org" }),
|
|
864
|
+
conf({ id: "poc-c-seat", user_id: "u-seat", email: null, display_name: null }),
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/** Confidential holders at these addresses, obtained the only way a caller can: the send read. */
|
|
869
|
+
async function holdersAt(addresses: string[]) {
|
|
870
|
+
rows.length = 0;
|
|
871
|
+
put(...addresses.map((email, i) => conf({ id: `poc-h-${i}`, email, display_name: `H${i}` })));
|
|
872
|
+
const send = await resolveMagicLinkRecipients(db, { agency_id: "agency-a" }, { resolveSeats });
|
|
873
|
+
expect(send.confidential.count).toBe(addresses.length);
|
|
874
|
+
return send.confidential;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
it("counts distinct confidential holders across agency, program, team, location, service and org subjects, seat-linked included", async () => {
|
|
878
|
+
putEverySubject();
|
|
879
|
+
const both = await listReferralContactsForPartner(db, BOTH, { resolveSeats });
|
|
880
|
+
expect(both.recipients.map((r) => r.id)).toEqual(["poc-visible"]);
|
|
881
|
+
expect(both.confidentialCount).toBe(7);
|
|
882
|
+
expect(both.unreachable).toEqual([]);
|
|
883
|
+
// The diagnostic is the send list's only, never on the UI-facing result.
|
|
884
|
+
expect(both).not.toHaveProperty("confidentialUnreachableCount");
|
|
885
|
+
// Agency-keyed only: the org-only holder (agency_id null) is not on the agency rollup.
|
|
886
|
+
const byAgency = await listReferralContactsForPartner(db, { agency_id: "agency-a" }, { resolveSeats });
|
|
887
|
+
expect(byAgency.confidentialCount).toBe(6);
|
|
888
|
+
const send = await resolveMagicLinkRecipients(db, BOTH, { resolveSeats });
|
|
889
|
+
expect(send.recipients.map((r) => r.id)).toEqual(["poc-visible"]);
|
|
890
|
+
expect(send.confidential.count).toBe(7);
|
|
891
|
+
expect(send.confidentialUnreachableCount).toBe(0);
|
|
892
|
+
const got: string[] = [];
|
|
893
|
+
const r = await send.confidential.deliver(async (to) => void got.push(to));
|
|
894
|
+
// Stored reading order (agency, org, program, team, location, service; the unnamed
|
|
895
|
+
// seat row before "Hidden"), the seat's email lowercased.
|
|
896
|
+
expect(got).toEqual([
|
|
897
|
+
"seat@a.org",
|
|
898
|
+
"hidden-agency@a.org",
|
|
899
|
+
"hidden-org@a.org",
|
|
900
|
+
"hidden-prog@a.org",
|
|
901
|
+
"hidden-team@a.org",
|
|
902
|
+
"hidden-loc@a.org",
|
|
903
|
+
"hidden-svc@a.org",
|
|
904
|
+
]);
|
|
905
|
+
expect(r).toEqual({ count: 7, delivered: 7, failed: 0, overflow: 0, firstErrorName: null });
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
it("a partner whose only holders are confidential has a holder and can be sent to", async () => {
|
|
909
|
+
put(conf({ id: "poc-only", email: "only@a.org" }));
|
|
910
|
+
const list = await listReferralContactsForPartner(db, { agency_id: "agency-a" }, { resolveSeats });
|
|
911
|
+
expect(list.recipients.length + list.confidentialCount).toBeGreaterThan(0);
|
|
912
|
+
const send = await resolveMagicLinkRecipients(db, { agency_id: "agency-a" }, { resolveSeats });
|
|
913
|
+
expect(send.recipients).toEqual([]);
|
|
914
|
+
expect(send.confidential.count).toBe(1);
|
|
915
|
+
const got: string[] = [];
|
|
916
|
+
expect((await send.confidential.deliver((to) => void got.push(to))).delivered).toBe(1);
|
|
917
|
+
expect(got).toEqual(["only@a.org"]);
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
it("pending, inactive and untagged confidential rows are not counted; unreachable ones are a count, never ids", async () => {
|
|
921
|
+
put(
|
|
922
|
+
conf({ id: "poc-c-pending", email: "p@a.org", status: "pending" }),
|
|
923
|
+
conf({ id: "poc-c-pending-inapp", email: "q@a.org", status: "pending", origin: "in_app", createdBy: ADVOCATE }),
|
|
924
|
+
conf({ id: "poc-c-gone", email: "g@a.org", active: false }),
|
|
925
|
+
conf({ id: "poc-c-untagged", email: "u@a.org", purposes: ["BILLING"] }),
|
|
926
|
+
conf({ id: "poc-c-other-partner", agency_id: "agency-b", subject_id: "agency-b", org_id: "org-b", email: "b@b.org" }),
|
|
927
|
+
conf({ id: "poc-c-nomail", user_id: "u-noemail", email: null, display_name: null }),
|
|
928
|
+
conf({ id: "poc-c-unresolved", user_id: "u-missing", email: null, display_name: null }),
|
|
929
|
+
doc({ id: "poc-v-nomail", user_id: "u-noemail", email: null, display_name: null, purposes: [REF] }),
|
|
930
|
+
);
|
|
931
|
+
const r = await listReferralContactsForPartner(
|
|
932
|
+
db,
|
|
933
|
+
{ agency_id: "agency-a" },
|
|
934
|
+
{ resolveSeats, includeOwnPendingFor: ADVOCATE },
|
|
935
|
+
);
|
|
936
|
+
expect(r.confidentialCount).toBe(0);
|
|
937
|
+
expect(r.recipients).toEqual([]);
|
|
938
|
+
// `unreachable` is visible-only (as before pl-iza); the confidential ones are a
|
|
939
|
+
// server-side count on the send list only.
|
|
940
|
+
expect(r.unreachable).toEqual(["poc-v-nomail"]);
|
|
941
|
+
expect(JSON.stringify(r)).not.toContain("poc-c-");
|
|
942
|
+
const send = await resolveMagicLinkRecipients(db, { agency_id: "agency-a" }, { resolveSeats });
|
|
943
|
+
expect([send.unreachable, send.confidentialUnreachableCount, send.confidential.count]).toEqual([
|
|
944
|
+
["poc-v-nomail"],
|
|
945
|
+
2,
|
|
946
|
+
0,
|
|
947
|
+
]);
|
|
948
|
+
let calls = 0;
|
|
949
|
+
expect(await send.confidential.deliver(() => void calls++)).toEqual({
|
|
950
|
+
count: 0,
|
|
951
|
+
delivered: 0,
|
|
952
|
+
failed: 0,
|
|
953
|
+
overflow: 0,
|
|
954
|
+
firstErrorName: null,
|
|
955
|
+
});
|
|
956
|
+
expect(calls).toBe(0);
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
it("a corrupt confidential row is skipped and counted, never thrown or named; visible sends go on", async () => {
|
|
960
|
+
put(
|
|
961
|
+
doc({ id: "poc-visible", purposes: [REF], email: "visible@a.org", display_name: "Visible" }),
|
|
962
|
+
conf({ id: "poc-c-good", email: "good@a.org" }),
|
|
963
|
+
);
|
|
964
|
+
rows.push({ ...conf({ id: "poc-c-corrupt-jane-roe", email: "jane@a.org" }), origin: "bogus" });
|
|
965
|
+
rows.push({ ...conf({ id: "poc-c-no-emails-list" }), emails: "not-a-list" });
|
|
966
|
+
const list = await listReferralContactsForPartner(db, { agency_id: "agency-a" }, { resolveSeats });
|
|
967
|
+
expect(list.recipients.map((r) => r.id)).toEqual(["poc-visible"]);
|
|
968
|
+
expect(list.confidentialCount).toBe(1);
|
|
969
|
+
expect(list.unreachable).toEqual([]);
|
|
970
|
+
const send = await resolveMagicLinkRecipients(db, { agency_id: "agency-a" }, { resolveSeats });
|
|
971
|
+
expect(send.confidentialUnreachableCount).toBe(2);
|
|
972
|
+
const got: string[] = [];
|
|
973
|
+
const sent = await send.confidential.deliver(async (to) => void got.push(to));
|
|
974
|
+
expect(sent).toMatchObject({ delivered: 1 });
|
|
975
|
+
expect(got).toEqual(["good@a.org"]);
|
|
976
|
+
const text = JSON.stringify(list) + JSON.stringify(send) + inspect(send, { depth: null });
|
|
977
|
+
for (const s of ["corrupt", "jane", "no-emails-list"]) expect(text).not.toContain(s);
|
|
978
|
+
// A corrupt VISIBLE row still fails loudly (unchanged): its id is not secret.
|
|
979
|
+
rows.push({ ...doc({ id: "poc-v-bad", purposes: [REF] }), origin: "bogus" });
|
|
980
|
+
await expect(listReferralContactsForPartner(db, { agency_id: "agency-a" }, { resolveSeats })).rejects.toThrow(
|
|
981
|
+
PointOfContactShapeError,
|
|
982
|
+
);
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
it("dedupes among confidential holders ONLY: a visible, pending or typed overlap never moves the count", async () => {
|
|
986
|
+
put(
|
|
987
|
+
doc({ id: "poc-visible", purposes: [REF], email: "shared@a.org", display_name: "Visible" }),
|
|
988
|
+
conf({ id: "poc-c-shared", email: "shared@a.org" }), // a visible row also reaches it: still counted
|
|
989
|
+
conf({ id: "poc-c-one", email: "one@a.org" }),
|
|
990
|
+
conf({ id: "poc-c-one-again", subject_type: "program", subject_id: "prog-1", email: "one@a.org" }),
|
|
991
|
+
conf({ id: "poc-c-probe", email: "probe@a.org" }),
|
|
992
|
+
doc({
|
|
993
|
+
id: "poc-mine",
|
|
994
|
+
purposes: [REF],
|
|
995
|
+
email: "probe@a.org", // the advocate's own pending add of the same address
|
|
996
|
+
display_name: "Mine",
|
|
997
|
+
status: "pending",
|
|
998
|
+
origin: "in_app",
|
|
999
|
+
added_in_app: "thread",
|
|
1000
|
+
confirmed_by: null,
|
|
1001
|
+
confirmed_at: null,
|
|
1002
|
+
createdBy: ADVOCATE,
|
|
1003
|
+
}),
|
|
1004
|
+
);
|
|
1005
|
+
const without = await listReferralContactsForPartner(db, { agency_id: "agency-a" }, { resolveSeats });
|
|
1006
|
+
const withPending = await listReferralContactsForPartner(
|
|
1007
|
+
db,
|
|
1008
|
+
{ agency_id: "agency-a" },
|
|
1009
|
+
{ resolveSeats, includeOwnPendingFor: ADVOCATE },
|
|
1010
|
+
);
|
|
1011
|
+
expect(without.confidentialCount).toBe(3);
|
|
1012
|
+
// The own-pending add is listed, and the count does NOT drop (no oracle).
|
|
1013
|
+
expect(withPending.recipients.map((r) => [r.id, r.pending ?? false])).toEqual([
|
|
1014
|
+
["poc-visible", false],
|
|
1015
|
+
["poc-mine", true],
|
|
1016
|
+
]);
|
|
1017
|
+
expect(withPending.confidentialCount).toBe(3);
|
|
1018
|
+
// Every overlap is sent twice: once as a visible pick, once to the holder.
|
|
1019
|
+
const send = await resolveMagicLinkRecipients(
|
|
1020
|
+
db,
|
|
1021
|
+
{ agency_id: "agency-a" },
|
|
1022
|
+
{ resolveSeats, includeOwnPendingFor: ADVOCATE },
|
|
1023
|
+
);
|
|
1024
|
+
const got: string[] = [];
|
|
1025
|
+
const r = await send.confidential.deliver(async (to) => void got.push(to));
|
|
1026
|
+
expect(got).toEqual(["one@a.org", "probe@a.org", "shared@a.org"]);
|
|
1027
|
+
expect(r).toEqual({ count: 3, delivered: 3, failed: 0, overflow: 0, firstErrorName: null });
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
it("the count does not change when a visible confirmed row with a holder's address appears", async () => {
|
|
1031
|
+
put(
|
|
1032
|
+
conf({ id: "poc-c-1", email: "secret@a.org" }),
|
|
1033
|
+
conf({ id: "poc-c-2", email: "other@a.org" }),
|
|
1034
|
+
doc({ id: "poc-v-seat", user_id: "u-pad", email: null, display_name: null, purposes: [REF] }),
|
|
1035
|
+
doc({
|
|
1036
|
+
id: "poc-mine",
|
|
1037
|
+
purposes: [REF],
|
|
1038
|
+
email: "secret@a.org",
|
|
1039
|
+
display_name: "Mine",
|
|
1040
|
+
status: "pending",
|
|
1041
|
+
origin: "in_app",
|
|
1042
|
+
added_in_app: "thread",
|
|
1043
|
+
confirmed_by: null,
|
|
1044
|
+
confirmed_at: null,
|
|
1045
|
+
createdBy: ADVOCATE,
|
|
1046
|
+
}),
|
|
1047
|
+
);
|
|
1048
|
+
let padEmail = "pad@a.org";
|
|
1049
|
+
const seats = async () => new Map([["u-pad", { email: padEmail, phone: null, name: "Pad" }]]);
|
|
1050
|
+
const count = async () =>
|
|
1051
|
+
(await listReferralContactsForPartner(db, { agency_id: "agency-a" }, { resolveSeats: seats })).confidentialCount;
|
|
1052
|
+
expect(await count()).toBe(2);
|
|
1053
|
+
// A steward confirms the advocate's add: it is now a visible confirmed recipient.
|
|
1054
|
+
const mine = rows.find((r) => r.id === "poc-mine")!;
|
|
1055
|
+
Object.assign(mine, { status: "confirmed", confirmed_by: "steward", confirmed_at: "2026-10-16T00:00:00.000Z" });
|
|
1056
|
+
const after = await listReferralContactsForPartner(db, { agency_id: "agency-a" }, { resolveSeats: seats });
|
|
1057
|
+
expect(after.recipients.map((r) => r.email)).toContain("secret@a.org");
|
|
1058
|
+
expect(after.confidentialCount).toBe(2);
|
|
1059
|
+
// A visible seat's email is edited to match the other holder.
|
|
1060
|
+
padEmail = "Other@A.org";
|
|
1061
|
+
expect(await count()).toBe(2);
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
it("a visible or pending row with a malformed confidential flag is skipped and counted, never thrown or named", async () => {
|
|
1065
|
+
put(doc({ id: "poc-visible", purposes: [REF], email: "visible@a.org", display_name: "Visible" }));
|
|
1066
|
+
rows.push(
|
|
1067
|
+
{ ...doc({ id: "poc-flag-string-jane", purposes: [REF], email: "jane@a.org" }), is_confidential: "true" },
|
|
1068
|
+
{ ...doc({ id: "poc-flag-one-ann", purposes: [REF], email: "ann@a.org" }), is_confidential: 1 },
|
|
1069
|
+
{
|
|
1070
|
+
...doc({
|
|
1071
|
+
id: "poc-flag-pending-bo",
|
|
1072
|
+
purposes: [REF],
|
|
1073
|
+
email: "bo@a.org",
|
|
1074
|
+
status: "pending",
|
|
1075
|
+
origin: "in_app",
|
|
1076
|
+
added_in_app: "thread",
|
|
1077
|
+
confirmed_by: null,
|
|
1078
|
+
confirmed_at: null,
|
|
1079
|
+
createdBy: ADVOCATE,
|
|
1080
|
+
}),
|
|
1081
|
+
is_confidential: "yes",
|
|
1082
|
+
},
|
|
1083
|
+
);
|
|
1084
|
+
const opts = { resolveSeats, includeOwnPendingFor: ADVOCATE };
|
|
1085
|
+
const list = await listReferralContactsForPartner(db, { agency_id: "agency-a" }, opts);
|
|
1086
|
+
expect(list.recipients.map((r) => r.id)).toEqual(["poc-visible"]);
|
|
1087
|
+
expect([list.confidentialCount, list.unreachable]).toEqual([0, []]);
|
|
1088
|
+
const send = await resolveMagicLinkRecipients(db, { agency_id: "agency-a" }, opts);
|
|
1089
|
+
expect(send.confidentialUnreachableCount).toBe(3);
|
|
1090
|
+
const text = JSON.stringify(list) + JSON.stringify(send) + inspect(send, { depth: null });
|
|
1091
|
+
for (const s of ["jane", "ann", "bo@", "poc-flag"]) expect(text).not.toContain(s);
|
|
1092
|
+
// A corrupt row whose flag is `false` is not confidential: it still fails loudly.
|
|
1093
|
+
rows.push({ ...doc({ id: "poc-v-bad", purposes: [REF] }), origin: "bogus" });
|
|
1094
|
+
await expect(listReferralContactsForPartner(db, { agency_id: "agency-a" }, opts)).rejects.toThrow(
|
|
1095
|
+
PointOfContactShapeError,
|
|
1096
|
+
);
|
|
1097
|
+
const { is_confidential: _flag, ...absent } = doc({ id: "poc-v-noflag", purposes: [REF] });
|
|
1098
|
+
rows.splice(rows.findIndex((r) => r.id === "poc-v-bad"), 1, absent);
|
|
1099
|
+
await expect(listReferralContactsForPartner(db, { agency_id: "agency-a" }, opts)).rejects.toThrow(
|
|
1100
|
+
PointOfContactShapeError,
|
|
1101
|
+
);
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
it("the outcome is identical whether or not an address the sender typed matches a holder (no probe)", async () => {
|
|
1105
|
+
put(
|
|
1106
|
+
doc({ id: "poc-visible", purposes: [REF], email: "visible@a.org", display_name: "Visible" }),
|
|
1107
|
+
conf({ id: "poc-c-1", email: "secret-1@a.org", display_name: "H1" }),
|
|
1108
|
+
conf({ id: "poc-c-2", email: "secret-2@a.org", display_name: "H2" }),
|
|
1109
|
+
conf({ id: "poc-c-3", email: "secret-3@a.org", display_name: "H3" }),
|
|
1110
|
+
);
|
|
1111
|
+
// A caller's whole send: visible and typed addresses (deduped), then the holders.
|
|
1112
|
+
async function sendWithTyped(typed: string) {
|
|
1113
|
+
const list = await resolveMagicLinkRecipients(db, { agency_id: "agency-a" }, { resolveSeats });
|
|
1114
|
+
const mailed: string[] = [];
|
|
1115
|
+
const shown = [...new Set([...list.recipients.map((r) => r.email), typed])];
|
|
1116
|
+
for (const to of shown) mailed.push(to);
|
|
1117
|
+
const outcome = await list.confidential.deliver(async (to) => void mailed.push(to), {
|
|
1118
|
+
capacity: 2,
|
|
1119
|
+
});
|
|
1120
|
+
return { shown, count: list.confidential.count, outcome, mailed };
|
|
1121
|
+
}
|
|
1122
|
+
const miss = await sendWithTyped("someone@else.org");
|
|
1123
|
+
const hit = await sendWithTyped("secret-1@a.org");
|
|
1124
|
+
expect(hit.count).toBe(miss.count);
|
|
1125
|
+
expect(hit.outcome).toEqual(miss.outcome);
|
|
1126
|
+
expect(hit.outcome).toEqual({
|
|
1127
|
+
count: 3,
|
|
1128
|
+
delivered: 2,
|
|
1129
|
+
failed: 0,
|
|
1130
|
+
overflow: 1,
|
|
1131
|
+
firstErrorName: null,
|
|
1132
|
+
});
|
|
1133
|
+
// The matching holder still gets its own link (a duplicate the sender cannot observe).
|
|
1134
|
+
expect(hit.mailed.filter((a) => a === "secret-1@a.org")).toHaveLength(2);
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
it("issues the confidential query separately, after the visible and own-pending ones, and resolves seats once", async () => {
|
|
1138
|
+
const filters: Record<string, unknown>[] = [];
|
|
1139
|
+
const recording: PocDbLike = {
|
|
1140
|
+
collection: () => ({
|
|
1141
|
+
find: (f: Record<string, unknown>) => (filters.push(f), { toArray: async () => [] }),
|
|
1142
|
+
findOne: async () => null,
|
|
1143
|
+
}),
|
|
1144
|
+
};
|
|
1145
|
+
await resolveMagicLinkRecipients(recording, { org_id: "org-a" }, { resolveSeats, includeOwnPendingFor: ADVOCATE });
|
|
1146
|
+
expect(filters).toHaveLength(3);
|
|
1147
|
+
expect(filters[0]).toMatchObject({ is_confidential: { $ne: true }, status: "confirmed" });
|
|
1148
|
+
expect(filters[1]).toMatchObject({ is_confidential: { $ne: true }, status: "pending" });
|
|
1149
|
+
expect(filters[2]).toEqual({
|
|
1150
|
+
$or: [{ org_id: "org-a" }],
|
|
1151
|
+
purposes: REF,
|
|
1152
|
+
active: true,
|
|
1153
|
+
status: "confirmed",
|
|
1154
|
+
is_confidential: true,
|
|
1155
|
+
});
|
|
1156
|
+
await expect(resolveMagicLinkRecipients(db, {}, { resolveSeats })).rejects.toThrow(TypeError);
|
|
1157
|
+
|
|
1158
|
+
put(
|
|
1159
|
+
doc({ id: "poc-v-seat", user_id: "u-seat", email: null, display_name: null, purposes: [REF] }),
|
|
1160
|
+
conf({ id: "poc-c-seat", user_id: "u-pad", email: null, display_name: null }),
|
|
1161
|
+
);
|
|
1162
|
+
const calls: string[][] = [];
|
|
1163
|
+
const counting = async (ids: readonly string[]) => {
|
|
1164
|
+
calls.push([...ids].sort());
|
|
1165
|
+
return resolveSeats(ids);
|
|
1166
|
+
};
|
|
1167
|
+
await listReferralContactsForPartner(db, { agency_id: "agency-a" }, { resolveSeats: counting });
|
|
1168
|
+
expect(calls).toEqual([["u-pad", "u-seat"]]);
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
it("JSON.stringify, util.inspect, String() and structuredClone of a result never carry an address", async () => {
|
|
1172
|
+
putEverySubject();
|
|
1173
|
+
const list = await listReferralContactsForPartner(db, BOTH, { resolveSeats });
|
|
1174
|
+
const send = await resolveMagicLinkRecipients(db, BOTH, { resolveSeats });
|
|
1175
|
+
const renders = [
|
|
1176
|
+
JSON.stringify(list),
|
|
1177
|
+
JSON.stringify(send),
|
|
1178
|
+
inspect(list, { depth: null }),
|
|
1179
|
+
inspect(send, { depth: null }),
|
|
1180
|
+
inspect(send, { depth: null, showHidden: true }),
|
|
1181
|
+
inspect(send.confidential, { customInspect: false, showHidden: true, depth: null }),
|
|
1182
|
+
String(send.confidential),
|
|
1183
|
+
`${send.confidential}`,
|
|
1184
|
+
JSON.stringify(structuredClone(send.confidential)),
|
|
1185
|
+
JSON.stringify(Object.entries(send.confidential)),
|
|
1186
|
+
];
|
|
1187
|
+
for (const text of renders) {
|
|
1188
|
+
for (const secret of SECRETS) expect(text, text).not.toContain(secret);
|
|
1189
|
+
expect(text, text).not.toContain("poc-c-");
|
|
1190
|
+
}
|
|
1191
|
+
expect(JSON.parse(JSON.stringify(send)).confidential).toEqual({ count: 7 });
|
|
1192
|
+
expect(inspect(send.confidential)).toBe("ConfidentialReferralRecipients(7)");
|
|
1193
|
+
expect(Object.keys(send.confidential)).toEqual(["count"]);
|
|
1194
|
+
expect(Object.isFrozen(send.confidential)).toBe(true);
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
it("an interface only: no constructor or class value reaches a caller", async () => {
|
|
1198
|
+
const mod: Record<string, unknown> = await import("../index.js");
|
|
1199
|
+
expect(mod).not.toHaveProperty("ConfidentialReferralRecipients");
|
|
1200
|
+
expect(typeof mod.resolveMagicLinkRecipients).toBe("function");
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
describe("deliver", () => {
|
|
1204
|
+
const FOUR = ["a@x.org", "b@x.org", "c@x.org", "d@x.org"];
|
|
1205
|
+
|
|
1206
|
+
it("overflow is max(0, count - capacity): the first `capacity` holders are sent", async () => {
|
|
1207
|
+
const got: string[] = [];
|
|
1208
|
+
const holders = await holdersAt(FOUR);
|
|
1209
|
+
expect(await holders.deliver(async (to) => void got.push(to), { capacity: 2 })).toEqual({
|
|
1210
|
+
count: 4,
|
|
1211
|
+
delivered: 2,
|
|
1212
|
+
failed: 0,
|
|
1213
|
+
overflow: 2,
|
|
1214
|
+
firstErrorName: null,
|
|
1215
|
+
});
|
|
1216
|
+
expect(got).toEqual(["a@x.org", "b@x.org"]);
|
|
1217
|
+
const noop = async () => undefined;
|
|
1218
|
+
const none = await holders.deliver(noop, { capacity: 0 });
|
|
1219
|
+
expect(none).toMatchObject({ overflow: 4, delivered: 0 });
|
|
1220
|
+
const all = await holders.deliver(noop, { capacity: 9 });
|
|
1221
|
+
expect(all).toMatchObject({ overflow: 0, delivered: 4 });
|
|
1222
|
+
for (const bad of [-1, 1.5, Number.NaN, Number.POSITIVE_INFINITY]) {
|
|
1223
|
+
const attempt = holders.deliver(async () => undefined, { capacity: bad });
|
|
1224
|
+
await expect(attempt, String(bad)).rejects.toThrow(TypeError);
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1228
|
+
it("catches every send error and keeps only its name, never the message that echoes the address", async () => {
|
|
1229
|
+
class ProviderRejected extends Error {
|
|
1230
|
+
constructor(to: string) {
|
|
1231
|
+
super(`550 mailbox ${to} rejected`);
|
|
1232
|
+
this.name = "ProviderRejected";
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
let n = 0;
|
|
1236
|
+
const r = await (await holdersAt(FOUR)).deliver(async (to) => {
|
|
1237
|
+
n++;
|
|
1238
|
+
if (to === "b@x.org") throw new ProviderRejected(to);
|
|
1239
|
+
if (to === "c@x.org") throw Object.assign(new Error(`bounce ${to}`), { name: `Bounce for ${to}` });
|
|
1240
|
+
});
|
|
1241
|
+
expect(n).toBe(4);
|
|
1242
|
+
expect(r).toEqual({ count: 4, delivered: 2, failed: 2, overflow: 0, firstErrorName: "ProviderRejected" });
|
|
1243
|
+
const text = JSON.stringify(r) + inspect(r);
|
|
1244
|
+
for (const a of FOUR) expect(text).not.toContain(a);
|
|
1245
|
+
|
|
1246
|
+
// A synchronous throw, a name carrying the address and a non-Error rejection all read safely.
|
|
1247
|
+
const one = await holdersAt(["z@x.org"]);
|
|
1248
|
+
const sync = await one.deliver((to) => {
|
|
1249
|
+
throw Object.assign(new Error(to), { name: `Err ${to}` });
|
|
1250
|
+
});
|
|
1251
|
+
expect(sync).toEqual({ count: 1, delivered: 0, failed: 1, overflow: 0, firstErrorName: "Error" });
|
|
1252
|
+
expect((await one.deliver(() => Promise.reject("z@x.org"))).firstErrorName).toBe("Error");
|
|
1253
|
+
});
|
|
1254
|
+
|
|
1255
|
+
it("an error whose name cannot be read (a throwing getter, a revoked proxy) reads Error; deliver never rejects", async () => {
|
|
1256
|
+
const one = await holdersAt(["z@x.org"]);
|
|
1257
|
+
const getter = Object.defineProperty(new Error("x"), "name", {
|
|
1258
|
+
get() {
|
|
1259
|
+
throw new Error("z@x.org");
|
|
1260
|
+
},
|
|
1261
|
+
});
|
|
1262
|
+
await expect(one.deliver(() => Promise.reject(getter))).resolves.toEqual({
|
|
1263
|
+
count: 1,
|
|
1264
|
+
delivered: 0,
|
|
1265
|
+
failed: 1,
|
|
1266
|
+
overflow: 0,
|
|
1267
|
+
firstErrorName: "Error",
|
|
1268
|
+
});
|
|
1269
|
+
const { proxy, revoke } = Proxy.revocable({}, {});
|
|
1270
|
+
revoke();
|
|
1271
|
+
expect((await one.deliver(() => Promise.reject(proxy))).firstErrorName).toBe("Error");
|
|
1272
|
+
});
|
|
1273
|
+
});
|
|
1274
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The confidential Referrals (magic link) read (pl-iza, 0.32.0) over a stored
|
|
3
|
+
* collection: the in-memory double (`./mongoDouble.ts`, always) and a REAL
|
|
4
|
+
* MongoDB (only when `POC_WRITER_MONGO_URI` names a server, as in
|
|
5
|
+
* `./writer.mongo.test.ts`; CI sets it). The same rows on both, so the
|
|
6
|
+
* filters the reader builds (`$or` rollup keys, array membership on
|
|
7
|
+
* `purposes`, `is_confidential: true` vs `{ $ne: true }`) are checked against
|
|
8
|
+
* the server's own matcher, not only the double's.
|
|
9
|
+
*
|
|
10
|
+
* mongod --dbpath "$(mktemp -d)" --port 27999 --fork --logpath /tmp/mongod.log
|
|
11
|
+
* POC_WRITER_MONGO_URI=mongodb://127.0.0.1:27999 npx vitest run src/pointsOfContact
|
|
12
|
+
*/
|
|
13
|
+
import { inspect } from "node:util";
|
|
14
|
+
|
|
15
|
+
import mongoose from "mongoose";
|
|
16
|
+
import type { MongoClient as MongoClientType } from "mongodb";
|
|
17
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
POINTS_OF_CONTACT_COLLECTION,
|
|
21
|
+
listReferralContactsForPartner,
|
|
22
|
+
pocIdentityKey,
|
|
23
|
+
resolveMagicLinkRecipients,
|
|
24
|
+
type PocDbLike,
|
|
25
|
+
type PointOfContactDoc,
|
|
26
|
+
type SeatReach,
|
|
27
|
+
} from "../index.js";
|
|
28
|
+
import { mongoDouble } from "./mongoDouble.js";
|
|
29
|
+
|
|
30
|
+
const URI = process.env.POC_WRITER_MONGO_URI;
|
|
31
|
+
const { MongoClient, ObjectId } = mongoose.mongo;
|
|
32
|
+
const REF = "REFERRALS_MAGIC_LINK" as const;
|
|
33
|
+
const ADVOCATE = "auth0|advocate";
|
|
34
|
+
|
|
35
|
+
function row(over: Partial<PointOfContactDoc> & { email?: string | null }): PointOfContactDoc {
|
|
36
|
+
const base: PointOfContactDoc = {
|
|
37
|
+
id: "poc-x",
|
|
38
|
+
subject_type: "agency",
|
|
39
|
+
subject_id: "agency-a",
|
|
40
|
+
agency_id: "agency-a",
|
|
41
|
+
org_id: "org-a",
|
|
42
|
+
user_id: null,
|
|
43
|
+
person_id: null,
|
|
44
|
+
display_name: "Pat Doe",
|
|
45
|
+
emails: [],
|
|
46
|
+
phones: [],
|
|
47
|
+
purposes: [REF],
|
|
48
|
+
urgent_methods: [],
|
|
49
|
+
is_primary: false,
|
|
50
|
+
is_confidential: false,
|
|
51
|
+
active: true,
|
|
52
|
+
notes: null,
|
|
53
|
+
status: "confirmed",
|
|
54
|
+
origin: "admin_hub",
|
|
55
|
+
added_in_app: "platform",
|
|
56
|
+
identity_key: "x",
|
|
57
|
+
confirmed_by: "steward",
|
|
58
|
+
confirmed_at: "2026-10-14T00:00:00.000Z",
|
|
59
|
+
deactivated_by: null,
|
|
60
|
+
deactivated_at: null,
|
|
61
|
+
version: 2,
|
|
62
|
+
createdBy: "u1",
|
|
63
|
+
createdAt: "2026-10-14T00:00:00.000Z",
|
|
64
|
+
updatedBy: "u1",
|
|
65
|
+
updatedAt: "2026-10-14T00:00:00.000Z",
|
|
66
|
+
};
|
|
67
|
+
const { email, ...rest } = over;
|
|
68
|
+
const d: PointOfContactDoc = { ...base, ...rest };
|
|
69
|
+
if (email !== undefined) d.emails = email === null ? [] : [{ value: email, is_preferred: true }];
|
|
70
|
+
return { ...d, identity_key: pocIdentityKey(d) };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const conf = (over: Partial<PointOfContactDoc> & { email?: string | null }) =>
|
|
74
|
+
row({ is_confidential: true, display_name: "Hidden", ...over });
|
|
75
|
+
|
|
76
|
+
/** One partner (agency-a / org-a) with every case the confidential read must get right. */
|
|
77
|
+
const ROWS: PointOfContactDoc[] = [
|
|
78
|
+
row({ id: "poc-visible", email: "visible@a.org", display_name: "Visible" }),
|
|
79
|
+
conf({ id: "poc-c-agency", email: "hidden-agency@a.org" }),
|
|
80
|
+
conf({ id: "poc-c-prog", subject_type: "program", subject_id: "prog-1", email: "hidden-prog@a.org" }),
|
|
81
|
+
conf({ id: "poc-c-team", subject_type: "team", subject_id: "intake", email: "hidden-team@a.org" }),
|
|
82
|
+
conf({ id: "poc-c-loc", subject_type: "location", subject_id: "loc-1", email: "hidden-loc@a.org" }),
|
|
83
|
+
conf({ id: "poc-c-svc", subject_type: "service", subject_id: "svc-1", email: "hidden-svc@a.org" }),
|
|
84
|
+
conf({ id: "poc-c-org", subject_type: "org", subject_id: "org-a", agency_id: null, email: "hidden-org@a.org" }),
|
|
85
|
+
conf({ id: "poc-c-seat", user_id: "u-seat", email: null, display_name: null }),
|
|
86
|
+
conf({ id: "poc-c-seat-nomail", user_id: "u-noemail", email: null, display_name: null }),
|
|
87
|
+
// A visible row also reaches it (still counted); a second holder of the same address (deduped).
|
|
88
|
+
conf({ id: "poc-c-visible-dup", email: "visible@a.org" }),
|
|
89
|
+
conf({ id: "poc-c-agency-dup", subject_type: "program", subject_id: "prog-2", email: "hidden-agency@a.org" }),
|
|
90
|
+
// Never counted.
|
|
91
|
+
conf({ id: "poc-c-pending", email: "pending@a.org", status: "pending" }),
|
|
92
|
+
conf({ id: "poc-c-gone", email: "gone@a.org", active: false }),
|
|
93
|
+
conf({ id: "poc-c-untagged", email: "billing@a.org", purposes: ["BILLING"] }),
|
|
94
|
+
conf({ id: "poc-c-other", agency_id: "agency-b", subject_id: "agency-b", org_id: "org-b", email: "b@b.org" }),
|
|
95
|
+
// The advocate's own pending add of a confidential holder's address: listed, never deduped against.
|
|
96
|
+
row({
|
|
97
|
+
id: "poc-mine",
|
|
98
|
+
email: "hidden-prog@a.org",
|
|
99
|
+
display_name: "Mine",
|
|
100
|
+
status: "pending",
|
|
101
|
+
origin: "in_app",
|
|
102
|
+
added_in_app: "thread",
|
|
103
|
+
confirmed_by: null,
|
|
104
|
+
confirmed_at: null,
|
|
105
|
+
createdBy: ADVOCATE,
|
|
106
|
+
}),
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
/** A stored confidential row that does not match the contract: skipped and counted, never named. */
|
|
110
|
+
const CORRUPT = { ...conf({ id: "poc-c-corrupt", email: "corrupt@a.org" }), origin: "bogus" };
|
|
111
|
+
/** A visible-leg row whose stored flag is malformed: it matches `{ $ne: true }` on the server too. */
|
|
112
|
+
const FLAG = { ...row({ id: "poc-v-flag", email: "flag@a.org" }), is_confidential: "true" };
|
|
113
|
+
const STORED = [...ROWS, CORRUPT, FLAG];
|
|
114
|
+
|
|
115
|
+
const SECRETS = [
|
|
116
|
+
"corrupt@a.org",
|
|
117
|
+
"flag@a.org",
|
|
118
|
+
"hidden-agency@a.org",
|
|
119
|
+
"hidden-prog@a.org",
|
|
120
|
+
"hidden-team@a.org",
|
|
121
|
+
"hidden-loc@a.org",
|
|
122
|
+
"hidden-svc@a.org",
|
|
123
|
+
"hidden-org@a.org",
|
|
124
|
+
"seat@a.org",
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
const SEATS = new Map<string, SeatReach>([
|
|
128
|
+
["u-seat", { email: " Seat@A.org ", phone: null, name: "Sam Seat" }],
|
|
129
|
+
["u-noemail", { email: null, phone: null, name: "No Mail" }],
|
|
130
|
+
]);
|
|
131
|
+
const resolveSeats = async (ids: readonly string[]) =>
|
|
132
|
+
new Map(ids.filter((i) => SEATS.has(i)).map((i) => [i, SEATS.get(i)!]));
|
|
133
|
+
|
|
134
|
+
function suite(name: string, handle: () => PocDbLike) {
|
|
135
|
+
const partner = { agency_id: "agency-a", org_id: "org-a" };
|
|
136
|
+
const withPending = { resolveSeats, includeOwnPendingFor: ADVOCATE };
|
|
137
|
+
|
|
138
|
+
it(`${name}: counts distinct confirmed confidential holders on every rollup subject`, async () => {
|
|
139
|
+
const r = await listReferralContactsForPartner(handle(), partner, { resolveSeats });
|
|
140
|
+
expect(r.recipients.map((x) => x.id)).toEqual(["poc-visible"]);
|
|
141
|
+
expect(r.confidentialCount).toBe(8);
|
|
142
|
+
// `unreachable` is visible-only; the no-email seat, the corrupt row and the
|
|
143
|
+
// malformed flag are a server-side count on the send list only.
|
|
144
|
+
expect(r.unreachable).toEqual([]);
|
|
145
|
+
expect(r).not.toHaveProperty("confidentialUnreachableCount");
|
|
146
|
+
const send = await resolveMagicLinkRecipients(handle(), partner, { resolveSeats });
|
|
147
|
+
expect(send.confidentialUnreachableCount).toBe(3);
|
|
148
|
+
expect(JSON.stringify(r) + JSON.stringify(send)).not.toMatch(/poc-c-|poc-v-flag/);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it(`${name}: an own-pending add of a confidential address is listed and the count does not drop`, async () => {
|
|
152
|
+
const r = await listReferralContactsForPartner(handle(), partner, withPending);
|
|
153
|
+
expect(r.recipients.map((x) => [x.id, x.pending ?? false])).toEqual([
|
|
154
|
+
["poc-visible", false],
|
|
155
|
+
["poc-mine", true],
|
|
156
|
+
]);
|
|
157
|
+
expect(r.confidentialCount).toBe(8);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it(`${name}: the send list delivers up to capacity and renders as a count only`, async () => {
|
|
161
|
+
const send = await resolveMagicLinkRecipients(handle(), partner, withPending);
|
|
162
|
+
// hidden-prog@a.org is also the advocate's OWN pending add, so it is theirs to see
|
|
163
|
+
// (as their pick, never as a confidential holder); every other holder stays unseen.
|
|
164
|
+
const unseen = SECRETS.filter((a) => a !== "hidden-prog@a.org");
|
|
165
|
+
for (const text of [JSON.stringify(send), inspect(send, { depth: null, showHidden: true })]) {
|
|
166
|
+
for (const secret of unseen) expect(text).not.toContain(secret);
|
|
167
|
+
}
|
|
168
|
+
const plain = await resolveMagicLinkRecipients(handle(), partner, { resolveSeats });
|
|
169
|
+
for (const text of [JSON.stringify(plain), inspect(plain, { depth: null, showHidden: true })]) {
|
|
170
|
+
for (const secret of SECRETS) expect(text).not.toContain(secret);
|
|
171
|
+
}
|
|
172
|
+
expect(JSON.parse(JSON.stringify(send)).confidential).toEqual({ count: 8 });
|
|
173
|
+
const got: string[] = [];
|
|
174
|
+
const r = await send.confidential.deliver(async (to) => void got.push(to), { capacity: 5 });
|
|
175
|
+
// Reading order, the first five sent (visible@ and hidden-prog@ too, though a visible
|
|
176
|
+
// row and the advocate's own pick also reach them: duplicates they cannot observe),
|
|
177
|
+
// the last three overflowing.
|
|
178
|
+
expect(got).toEqual([
|
|
179
|
+
"seat@a.org",
|
|
180
|
+
"hidden-agency@a.org",
|
|
181
|
+
"visible@a.org",
|
|
182
|
+
"hidden-org@a.org",
|
|
183
|
+
"hidden-prog@a.org",
|
|
184
|
+
]);
|
|
185
|
+
expect(r).toEqual({ count: 8, delivered: 5, failed: 0, overflow: 3, firstErrorName: null });
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
describe("confidential referral holders over the in-memory double", () => {
|
|
190
|
+
const m = mongoDouble();
|
|
191
|
+
m.store.set(POINTS_OF_CONTACT_COLLECTION, STORED.map((d) => ({ ...d })));
|
|
192
|
+
suite("double", () => m.handle() as unknown as PocDbLike);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe.skipIf(!URI)("confidential referral holders against a real MongoDB", () => {
|
|
196
|
+
let client: MongoClientType;
|
|
197
|
+
let dbName: string;
|
|
198
|
+
|
|
199
|
+
beforeAll(async () => {
|
|
200
|
+
client = await new MongoClient(URI!).connect();
|
|
201
|
+
dbName = `poc_reader_test_${new ObjectId().toHexString()}`;
|
|
202
|
+
const coll = client.db(dbName).collection(POINTS_OF_CONTACT_COLLECTION);
|
|
203
|
+
await coll.insertMany(STORED.map((d) => ({ ...d })));
|
|
204
|
+
});
|
|
205
|
+
afterAll(async () => {
|
|
206
|
+
await client?.db(dbName).dropDatabase();
|
|
207
|
+
await client?.close();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
suite("mongodb", () => client.db(dbName) as unknown as PocDbLike);
|
|
211
|
+
});
|