Files
geo/apps/desktop-client/src/main/device-id.test.ts
T

55 lines
1.2 KiB
TypeScript
Raw Normal View History

import { describe, expect, it, vi } from 'vitest'
vi.mock('electron/main', () => ({
app: {
getPath: () => '/tmp/geo-rankly-test-user-data',
},
}))
import { resolveDesktopClientID } from './device-id'
describe('desktop device client id', () => {
it('is stable for the same hardware and account scope', () => {
const scope = {
tenant_id: 1,
workspace_id: 2,
user_id: 3,
}
expect(resolveDesktopClientID(scope)).toBe(resolveDesktopClientID(scope))
})
it('keeps different account scopes separate on the same hardware', () => {
const base = resolveDesktopClientID({
tenant_id: 1,
workspace_id: 2,
user_id: 3,
})
expect(
resolveDesktopClientID({
tenant_id: 1,
workspace_id: 2,
user_id: 4,
}),
).not.toBe(base)
expect(
resolveDesktopClientID({
tenant_id: 1,
workspace_id: 5,
user_id: 3,
}),
).not.toBe(base)
})
it('rejects missing account scope instead of generating a random id', () => {
expect(() =>
resolveDesktopClientID({
tenant_id: 1,
workspace_id: 0,
user_id: 3,
}),
).toThrow('desktop_client_id_scope_invalid')
})
})