initial commit
This commit is contained in:
32
test/unit/migrateFeedsToDevices.spec.js
Normal file
32
test/unit/migrateFeedsToDevices.spec.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { getDb, setDbPathForTest } from '../../server/utils/db.js'
|
||||
import { migrateFeedsToDevices } from '../../server/utils/migrateFeedsToDevices.js'
|
||||
|
||||
describe('migrateFeedsToDevices', () => {
|
||||
beforeEach(() => {
|
||||
setDbPathForTest(':memory:')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
setDbPathForTest(null)
|
||||
})
|
||||
|
||||
it('runs without error when devices table is empty', async () => {
|
||||
const db = await getDb()
|
||||
await expect(migrateFeedsToDevices()).resolves.toBeUndefined()
|
||||
const rows = await db.all('SELECT id FROM devices')
|
||||
expect(rows.length).toBeGreaterThanOrEqual(0)
|
||||
})
|
||||
|
||||
it('is no-op when devices already has rows', async () => {
|
||||
const db = await getDb()
|
||||
await db.run(
|
||||
'INSERT INTO devices (id, name, device_type, vendor, lat, lng, stream_url, source_type, config) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
['existing', 'Existing', 'feed', null, 0, 0, '', 'mjpeg', null],
|
||||
)
|
||||
await migrateFeedsToDevices()
|
||||
const rows = await db.all('SELECT id FROM devices')
|
||||
expect(rows).toHaveLength(1)
|
||||
expect(rows[0].id).toBe('existing')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user