forked from Yara724/api
fix(api contract): trimmed user blame/claim lists and queues and removing unused data
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import { toPublicListItems } from "./public-list-response";
|
||||
import { applyListQueryV2 } from "./list-query-v2";
|
||||
import { ClaimRequestManagementService } from "src/claim-request-management/claim-request-management.service";
|
||||
import { ExpertClaimService } from "src/expert-claim/expert-claim.service";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
|
||||
describe("public list payloads", () => {
|
||||
it("filters full party snapshots before removing them, and preserves locks/workflow fields", () => {
|
||||
const row = {
|
||||
publicId: "A100",
|
||||
status: "EXPERT_REVIEWING",
|
||||
createdAt: "2026-10-03",
|
||||
claimRequestId: "claim-id",
|
||||
currentStep: "EXPERT_COST_EVALUATION",
|
||||
locked: true,
|
||||
lockedBy: { actorId: "expert-id" },
|
||||
partyIdentities: [
|
||||
{
|
||||
person: { nationalCode: "1234567890" },
|
||||
evidence: { secret: "large snapshot" },
|
||||
},
|
||||
],
|
||||
};
|
||||
const paged = applyListQueryV2(
|
||||
[row],
|
||||
{
|
||||
publicId: (r) => r.publicId,
|
||||
createdAt: (r) => r.createdAt,
|
||||
status: (r) => r.status,
|
||||
},
|
||||
{ nationalCode: "۱۲۳۴۵۶۷۸۹۰" },
|
||||
);
|
||||
const result = toPublicListItems(paged.list);
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]).toMatchObject({
|
||||
locked: true,
|
||||
lockedBy: { actorId: "expert-id" },
|
||||
currentStep: "EXPERT_COST_EVALUATION",
|
||||
});
|
||||
expect(result[0]).not.toHaveProperty("partyIdentities");
|
||||
expect(row.partyIdentities).toHaveLength(1);
|
||||
expect(toPublicListItems([])).toEqual([]);
|
||||
});
|
||||
|
||||
it("removes identity snapshots at the actual user and expert list response boundaries", async () => {
|
||||
const userService = Object.create(
|
||||
ClaimRequestManagementService.prototype,
|
||||
) as any;
|
||||
userService.blameRequestDbService = {
|
||||
find: jest.fn().mockResolvedValue([]),
|
||||
};
|
||||
userService.claimCaseDbService = {
|
||||
find: jest.fn().mockResolvedValue([
|
||||
{
|
||||
_id: "claim-id",
|
||||
publicId: "A100",
|
||||
status: "WAITING_FOR_DAMAGE_EXPERT",
|
||||
createdAt: "2026-10-03",
|
||||
workflow: { currentStep: "EXPERT_COST_EVALUATION" },
|
||||
snapshot: {
|
||||
parties: [
|
||||
{
|
||||
person: { nationalCode: "1234567890" },
|
||||
inquiries: { huge: "raw provider data" },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]),
|
||||
};
|
||||
const userResult = await userService.getMyClaimsV2(
|
||||
"650000000000000000000001",
|
||||
{ role: RoleEnum.FIELD_EXPERT },
|
||||
{ nationalCode: "1234567890" },
|
||||
);
|
||||
expect(userResult.total).toBe(1);
|
||||
expect(userResult.list[0]).not.toHaveProperty("partyIdentities");
|
||||
const expertService = Object.create(ExpertClaimService.prototype) as any;
|
||||
const expertResult = expertService.paginateClaimListV2(
|
||||
[
|
||||
{
|
||||
claimRequestId: "claim-id",
|
||||
publicId: "A100",
|
||||
status: "WAITING_FOR_DAMAGE_EXPERT",
|
||||
currentStep: "EXPERT_COST_EVALUATION",
|
||||
locked: true,
|
||||
lockedBy: { actorId: "expert-id" },
|
||||
partyIdentities: [{ person: { nationalCode: "1234567890" } }],
|
||||
},
|
||||
],
|
||||
{ nationalCode: "1234567890" },
|
||||
);
|
||||
expect(expertResult.total).toBe(1);
|
||||
expect(expertResult.list[0]).not.toHaveProperty("partyIdentities");
|
||||
expect(expertResult.list[0].lockedBy).toEqual({ actorId: "expert-id" });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user