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.
sims-hq/apps/hq/test/client-modules.test.ts

25 lines
1.5 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { openDb } from '../src/db'
import { createClient } from '../src/repos-clients'
import { createModule, assignModule, updateClientModule } from '../src/repos-modules'
describe('client modules', () => {
it('enforces allowed kinds and single-subscription', async () => {
const db = openDb(':memory:')
const c = await createClient(db, 'u1', { name: 'Acme', stateCode: '32' })
const m = await createModule(db, 'u1', { code: 'POS', name: 'POS', allowedKinds: ['one_time','yearly'] })
await expect(assignModule(db, 'u1', { clientId: c.id, moduleId: m.id, kind: 'monthly' })).rejects.toThrow(/allow/)
const cm = await assignModule(db, 'u1', { clientId: c.id, moduleId: m.id, kind: 'yearly' })
await expect(assignModule(db, 'u1', { clientId: c.id, moduleId: m.id, kind: 'yearly' })).rejects.toThrow(/already/)
const up = await updateClientModule(db, 'u1', cm.id, { status: 'installed', installedOn: '2026-07-01' })
expect(up.status).toBe('installed')
})
it('allows concurrent rows when multi_subscription = 1', async () => {
const db = openDb(':memory:')
const c = await createClient(db, 'u1', { name: 'Acme', stateCode: '32' })
const m = await createModule(db, 'u1', { code: 'CLOUD', name: 'Cloud', multiSubscription: true })
await assignModule(db, 'u1', { clientId: c.id, moduleId: m.id, kind: 'usage' })
await expect(assignModule(db, 'u1', { clientId: c.id, moduleId: m.id, kind: 'usage' })).resolves.not.toThrow()
})
})