forked from Yara724/api
fanavaran locations getting from branches
This commit is contained in:
@@ -46,6 +46,7 @@ function createHarness(blame: object, claim: object, role: number) {
|
||||
findOneAndUpdate: () => ({ exec: async () => null }),
|
||||
};
|
||||
const management = Object.create(ClaimRequestManagementService.prototype);
|
||||
const branches = { findById: jest.fn().mockResolvedValue(null) };
|
||||
Object.assign(management, {
|
||||
logger: new Logger("LocationHeaderTest"),
|
||||
httpService: http,
|
||||
@@ -61,6 +62,7 @@ function createHarness(blame: object, claim: object, role: number) {
|
||||
},
|
||||
fanavaranLocationService: new FanavaranLocationService(
|
||||
...(staff as [any, any, any, any, any]),
|
||||
branches as any,
|
||||
),
|
||||
fanavaranAuthService: new FanavaranAuthService(
|
||||
http as any,
|
||||
@@ -68,10 +70,41 @@ function createHarness(blame: object, claim: object, role: number) {
|
||||
tokenModel as any,
|
||||
),
|
||||
});
|
||||
return { management, http, audit, staff };
|
||||
return { management, http, audit, staff, branches };
|
||||
}
|
||||
|
||||
describe("Fanavaran outgoing Location headers", () => {
|
||||
it.each([{ locations: null }, { locations: [] }, { locations: undefined }])(
|
||||
"uses the creator's branch code when staff locations are %j",
|
||||
async ({ locations }) => {
|
||||
const { management, http, staff, branches } = createHarness(
|
||||
{ expert: { assignedExpertId: "blame-expert" } },
|
||||
{ initiatedByFieldExpertId: "damage-creator" },
|
||||
-1,
|
||||
);
|
||||
staff[3].findById.mockImplementation(async (id: string) =>
|
||||
id === "damage-creator" ? { locations, branchId: "branch-1" } : null,
|
||||
);
|
||||
staff[2].findById.mockImplementation(async (id: string) =>
|
||||
id === "blame-expert"
|
||||
? { locations: [{ id: "210050", name: "Other" }] }
|
||||
: null,
|
||||
);
|
||||
branches.findById.mockResolvedValue({ code: "110011" });
|
||||
await management.postFanavaranJson(
|
||||
"https://example.test/claims",
|
||||
{},
|
||||
"parsian",
|
||||
undefined,
|
||||
"claim-1",
|
||||
);
|
||||
expect(http.post.mock.calls.at(-1)?.[2].headers).toMatchObject({
|
||||
Location: "110011",
|
||||
});
|
||||
expect(branches.findById).toHaveBeenCalledWith("branch-1");
|
||||
},
|
||||
);
|
||||
|
||||
it("uses the damage expert handling a user-created claim before the previous blame expert", async () => {
|
||||
const { management, http, staff } = createHarness(
|
||||
{ expert: { assignedExpertId: "blame-expert" } },
|
||||
@@ -90,7 +123,9 @@ describe("Fanavaran outgoing Location headers", () => {
|
||||
);
|
||||
management.assertFanavaranVehicleReviewApproved = jest.fn();
|
||||
management.previewFanavaranSubmitV2 = jest.fn().mockResolvedValue({
|
||||
PolicyId: 1, AccidentCauseId: 6, CulpritLicenceNo: "1234567890",
|
||||
PolicyId: 1,
|
||||
AccidentCauseId: 6,
|
||||
CulpritLicenceNo: "1234567890",
|
||||
});
|
||||
await management.executeFanavaranV2Submit("claim-1", "parsian");
|
||||
expect(http.post.mock.calls.at(-1)?.[2].headers).toMatchObject({
|
||||
@@ -216,20 +251,43 @@ describe("Fanavaran outgoing Location headers", () => {
|
||||
|
||||
it("keeps concurrent claims' staff locations separate while sharing a login token", async () => {
|
||||
const { management, http, staff } = createHarness({}, {}, -1);
|
||||
management.claimCaseDbService.findById.mockImplementation(async (id: string) => ({
|
||||
blameRequestId: "blame-1", initiatedByFieldExpertId: id,
|
||||
}));
|
||||
management.claimCaseDbService.findById.mockImplementation(
|
||||
async (id: string) => ({
|
||||
blameRequestId: "blame-1",
|
||||
initiatedByFieldExpertId: id,
|
||||
}),
|
||||
);
|
||||
staff[3].findById.mockImplementation(async (id: string) => ({
|
||||
locations: [{ id: id === "claim-a" ? "110011" : "210050", name: "Branch" }],
|
||||
locations: [
|
||||
{ id: id === "claim-a" ? "110011" : "210050", name: "Branch" },
|
||||
],
|
||||
}));
|
||||
await Promise.all(["claim-a", "claim-b"].map((id) => management.postFanavaranJson(
|
||||
`https://example.test/${id}`, {}, "parsian", undefined, id,
|
||||
)));
|
||||
const calls = http.post.mock.calls.filter(([url]) => url.startsWith("https://example.test/"));
|
||||
const headersByUrl = Object.fromEntries(calls.map(([url, , options]) => [url, options.headers]));
|
||||
await Promise.all(
|
||||
["claim-a", "claim-b"].map((id) =>
|
||||
management.postFanavaranJson(
|
||||
`https://example.test/${id}`,
|
||||
{},
|
||||
"parsian",
|
||||
undefined,
|
||||
id,
|
||||
),
|
||||
),
|
||||
);
|
||||
const calls = http.post.mock.calls.filter(([url]) =>
|
||||
url.startsWith("https://example.test/"),
|
||||
);
|
||||
const headersByUrl = Object.fromEntries(
|
||||
calls.map(([url, , options]) => [url, options.headers]),
|
||||
);
|
||||
expect(headersByUrl).toEqual({
|
||||
"https://example.test/claim-a": expect.objectContaining({ Location: "110011", authenticationToken: "auth-test" }),
|
||||
"https://example.test/claim-b": expect.objectContaining({ Location: "210050", authenticationToken: "auth-test" }),
|
||||
"https://example.test/claim-a": expect.objectContaining({
|
||||
Location: "110011",
|
||||
authenticationToken: "auth-test",
|
||||
}),
|
||||
"https://example.test/claim-b": expect.objectContaining({
|
||||
Location: "210050",
|
||||
authenticationToken: "auth-test",
|
||||
}),
|
||||
});
|
||||
expect(http.post).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user