fix(app): unreadable permissions show a retry, never the form (V1-2.5 L1)
Owner checkpoint 2026-11-02: creation page checks loading, server refusal, failed read, then the editor rule; Administration home shows the same notice. reloadAccess re-reads roles and grants without wiping held state; refreshAccount (no caller) removed. Zone panel live region always mounted. Unit and e2e for reviewer-only and editor.
This commit is contained in:
1 parent
14ff890761
commit
4111efa1d1
15 files changed
+856
-56
No files matched your search
@@ -117,6 +117,91 @@ describe('authStore', () => {
|
||||
expect(useAuthStore.getState().catalogGrantsStatus).toBe('loading')
|
||||
})
|
||||
|
||||
describe('reloadAccess', () => {
|
||||
type Answer = { data: unknown; error: unknown; status?: number }
|
||||
const FAILED: Answer = { data: null, error: { code: '', message: 'FetchError' }, status: 0 }
|
||||
const GRANT = { user_id: 'user-1', kind: 'sheet_editor', expires_at: null, revoked_at: null }
|
||||
|
||||
/** Every chain on `table` ends in `answer()`, as a dropped request or a late reply would. */
|
||||
function answerTable(table: string, answer: () => Answer | Promise<Answer>) {
|
||||
const from = fake.client.from.bind(fake.client)
|
||||
const chain: unknown = new Proxy(() => undefined, {
|
||||
get: (_, key) =>
|
||||
key === 'then'
|
||||
? (resolve: (v: unknown) => void, reject: (e: unknown) => void) =>
|
||||
Promise.resolve(answer()).then(resolve, reject)
|
||||
: () => chain,
|
||||
})
|
||||
;(fake.client as unknown as { from: (t: string) => unknown }).from = (t: string) =>
|
||||
t === table ? chain : from(t as never)
|
||||
}
|
||||
|
||||
async function signedIn() {
|
||||
fake.tables.profiles = [fakeProfile(), fakeProfile({ id: 'user-2' })]
|
||||
stop = useAuthStore.getState().start()
|
||||
fake.emit('SIGNED_IN', fakeSession())
|
||||
await flush()
|
||||
await flush()
|
||||
}
|
||||
|
||||
it('goes loading then ready, replacing the roles and the grants', async () => {
|
||||
await signedIn()
|
||||
expect(useAuthStore.getState().roles).toEqual(['admin'])
|
||||
fake.tables.profile_roles = [{ user_id: 'user-1', role: 'owner', revoked_at: null }]
|
||||
fake.tables.anatomical_catalog_grants = [GRANT]
|
||||
const reload = useAuthStore.getState().reloadAccess()
|
||||
expect(useAuthStore.getState().catalogGrantsStatus).toBe('loading')
|
||||
await reload
|
||||
const s = useAuthStore.getState()
|
||||
expect(s.catalogGrantsStatus).toBe('ready')
|
||||
expect(s.roles).toEqual(['owner'])
|
||||
expect(s.catalogGrants).toEqual([GRANT])
|
||||
})
|
||||
|
||||
it.each(['anatomical_catalog_grants', 'profile_roles'])(
|
||||
'ends failed with no grants and keeps the roles, profile and workspace when the %s read rejects',
|
||||
async (table) => {
|
||||
fake.tables.workspaces = [{ id: 'ws-1', personal_user_id: 'user-1' }]
|
||||
fake.tables.anatomical_catalog_grants = [GRANT]
|
||||
await signedIn()
|
||||
const before = useAuthStore.getState()
|
||||
expect(before.catalogGrants).toEqual([GRANT])
|
||||
answerTable(table, () => FAILED)
|
||||
await expect(useAuthStore.getState().reloadAccess()).resolves.toBeUndefined()
|
||||
const s = useAuthStore.getState()
|
||||
expect(s.catalogGrantsStatus).toBe('failed')
|
||||
expect(s.catalogGrants).toEqual([])
|
||||
expect(s.roles).toEqual(['admin'])
|
||||
expect(s.profile).toEqual(before.profile)
|
||||
expect(s.workspace).toEqual({ status: 'ready', id: 'ws-1' })
|
||||
},
|
||||
)
|
||||
|
||||
it('ends failed and resolves without a user', async () => {
|
||||
useAuthStore.setState({ catalogGrants: [], catalogGrantsStatus: 'ready' })
|
||||
await expect(useAuthStore.getState().reloadAccess()).resolves.toBeUndefined()
|
||||
expect(useAuthStore.getState().catalogGrantsStatus).toBe('failed')
|
||||
})
|
||||
|
||||
it('drops a late answer once another account signed in', async () => {
|
||||
await signedIn()
|
||||
const releases: Array<(a: Answer) => void> = []
|
||||
answerTable(
|
||||
'anatomical_catalog_grants',
|
||||
() => new Promise<Answer>((resolve) => releases.push(resolve)),
|
||||
)
|
||||
const reload = useAuthStore.getState().reloadAccess()
|
||||
await flush()
|
||||
fake.emit('SIGNED_IN', fakeSession(fakeUser({ id: 'user-2' })))
|
||||
releases.forEach((release) => release({ data: [GRANT], error: null }))
|
||||
await reload
|
||||
await flush()
|
||||
expect(useAuthStore.getState().catalogGrants).toEqual([])
|
||||
expect(useAuthStore.getState().roles).not.toEqual(['owner'])
|
||||
expect(useAuthStore.getState().user?.id).toBe('user-2')
|
||||
})
|
||||
})
|
||||
|
||||
it('updateProfile writes the row and keeps the store in sync', async () => {
|
||||
stop = useAuthStore.getState().start()
|
||||
fake.emit('SIGNED_IN', fakeSession())
|
||||
|
||||
Reference in new issue
Block a user