feat(app): personal workspace in the account store, reset on account change
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.
This commit is contained in:
1 parent
a0e069959b
commit
ff028ec071
4 files changed
+289
-19
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { generateId } from '@/lib/id'
|
||||
import { generateId, generateUuid } from '@/lib/id'
|
||||
|
||||
describe('generateId', () => {
|
||||
it('returns a non-empty string', () => {
|
||||
@@ -12,3 +12,23 @@ describe('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 })
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user