forked from Yara724/api
Fixed GET users
This commit is contained in:
61
src/helpers/party-access-queries.spec.ts
Normal file
61
src/helpers/party-access-queries.spec.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Types } from "mongoose";
|
||||
import { partyPersonMatchesUser } from "./iran-mobile";
|
||||
import {
|
||||
buildBlamePartyAccessOrConditions,
|
||||
mongoUserIdEqualityFilter,
|
||||
} from "./party-access-queries";
|
||||
|
||||
describe("party access queries", () => {
|
||||
const userId = new Types.ObjectId();
|
||||
|
||||
describe("mongoUserIdEqualityFilter", () => {
|
||||
it("includes both ObjectId and string forms", () => {
|
||||
const filter = mongoUserIdEqualityFilter(
|
||||
"parties.person.userId",
|
||||
String(userId),
|
||||
);
|
||||
expect(filter).toEqual({
|
||||
$or: [
|
||||
{ "parties.person.userId": String(userId) },
|
||||
{ "parties.person.userId": userId },
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildBlamePartyAccessOrConditions", () => {
|
||||
it("builds userId and phone branches", () => {
|
||||
const or = buildBlamePartyAccessOrConditions({
|
||||
sub: String(userId),
|
||||
username: "09123456789",
|
||||
});
|
||||
expect(or).toHaveLength(2);
|
||||
expect(or[0]).toHaveProperty("$or");
|
||||
expect(or[1]).toEqual({
|
||||
"parties.person.phoneNumber": {
|
||||
$in: expect.arrayContaining(["09123456789", "9123456789"]),
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("partyPersonMatchesUser", () => {
|
||||
it("matches party userId stored as ObjectId against string JWT sub", () => {
|
||||
expect(
|
||||
partyPersonMatchesUser(
|
||||
{ userId, phoneNumber: "09111111111" },
|
||||
{ sub: String(userId), username: "09999999999" },
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("matches phone variants when userId is not set yet", () => {
|
||||
expect(
|
||||
partyPersonMatchesUser(
|
||||
{ phoneNumber: "9123456789" },
|
||||
{ sub: "other", username: "09123456789" },
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user