forked from Yara724/api
fix: align inquiry errors and expert review rules
This commit is contained in:
25
src/helpers/claim-price-cap.spec.ts
Normal file
25
src/helpers/claim-price-cap.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { CreationMethod } from "src/request-management/entities/schema/request-management.schema";
|
||||
import { claimPriceCapAppliesToBlame } from "./claim-price-cap";
|
||||
|
||||
describe("claimPriceCapAppliesToBlame", () => {
|
||||
it.each([
|
||||
[{ creationMethod: CreationMethod.NORMAL }],
|
||||
[{}],
|
||||
])("applies to V1 user-created files (%p)", (blame) => {
|
||||
expect(claimPriceCapAppliesToBlame(blame)).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[{ creationMethod: CreationMethod.LINK, expertInitiated: true }],
|
||||
[{ creationMethod: CreationMethod.IN_PERSON, expertInitiated: true }],
|
||||
[{ creationMethod: CreationMethod.IN_PERSON, registrarInitiated: true }],
|
||||
[{ creationMethod: CreationMethod.LINK, callCenterInitiated: true }],
|
||||
[{ creationMethod: CreationMethod.NORMAL, initiatedByCallCenterId: "agent" }],
|
||||
])("does not apply to non-V1 files (%p)", (blame) => {
|
||||
expect(claimPriceCapAppliesToBlame(blame)).toBe(false);
|
||||
});
|
||||
|
||||
it("does not apply when the linked blame origin is unavailable", () => {
|
||||
expect(claimPriceCapAppliesToBlame(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
39
src/helpers/claim-price-cap.ts
Normal file
39
src/helpers/claim-price-cap.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { CreationMethod } from "src/request-management/entities/schema/request-management.schema";
|
||||
|
||||
export type ClaimPriceCapBlameOrigin = {
|
||||
creationMethod?: CreationMethod | string | null;
|
||||
expertInitiated?: boolean | null;
|
||||
registrarInitiated?: boolean | null;
|
||||
callCenterInitiated?: boolean | null;
|
||||
initiatedByFieldExpertId?: unknown;
|
||||
initiatedByRegistrarId?: unknown;
|
||||
initiatedByCallCenterId?: unknown;
|
||||
};
|
||||
|
||||
/**
|
||||
* The total-payment cap is a V1 business rule. V1 files are created directly
|
||||
* by a user (`NORMAL`); expert/registrar LINK or IN_PERSON files and V6
|
||||
* call-center files must not inherit it. Missing creationMethod is treated as
|
||||
* NORMAL for older user-created records, while initiator markers take
|
||||
* precedence so legacy non-V1 records cannot be misclassified.
|
||||
*/
|
||||
export function claimPriceCapAppliesToBlame(
|
||||
blame?: ClaimPriceCapBlameOrigin | null,
|
||||
): boolean {
|
||||
if (!blame) return false;
|
||||
|
||||
const hasNonV1Initiator =
|
||||
blame.expertInitiated === true ||
|
||||
blame.registrarInitiated === true ||
|
||||
blame.callCenterInitiated === true ||
|
||||
blame.initiatedByFieldExpertId != null ||
|
||||
blame.initiatedByRegistrarId != null ||
|
||||
blame.initiatedByCallCenterId != null;
|
||||
|
||||
if (hasNonV1Initiator) return false;
|
||||
|
||||
return (
|
||||
blame.creationMethod == null ||
|
||||
blame.creationMethod === CreationMethod.NORMAL
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user