2026-03-03 12:50:24 -06:00
|
|
|
import { describe, it, expect, beforeEach } from 'vitest'
|
|
|
|
|
import { db, getLastSync, setLastSync, getSession, saveSession, clearSession } from './db.js'
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
await Promise.all(db.tables.map(t => t.clear()))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('db schema', () => {
|
|
|
|
|
it('has expected tables', () => {
|
|
|
|
|
const names = db.tables.map(t => t.name).sort()
|
|
|
|
|
expect(names).toEqual([
|
2026-03-04 15:27:03 -06:00
|
|
|
'departments', 'event', 'meta',
|
|
|
|
|
'participants', 'session', 'shifts', 'tickets', 'volunteer_shifts', 'volunteers',
|
2026-03-03 12:50:24 -06:00
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('session', () => {
|
|
|
|
|
it('returns undefined when no session', async () => {
|
|
|
|
|
const s = await getSession()
|
|
|
|
|
expect(s).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('saves and retrieves session', async () => {
|
|
|
|
|
await saveSession('tok123', { id: 1, username: 'admin', role: 'admin' })
|
|
|
|
|
const s = await getSession()
|
|
|
|
|
expect(s.token).toBe('tok123')
|
|
|
|
|
expect(s.user.username).toBe('admin')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('clears session and meta', async () => {
|
|
|
|
|
await saveSession('tok123', { id: 1 })
|
|
|
|
|
await setLastSync('2026-01-01T00:00:00Z')
|
|
|
|
|
await clearSession()
|
|
|
|
|
expect(await getSession()).toBeUndefined()
|
|
|
|
|
expect(await getLastSync()).toBe('')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('lastSync', () => {
|
|
|
|
|
it('returns empty string when unset', async () => {
|
|
|
|
|
expect(await getLastSync()).toBe('')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('roundtrips a timestamp', async () => {
|
|
|
|
|
await setLastSync('2026-03-01T12:00:00Z')
|
|
|
|
|
expect(await getLastSync()).toBe('2026-03-01T12:00:00Z')
|
|
|
|
|
})
|
|
|
|
|
})
|