fix(claims): defer flow 1 fanavaran submission at creation

Skip creation-time submission for Flow 1 while preserving branch validation, later staged submission, and other flows.
This commit is contained in:
2026-11-21 10:33:11 +03:30
parent 68e26920e2
commit cda424a536
3 changed files with 55 additions and 4 deletions
@@ -90,10 +90,50 @@ describe("claim beneficiary authorization across shared user flows", () => {
expect(saved.owner.userClientKey).toBe(payer);
expect(
service.autoSubmitToFanavaranV2OnClaimCreated,
).toHaveBeenCalledTimes(1);
).not.toHaveBeenCalled();
},
);
it.each(["THIRD_PARTY", "CAR_BODY"])(
"defers Flow 1 %s submission at creation while retaining the selected branch",
async (type) => {
const blame = source();
blame.type = type;
blame.branchId = "650000000000000000000099";
if (type === "CAR_BODY") blame.parties = [blame.parties[0]];
const service = serviceFor(blame);
const result = await service.createClaimFromBlameV2(
blameId,
type === "CAR_BODY" ? firstId : secondId,
);
expect(result.fanavaran).toMatchObject({
attempted: false,
submitted: false,
skipped: true,
});
expect(service.autoSubmitToFanavaranV2OnClaimCreated).not.toHaveBeenCalled();
expect(service.userClaimBranchService.validate).toHaveBeenCalledWith(blame, blame.branchId);
expect(String(service.claimCaseDbService.create.mock.calls[0][0].branchId)).toBe(blame.branchId);
},
);
it.each([
{ callCenterInitiated: true },
{ expertInitiated: true, creationMethod: "LINK" },
{ expertInitiated: true, creationMethod: "IN_PERSON" },
{ registrarInitiated: true },
{ isMadeByFileMaker: true },
])("preserves early submission for other flows: %j", async (flags) => {
const service = serviceFor({ ...source(), ...flags });
await service.createClaimFromBlameV2(blameId, secondId);
expect(service.autoSubmitToFanavaranV2OnClaimCreated).toHaveBeenCalledTimes(1);
expect(service.autoSubmitToFanavaranV2OnClaimCreated).toHaveBeenCalledWith(claimId);
});
it("blocks incomplete, unsigned, rejected, and unresolved cases without creating or submitting a claim", async () => {
const invalid = [
{ ...source(), status: "WAITING_FOR_SIGNATURES" },
@@ -8213,9 +8213,18 @@ export class ClaimRequestManagementService {
`Claim created: ${newClaim._id} from blame: ${blameRequestId}`,
);
const fanavaran = await this.autoSubmitToFanavaranV2OnClaimCreated(
String(newClaim._id),
);
// Flow 1 defers Fanavaran submission to the later staged hooks.
// Flow 6 and expert/registrar-created cases retain early submission.
const deferFanavaran =
usesUserClaimBranch(blameRequest) && !blameRequest.callCenterInitiated;
const fanavaran: FanavaranAutoSubmitResult = deferFanavaran
? {
attempted: false,
submitted: false,
skipped: true,
skipReason: 'Flow 1 defers Fanavaran submission until a later stage',
}
: await this.autoSubmitToFanavaranV2OnClaimCreated(String(newClaim._id));
const message = this.withFanavaranAutoSubmitMessage(
'Claim request created successfully',
fanavaran,