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/clients.test.ts

23 lines
1.0 KiB
TypeScript

// apps/hq/test/clients.test.ts
import { describe, it, expect } from 'vitest'
import { openDb } from '../src/db'
import { createClient, listClients, updateClient } from '../src/repos-clients'
describe('client registry', () => {
it('creates with auto code, searches, updates with audit', async () => {
const db = openDb(':memory:')
const c = await createClient(db, 'u1', { name: 'Malabar Stores', stateCode: '32',
contacts: [{ name: 'Ravi', email: 'ravi@malabar.in' }] })
expect(c.code).toBe('CL0001')
expect(await listClients(db, 'malabar')).toHaveLength(1)
const up = await updateClient(db, 'u1', c.id, { status: 'active', notes: 'AMC due Oct' })
expect(up.status).toBe('active')
const audits = await db.all(`SELECT action FROM audit_log WHERE entity='client'`)
expect(audits.length).toBe(2)
})
it('rejects a bad GSTIN checksum', async () => {
const db = openDb(':memory:')
await expect(createClient(db, 'u1', { name: 'X', stateCode: '32', gstin: '32AAAAA0000A1Z9' })).rejects.toThrow()
})
})