- Device domain: updateFromValues, organizeParameters, identifier - BaseModel: full CRUD mock tests - DeviceModel: all methods mocked - Other models: collectionName verification - MainStateMachine: start, handleResponse, state transitions - ConfigurationEvaluationState: init, GPN flow, GPN-unsupported skip - MongodbProvider: getMongoDb guard - device_utils: hash determinism - vitest.config.ts: coverage scope (excludes HTTP layer) - 492 tests passing, 78% line coverage
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
|
|
const mockCollection = {
|
|
findOne: vi.fn(),
|
|
find: vi.fn().mockReturnThis(),
|
|
insertOne: vi.fn(),
|
|
updateOne: vi.fn(),
|
|
deleteOne: vi.fn(),
|
|
deleteMany: vi.fn(),
|
|
countDocuments: vi.fn(),
|
|
sort: vi.fn().mockReturnThis(),
|
|
skip: vi.fn().mockReturnThis(),
|
|
limit: vi.fn().mockReturnThis(),
|
|
toArray: vi.fn().mockResolvedValue([]),
|
|
findOneAndUpdate: vi.fn(),
|
|
}
|
|
const mockDb = { collection: vi.fn().mockReturnValue(mockCollection) }
|
|
vi.mock('#providers/mongodb_provider', () => ({ getMongoDb: () => mockDb }))
|
|
|
|
import ConfigurationModel from '../../../app/models/configuration.js'
|
|
import ConfigurationVersionModel from '../../../app/models/configuration_version.js'
|
|
import FirmwareEntryModel from '../../../app/models/firmware_entry.js'
|
|
import MigrationRouteModel from '../../../app/models/migration_route.js'
|
|
|
|
describe('ConfigurationModel', () => {
|
|
it('has collectionName "configurations"', () => {
|
|
expect(ConfigurationModel.collectionName).toBe('configurations')
|
|
})
|
|
|
|
it('getCollection returns a collection', () => {
|
|
const col = ConfigurationModel.getCollection()
|
|
expect(col).toBeDefined()
|
|
})
|
|
})
|
|
|
|
describe('ConfigurationVersionModel', () => {
|
|
it('has collectionName "configuration_versions"', () => {
|
|
expect(ConfigurationVersionModel.collectionName).toBe('configuration_versions')
|
|
})
|
|
})
|
|
|
|
describe('FirmwareEntryModel', () => {
|
|
it('has collectionName "firmware_entries"', () => {
|
|
expect(FirmwareEntryModel.collectionName).toBe('firmware_entries')
|
|
})
|
|
})
|
|
|
|
describe('MigrationRouteModel', () => {
|
|
it('has collectionName "migration_routes"', () => {
|
|
expect(MigrationRouteModel.collectionName).toBe('migration_routes')
|
|
})
|
|
})
|