@accounter/server
Version:
Accounter GraphQL server
44 lines (36 loc) • 1.58 kB
text/typescript
import { describe, expect, it } from 'vitest';
import type { IGetContractsByIdsResult } from '../../types.js';
import { buildContractDocumentDescription } from '../contracts.helper.js';
function buildContract(overrides: Partial<IGetContractsByIdsResult>): IGetContractsByIdsResult {
return {
product: 'hive',
plan: 'pro',
billing_cycle: 'monthly',
// pg parses `date` columns to local-midnight Date objects; mirror that here so
// formatting is timezone-independent.
start_date: new Date(2025, 0, 15),
end_date: new Date(2026, 0, 14),
...overrides,
} as unknown as IGetContractsByIdsResult;
}
describe('buildContractDocumentDescription', () => {
it('uses the billed month for monthly contracts', () => {
const contract = buildContract({ billing_cycle: 'monthly' });
// The billed month is the issue month itself.
expect(buildContractDocumentDescription(contract, '2026-05-01')).toBe(
'GraphQL Hive Pro Plan - May 2026',
);
});
it('uses the contract start & end dates for annual contracts', () => {
const contract = buildContract({ billing_cycle: 'annual' });
expect(buildContractDocumentDescription(contract, '2025-01-01')).toBe(
'GraphQL Hive Pro Plan January 15th, 2025 → January 14th, 2026',
);
});
it('ignores the issue month for annual contracts', () => {
const contract = buildContract({ billing_cycle: 'annual' });
expect(buildContractDocumentDescription(contract, '2025-01-01')).toBe(
buildContractDocumentDescription(contract, '2025-08-01'),
);
});
});