Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/claims/entities/claim.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,32 @@ describe('Claim Entity', () => {
expect(claim.resolvedAt).toBeNull();
});

it('legacy claim (RESOLVED with null resolvedAt) updates resolvedAt on transition to FINALIZED (BE-219 Audit)', () => {
claim.resolvedVerdict = true;
claim.confidenceScore = 0.80;
claim.finalized = false;
claim.resolvedAt = null;

claim.transitionTo(ClaimState.FINALIZED);

expect(claim.resolvedAt).not.toBeNull();
expect(claim.resolvedAt).toBeInstanceOf(Date);
expect(claim.finalized).toBe(true);
});

it('legacy claim (RESOLVED with null resolvedAt) updates resolvedAt on transition to RESOLVED (BE-219 Audit)', () => {
claim.resolvedVerdict = true;
claim.confidenceScore = 0.80;
claim.finalized = false;
claim.resolvedAt = null;

claim.transitionTo(ClaimState.RESOLVED, { confidence: 0.90 });

expect(claim.resolvedAt).not.toBeNull();
expect(claim.resolvedAt).toBeInstanceOf(Date);
expect(claim.confidenceScore).toBe(0.90);
});

it('PENDING → RESOLVED sets resolvedAt to a Date', () => {
const before = new Date();
claim.transitionTo(ClaimState.RESOLVED, { verdict: true, confidence: 0.85 });
Expand Down Expand Up @@ -414,5 +440,31 @@ describe('Claim Entity', () => {
expect(claim.getCurrentState()).toBe(ClaimState.PENDING);
expect(claim.resolvedAt).toBeNull();
});

it('legacy claim (RESOLVED with null resolvedAt) updates resolvedAt on transition to FINALIZED (BE-219 Audit)', () => {
claim.resolvedVerdict = true;
claim.confidenceScore = 0.80;
claim.finalized = false;
claim.resolvedAt = null;

claim.transitionTo(ClaimState.FINALIZED);

expect(claim.resolvedAt).not.toBeNull();
expect(claim.resolvedAt).toBeInstanceOf(Date);
expect(claim.finalized).toBe(true);
});

it('legacy claim (RESOLVED with null resolvedAt) updates resolvedAt on transition to RESOLVED (BE-219 Audit)', () => {
claim.resolvedVerdict = true;
claim.confidenceScore = 0.80;
claim.finalized = false;
claim.resolvedAt = null;

claim.transitionTo(ClaimState.RESOLVED, { confidence: 0.90 });

expect(claim.resolvedAt).not.toBeNull();
expect(claim.resolvedAt).toBeInstanceOf(Date);
expect(claim.confidenceScore).toBe(0.90);
});
});
});
12 changes: 10 additions & 2 deletions src/claims/entities/claim.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ export class Claim {
if (data?.confidence !== undefined) {
this.confidenceScore = data.confidence;
}
// resolvedAt is already set; do not overwrite it
// resolvedAt is already set; do not overwrite it unless null (legacy data)
// BE-219 Audit Fix: Ensure legacy claims get a timestamp
if (this.resolvedAt === null || this.resolvedAt === undefined) {
this.resolvedAt = new Date();
}
}
break;

Expand Down Expand Up @@ -161,7 +165,11 @@ export class Claim {
this.confidenceScore = data.confidence;
}
this.finalized = true;
// resolvedAt was already set when transitioning to RESOLVED; do not overwrite it
// resolvedAt was already set when transitioning to RESOLVED; do not overwrite it unless null (legacy data)
// BE-219 Audit Fix: Ensure legacy claims get a timestamp
if (this.resolvedAt === null || this.resolvedAt === undefined) {
this.resolvedAt = new Date();
}
}
break;

Expand Down