d3ro-voice/apps/mobile-rn/__tests__/devices.test.ts
Yun Chan 53fcdf6305 fix(mobile): list desktop and web devices instead of failing the screen
normalizeRegisteredDevice accepted only android/ios, so one desktop row made
the whole Devices screen fail. Accept the server platform list and show the
platform on each card.
2026-09-27 14:04:49 +09:00

42 lines
1.3 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('accepts desktop and web devices registered to the same account', () => {
for (const platform of ['windows', 'macos', 'web', 'ios'] as const) {
expect(normalizeRegisteredDevice({ ...row, platform }).platform).toBe(platform)
}
})
it('rejects missing timestamps and unsupported platforms', () => {
expect(() => normalizeRegisteredDevice({ ...row, last_seen_at: 'bad' }))
.toThrow(DeviceServiceError)
expect(() => normalizeRegisteredDevice({ ...row, platform: 'unknown' }))
.toThrow('invalid-response')
})
})