Files
hermes-ui/tests/server/mcu-devices-store.test.ts
T
toor 1e9ea89d86
Build / build (push) Canceled after 0s
NPM Lockfile Check / npm ci --ignore-scripts (push) Canceled after 0s
Playwright / e2e (push) Canceled after 0s
chore: bootstrap hermes-ui skeleton from 0.6.29 snapshot
Import the client, server, skills, tests, and build scripts as the starting
point for the rebuild, then trim the surfaces this project does not ship:
Electron desktop packaging, the marketing website, and the ESP32 firmware
tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows.

Rename the package and CLI entry points to hermes-ui, drop the prepare hook so
npm ci no longer triggers a build, and drop the removed tsconfig and nodemon
references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs
so the documented package map and hard rules match this repository.

reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
2026-10-16 10:34:35 +08:00

89 lines
2.7 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
describe('MCU devices store', () => {
let db: any = null
beforeEach(async () => {
vi.resetModules()
const { DatabaseSync } = await import('node:sqlite')
db = new DatabaseSync(':memory:')
vi.doMock('../../packages/server/src/db/index', () => ({
getDb: () => db,
getStoragePath: () => ':memory:',
}))
const { initAllHermesTables } = await import('../../packages/server/src/db/hermes/schemas')
initAllHermesTables()
})
afterEach(() => {
db?.close()
db = null
vi.doUnmock('../../packages/server/src/db/index')
vi.resetModules()
})
it('stores official and unofficial MCU devices', async () => {
const { createMcuDevice, listMcuDevices } = await import('../../packages/server/src/db/hermes/mcu-devices-store')
const official = createMcuDevice({
name: 'Official Box',
deviceCode: 'official-code',
isOfficial: true,
})
const unofficial = createMcuDevice({
name: 'Unofficial Box',
deviceCode: 'unofficial-code',
isOfficial: false,
})
expect(official.is_official).toBe(true)
expect(unofficial.is_official).toBe(false)
expect(listMcuDevices().map(device => device.device_code).sort()).toEqual(['official-code', 'unofficial-code'])
})
it('rejects duplicate device codes', async () => {
const { createMcuDevice } = await import('../../packages/server/src/db/hermes/mcu-devices-store')
createMcuDevice({
name: 'Box',
deviceCode: 'duplicate-code',
isOfficial: true,
})
expect(() => createMcuDevice({
name: 'Box 2',
deviceCode: 'duplicate-code',
isOfficial: false,
})).toThrow('mcu_device_exists')
})
it('updates device name only', async () => {
const { createMcuDevice, updateMcuDeviceName } = await import('../../packages/server/src/db/hermes/mcu-devices-store')
const created = createMcuDevice({
name: 'Old Name',
deviceCode: 'editable-code',
isOfficial: true,
})
const updated = updateMcuDeviceName(created.id, 'New Name')
expect(updated.name).toBe('New Name')
expect(updated.device_code).toBe('editable-code')
expect(updated.is_official).toBe(true)
})
it('deletes MCU devices', async () => {
const { createMcuDevice, deleteMcuDevice, listMcuDevices } = await import('../../packages/server/src/db/hermes/mcu-devices-store')
const created = createMcuDevice({
name: 'Delete Me',
deviceCode: 'delete-code',
isOfficial: false,
})
expect(deleteMcuDevice(created.id)).toBe(true)
expect(deleteMcuDevice(created.id)).toBe(false)
expect(listMcuDevices()).toEqual([])
})
})