You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.8 KiB
TypeScript
40 lines
1.8 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { openDb } from '../src/db'
|
|
import { seedIfEmpty } from '../src/seed'
|
|
import { createClient } from '../src/repos-clients'
|
|
import { recordPayment } from '../src/repos-payments'
|
|
import {
|
|
createAmc, listAmc, generateAmcRenewalInvoice, amcPaidStatus, getAmc,
|
|
} from '../src/repos-amc'
|
|
|
|
async function setup() {
|
|
const db = openDb(':memory:'); await seedIfEmpty(db) // seeds company.state_code, GST18, AMC module
|
|
const c = await createClient(db, 'u1', { name: 'Acme', stateCode: '32' })
|
|
return { db, c }
|
|
}
|
|
|
|
describe('amc contracts', () => {
|
|
it('creates, generates a renewal invoice, and derives paid from settlement', async () => {
|
|
const { db, c } = await setup()
|
|
const amc = await createAmc(db, 'u1', {
|
|
clientId: c.id, coverage: 'On-site support', periodFrom: '2026-04-01', periodTo: '2027-03-31',
|
|
amountPaise: 20_000_00,
|
|
})
|
|
expect(await listAmc(db, c.id)).toHaveLength(1)
|
|
expect(await amcPaidStatus(db, (await getAmc(db, amc.id))!)).toBe('unbilled')
|
|
const inv = await generateAmcRenewalInvoice(db, 'u1', amc.id)
|
|
expect(inv.docType).toBe('INVOICE')
|
|
expect(inv.payablePaise).toBe(23_600_00) // 20,000 + 18% GST intra-state
|
|
expect(await amcPaidStatus(db, (await getAmc(db, amc.id))!)).toBe('unpaid')
|
|
await recordPayment(db, 'u1', { clientId: c.id, receivedOn: '2026-07-10', mode: 'bank', amountPaise: 23_600_00 })
|
|
expect(await amcPaidStatus(db, (await getAmc(db, amc.id))!)).toBe('paid')
|
|
})
|
|
it('honours the legacy_paid flag for imported contracts without an invoice', async () => {
|
|
const { db, c } = await setup()
|
|
const amc = await createAmc(db, 'u1', {
|
|
clientId: c.id, periodFrom: '2025-04-01', periodTo: '2026-03-31', amountPaise: 10_000_00, legacyPaid: true,
|
|
})
|
|
expect(await amcPaidStatus(db, (await getAmc(db, amc.id))!)).toBe('paid')
|
|
})
|
|
})
|