Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { IRecurringServicePeriodRecord } from '@alga-psa/types';
|
|
import { regenerateRecurringServicePeriods } from '../billingClients/regenerateRecurringServicePeriods';
|
|
|
|
function makeRecord(input: {
|
|
recordId: string;
|
|
scheduleKey: string;
|
|
periodKey: string;
|
|
revision: number;
|
|
duePosition: 'advance' | 'arrears';
|
|
lifecycleState?: IRecurringServicePeriodRecord['lifecycleState'];
|
|
provenance?: IRecurringServicePeriodRecord['provenance'];
|
|
}): IRecurringServicePeriodRecord {
|
|
return {
|
|
kind: 'persisted_service_period_record',
|
|
recordId: input.recordId,
|
|
scheduleKey: input.scheduleKey,
|
|
periodKey: input.periodKey,
|
|
revision: input.revision,
|
|
sourceObligation: {
|
|
tenant: 'tenant-1',
|
|
obligationId: 'line-1',
|
|
obligationType: 'contract_line',
|
|
chargeFamily: 'fixed',
|
|
},
|
|
cadenceOwner: 'contract',
|
|
duePosition: input.duePosition,
|
|
lifecycleState: input.lifecycleState ?? 'generated',
|
|
servicePeriod: {
|
|
start: '2026-03-01',
|
|
end: '2026-04-01',
|
|
semantics: 'half_open',
|
|
},
|
|
invoiceWindow: {
|
|
start: input.duePosition === 'advance' ? '2026-03-01' : '2026-04-01',
|
|
end: input.duePosition === 'advance' ? '2026-04-01' : '2026-05-01',
|
|
semantics: 'half_open',
|
|
},
|
|
activityWindow: null,
|
|
provenance: input.provenance ?? {
|
|
kind: 'generated',
|
|
reasonCode: 'initial_materialization',
|
|
sourceRuleVersion: 'rule-v1',
|
|
sourceRunKey: 'run-v1',
|
|
},
|
|
invoiceLinkage: null,
|
|
createdAt: '2026-03-01T00:00:00Z',
|
|
updatedAt: '2026-03-01T00:00:00Z',
|
|
};
|
|
}
|
|
|
|
describe('regenerateRecurringServicePeriods', () => {
|
|
it('rekeys regenerated records when schedule identity changes', () => {
|
|
const existingArrears = makeRecord({
|
|
recordId: 'record-arrears-r1',
|
|
scheduleKey: 'schedule:tenant-1:contract_line:line-1:contract:arrears',
|
|
periodKey: 'period:2026-03-01:2026-04-01',
|
|
revision: 1,
|
|
duePosition: 'arrears',
|
|
});
|
|
|
|
const candidateAdvance = makeRecord({
|
|
recordId: 'record-advance-r1',
|
|
scheduleKey: 'schedule:tenant-1:contract_line:line-1:contract:advance',
|
|
periodKey: 'period:2026-03-01:2026-04-01',
|
|
revision: 1,
|
|
duePosition: 'advance',
|
|
});
|
|
|
|
const plan = regenerateRecurringServicePeriods({
|
|
existingRecords: [existingArrears],
|
|
candidateRecords: [candidateAdvance],
|
|
regeneratedAt: '2026-03-21T00:00:00Z',
|
|
sourceRuleVersion: 'rule-v2',
|
|
sourceRunKey: 'run-v2',
|
|
});
|
|
|
|
expect(plan.supersededRecords).toHaveLength(1);
|
|
expect(plan.regeneratedRecords).toHaveLength(1);
|
|
expect(plan.regeneratedRecords[0]?.scheduleKey).toBe(candidateAdvance.scheduleKey);
|
|
expect(plan.regeneratedRecords[0]?.duePosition).toBe('advance');
|
|
expect(plan.regeneratedRecords[0]?.recordId).toBe(
|
|
'schedule:tenant-1:contract_line:line-1:contract:advance:period:2026-03-01:2026-04-01:r2',
|
|
);
|
|
});
|
|
});
|