Added tests, shift 'delete'. Fixed overnight shifts, sync, error handling.
This commit is contained in:
parent
9d0fa1f0af
commit
f9c4facad6
21 changed files with 2522 additions and 40 deletions
49
frontend/src/db.test.js
Normal file
49
frontend/src/db.test.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
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([
|
||||
'attendees', 'departments', 'event', 'meta',
|
||||
'outbox', 'session', 'shifts', 'volunteer_shifts', 'volunteers',
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
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')
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue