PSA/packages/billing/tests/billingCycleAlignmentCompatibility.model.test.ts
Hermes 284313f908
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
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

91 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import ContractLineFixedConfig from '../src/models/contractLineFixedConfig';
type QueryState = {
rows: Record<string, any[]>;
updates: Array<{ table: string; payload: Record<string, unknown> }>;
};
class FakeQuery {
constructor(
private readonly table: string,
private readonly state: QueryState,
) {}
where(_filters: Record<string, unknown>) {
return this;
}
first(_columns?: string | string[]) {
return Promise.resolve(this.rows()[0]);
}
update(payload: Record<string, unknown>) {
this.state.updates.push({ table: this.table, payload });
return Promise.resolve(1);
}
private rows() {
return this.state.rows[this.table] ?? [];
}
}
function createFakeKnex(rows: QueryState['rows']) {
const state: QueryState = {
rows,
updates: [],
};
const knex = ((table: string) => new FakeQuery(table, state)) as any;
return {
knex,
updates: state.updates,
};
}
describe('billing_cycle_alignment compatibility model behavior', () => {
it('T109 and T161: fixed config reads, writes, and resets keep billing_cycle_alignment readable while no longer requiring it for new writes', async () => {
const { knex, updates } = createFakeKnex({
contract_lines: [
{
contract_line_id: 'line-1',
custom_rate: 100,
enable_proration: true,
billing_cycle_alignment: null,
created_at: '2026-03-17T00:00:00.000Z',
updated_at: '2026-03-17T00:00:00.000Z',
},
],
});
const model = new ContractLineFixedConfig(knex, 'tenant-1');
const config = await model.getByPlanId('line-1');
expect(config?.billing_cycle_alignment).toBe('prorated');
await model.update('line-1', {
enable_proration: true,
});
expect(updates.at(-1)).toEqual({
table: 'contract_lines',
payload: expect.objectContaining({
enable_proration: true,
billing_cycle_alignment: 'prorated',
}),
});
await model.delete('line-1');
expect(updates.at(-1)).toEqual({
table: 'contract_lines',
payload: expect.objectContaining({
enable_proration: false,
billing_cycle_alignment: 'start',
}),
});
});
});