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.
46 lines
1.9 KiB
TypeScript
46 lines
1.9 KiB
TypeScript
// apps/hq/test/milestone-status.test.ts — milestone→status auto-drive (never downgrade).
|
|
import { describe, it, expect } from 'vitest'
|
|
import { openDb } from '../src/db'
|
|
import { seedIfEmpty } from '../src/seed'
|
|
import { createClient } from '../src/repos-clients'
|
|
import { createModule, assignModule, getClientModule } from '../src/repos-modules'
|
|
import { setMilestone } from '../src/repos-milestones'
|
|
|
|
async function world() {
|
|
const db = openDb(':memory:')
|
|
await seedIfEmpty(db)
|
|
const c = await createClient(db, 'u1', { name: 'Kothavara SCB', stateCode: '32' })
|
|
const m = await createModule(db, 'u1', { code: 'SMS', name: 'Bulk SMS' })
|
|
const cm = await assignModule(db, 'u1', { clientId: c.id, moduleId: m.id, kind: 'yearly' })
|
|
return { db, c, m, cmId: cm.id }
|
|
}
|
|
|
|
describe('milestone → status auto-drive (D22 status line)', () => {
|
|
it('ticking installation advances status to installed', async () => {
|
|
const { db, cmId } = await world()
|
|
await setMilestone(db, 'u1', cmId, 'installation', true)
|
|
const cm = await getClientModule(db, cmId)
|
|
expect(cm!.status).toBe('installed')
|
|
})
|
|
|
|
it('ticking go_live advances status to live', async () => {
|
|
const { db, cmId } = await world()
|
|
await setMilestone(db, 'u1', cmId, 'go_live', true)
|
|
expect((await getClientModule(db, cmId))!.status).toBe('live')
|
|
})
|
|
|
|
it('unticking never downgrades status', async () => {
|
|
const { db, cmId } = await world()
|
|
await setMilestone(db, 'u1', cmId, 'go_live', true)
|
|
await setMilestone(db, 'u1', cmId, 'go_live', false)
|
|
expect((await getClientModule(db, cmId))!.status).toBe('live')
|
|
})
|
|
|
|
it('a lower step never downgrades a higher status', async () => {
|
|
const { db, cmId } = await world()
|
|
await setMilestone(db, 'u1', cmId, 'go_live', true) // live
|
|
await setMilestone(db, 'u1', cmId, 'installation', true) // still live
|
|
expect((await getClientModule(db, cmId))!.status).toBe('live')
|
|
})
|
|
})
|