The store reads the personal workspace with the account (ready, loading, inactive, unconfirmed, missing, error; never created in the browser). A change of account drops profile, roles, avatar and workspace at once, and a late answer for the previous account is ignored. generateUuid gives v4 ids on the plain-HTTP LAN origin, where crypto.randomUUID is missing.
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { generateId, generateUuid } from '@/lib/id'
|
|
|
|
describe('generateId', () => {
|
|
it('returns a non-empty string', () => {
|
|
expect(generateId().length).toBeGreaterThan(0)
|
|
})
|
|
|
|
it('returns distinct ids on consecutive calls', () => {
|
|
const a = generateId()
|
|
const b = generateId()
|
|
expect(a).not.toBe(b)
|
|
})
|
|
})
|
|
|
|
describe('generateUuid', () => {
|
|
const V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/
|
|
|
|
it('returns a version 4 uuid', () => {
|
|
expect(generateUuid()).toMatch(V4)
|
|
})
|
|
|
|
it('still returns one where crypto.randomUUID is missing (plain HTTP on the LAN)', () => {
|
|
const original = crypto.randomUUID
|
|
Object.defineProperty(crypto, 'randomUUID', { value: undefined, configurable: true })
|
|
try {
|
|
const ids = new Set(Array.from({ length: 50 }, () => generateUuid()))
|
|
expect([...ids].every((id) => V4.test(id))).toBe(true)
|
|
expect(ids.size).toBe(50)
|
|
} finally {
|
|
Object.defineProperty(crypto, 'randomUUID', { value: original, configurable: true })
|
|
}
|
|
})
|
|
})
|