1
0
forked from Yara724/api

Fixed GET users

This commit is contained in:
2026-06-18 18:15:20 +03:30
parent d8f7766f10
commit dcc3ee71de
11 changed files with 368 additions and 103 deletions

View 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);
});
});
});