Files
yara724api/src/request-management/request-management.file-reviewer.spec.ts
2026-09-12 10:18:17 +03:30

204 lines
6.2 KiB
TypeScript

import { Types } from "mongoose";
import { ExpertClaimService } from "src/expert-claim/expert-claim.service";
import { RoleEnum } from "src/Types&Enums/role.enum";
import { RequestManagementService } from "./request-management.service";
describe("RequestManagementService FileReviewer inbox", () => {
const reviewerId = new Types.ObjectId();
const otherReviewerId = new Types.ObjectId();
const clientId = new Types.ObjectId();
const otherClientId = new Types.ObjectId();
const sealedFile = {
_id: new Types.ObjectId(),
publicId: "BLM-OPEN",
type: "THIRD_PARTY",
status: "WAITING_FOR_FILE_REVIEWER",
isMadeByFileMaker: true,
expertInitiated: true,
creationMethod: "IN_PERSON",
parties: [
{
role: "FIRST",
person: { clientId, userId: new Types.ObjectId() },
},
],
expert: { decision: { guiltyPartyId: new Types.ObjectId() } },
};
function createService(files: any[]) {
const blameRequestDbService = {
find: jest.fn().mockResolvedValue(files),
};
const service = new (RequestManagementService as any)(
undefined,
blameRequestDbService,
) as RequestManagementService;
return { service, blameRequestDbService };
}
it("lists a FileMaker-sealed, unassigned file for a reviewer in the same tenant", async () => {
const { service, blameRequestDbService } = createService([sealedFile]);
const result = await service.getMyFileReviewerFiles({
sub: String(reviewerId),
role: RoleEnum.FILE_REVIEWER,
clientKey: String(clientId),
});
expect(result).toEqual([
expect.objectContaining({ _id: sealedFile._id, publicId: "BLM-OPEN" }),
]);
expect(blameRequestDbService.find).toHaveBeenCalledWith(
expect.objectContaining({
isMadeByFileMaker: true,
expertInitiated: true,
creationMethod: "IN_PERSON",
$or: expect.arrayContaining([
expect.objectContaining({ status: "WAITING_FOR_FILE_REVIEWER" }),
expect.objectContaining({ assignedFileReviewerId: reviewerId }),
]),
}),
);
});
it("does not list another tenant's open file or a file assigned to another reviewer", async () => {
const { service } = createService([
{
...sealedFile,
_id: new Types.ObjectId(),
parties: [{ role: "FIRST", person: { clientId: otherClientId } }],
},
{
...sealedFile,
_id: new Types.ObjectId(),
assignedFileReviewerId: otherReviewerId,
},
]);
const result = await service.getMyFileReviewerFiles({
sub: String(reviewerId),
role: RoleEnum.FILE_REVIEWER,
clientKey: String(clientId),
});
expect(result).toEqual([]);
});
it("does not expose an open file's details to a reviewer from another tenant", async () => {
const { service } = createService([]);
(service as any).blameRequestDbService.findById = jest.fn().mockResolvedValue({
...sealedFile,
parties: [{ role: "FIRST", person: { clientId: otherClientId } }],
});
await expect(
service.getMyFileReviewerFileDetail(
{
sub: String(reviewerId),
role: RoleEnum.FILE_REVIEWER,
clientKey: String(clientId),
},
String(sealedFile._id),
),
).rejects.toThrow("does not belong to your organization");
});
it("returns party identity, VIN plate and claim payment/reference data to the V4 reviewer", async () => {
const { service } = createService([]);
const request = {
...sealedFile,
parties: [
{
role: "FIRST",
person: {
clientId,
fullName: "راننده و بیمه‌گذار نمونه",
nationalCodeOfInsurer: "1111111111",
nationalCodeOfDriver: "2222222222",
driverIsInsurer: false,
licenseType: "پایه یک",
driverLicense: "L-123",
},
vehicle: { plateId: "11-22-ب-333", vin: "VIN-123" },
},
],
};
(service as any).blameRequestDbService.findById = jest
.fn()
.mockResolvedValue(request);
(service as any).claimCaseDbService = {
findOne: jest.fn().mockResolvedValue({
_id: new Types.ObjectId(),
status: "COMPLETED",
workflow: {},
money: { sheba: "IR123" },
claimId: 101,
fanavaranSync: { baseClaim: { policyId: 202 } },
}),
};
const result = await service.getMyFileReviewerFileDetail(
{
sub: String(reviewerId),
role: RoleEnum.FILE_REVIEWER,
clientKey: String(clientId),
},
String(sealedFile._id),
);
expect(result.parties[0]).toEqual(
expect.objectContaining({
person: expect.objectContaining({
fullName: "راننده و بیمه‌گذار نمونه",
nationalCodeOfInsurer: "1111111111",
nationalCodeOfDriver: "2222222222",
licenseType: "پایه یک",
}),
vehicle: expect.objectContaining({
plateId: "11-22-ب-333",
vin: "VIN-123",
}),
}),
);
expect(result.money).toEqual({ sheba: "IR123" });
expect(result.fanavaran).toEqual(
expect.objectContaining({ claimId: 101, policyId: 202 }),
);
});
it("does not let a reviewer claim another tenant's file through its linked claim ID", async () => {
const blameRequestDbService = {
findById: jest.fn().mockResolvedValue({
...sealedFile,
parties: [{ role: "FIRST", person: { clientId: otherClientId } }],
}),
findOneAndUpdate: jest.fn(),
};
const expertClaimService = new (ExpertClaimService as any)(
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
blameRequestDbService,
) as ExpertClaimService;
await expect(
(expertClaimService as any).assignFileReviewerToV4Blame(
String(new Types.ObjectId()),
{ blameRequestId: sealedFile._id },
{
sub: String(reviewerId),
role: RoleEnum.FILE_REVIEWER,
clientKey: String(clientId),
},
),
).rejects.toThrow("does not belong to your organization");
expect(blameRequestDbService.findOneAndUpdate).not.toHaveBeenCalled();
});
});