HOTFIX: not allowing empty price when expert tries to submit

This commit is contained in:
SepehrYahyaee
2026-09-05 16:44:40 +03:30
parent 70fa49398d
commit feacad58ca
7 changed files with 200 additions and 1 deletions

View File

@@ -0,0 +1,69 @@
import { BadRequestException } from "@nestjs/common";
import { ClaimCaseStatus } from "src/Types&Enums/claim-request-management/claim-case-status.enum";
import { RoleEnum } from "src/Types&Enums/role.enum";
import { ExpertClaimService } from "./expert-claim.service";
const blankPricingReply = {
description: "Damage assessment",
parts: [
{
partId: 201,
price: "",
salary: "",
totalPayment: "",
factorNeeded: false,
},
],
};
function createService() {
return new (ExpertClaimService as any)(
...new Array(21).fill(undefined),
) as ExpertClaimService;
}
describe("ExpertClaimService expert-reply pricing", () => {
it("rejects a blank pricing line on the legacy submit endpoint before changing status", async () => {
const service = createService() as any;
const findAndUpdate = jest.fn();
service.claimRequestManagementDbService = {
findOne: jest.fn().mockResolvedValue({
_id: "legacy-claim",
actorLocked: { actorId: "expert-1" },
unlockTime: new Date(Date.now() + 60_000),
lockFile: true,
}),
findAndUpdate,
};
await expect(
service.submitReplyRequest("legacy-claim", blankPricingReply, {
sub: "expert-1",
}),
).rejects.toBeInstanceOf(BadRequestException);
expect(findAndUpdate).not.toHaveBeenCalled();
});
it("rejects a blank pricing line on the V2 submit endpoint before completion", async () => {
const service = createService() as any;
const findByIdAndUpdate = jest.fn();
service.claimCaseDbService = {
findById: jest.fn().mockResolvedValue({
status: ClaimCaseStatus.EXPERT_REVIEWING,
workflow: { locked: true, lockedBy: { actorId: "expert-1" } },
}),
findByIdAndUpdate,
};
service.assertExpertActorOnClaim = jest.fn().mockResolvedValue(undefined);
await expect(
service.submitExpertReplyV2("v2-claim", blankPricingReply, {
sub: "expert-1",
role: RoleEnum.FIELD_EXPERT,
}),
).rejects.toBeInstanceOf(BadRequestException);
expect(findByIdAndUpdate).not.toHaveBeenCalled();
});
});