36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import {
|
|
DeviceServiceError,
|
|
normalizeRegisteredDevice,
|
|
} from '../src/features/devices/device-service'
|
|
|
|
describe('device response contract', () => {
|
|
const row = {
|
|
id: 'device-1',
|
|
user_id: 'user-1',
|
|
installation_id: '00000000-0000-4000-8000-000000000001',
|
|
platform: 'android',
|
|
device_name: 'Pixel 7',
|
|
app_version: '1.0.0',
|
|
os_version: 'Android 14',
|
|
push_token: null,
|
|
last_seen_at: '2026-08-21T00:00:00Z',
|
|
revoked_at: null,
|
|
created_at: '2026-08-20T00:00:00Z',
|
|
updated_at: '2026-08-21T00:00:00Z',
|
|
}
|
|
|
|
it('normalizes an owned registered device', () => {
|
|
expect(normalizeRegisteredDevice(row)).toMatchObject({
|
|
installationId: row.installation_id,
|
|
deviceName: 'Pixel 7',
|
|
revokedAt: null,
|
|
})
|
|
})
|
|
|
|
it('rejects missing timestamps and unsupported platforms', () => {
|
|
expect(() => normalizeRegisteredDevice({ ...row, last_seen_at: 'bad' }))
|
|
.toThrow(DeviceServiceError)
|
|
expect(() => normalizeRegisteredDevice({ ...row, platform: 'unknown' }))
|
|
.toThrow('invalid-response')
|
|
})
|
|
})
|