fix(app): a failed account load no longer leaves own grants loading
Delta verifier: when the profile or roles read failed, the grant read never ran and the creation page waited forever; the catch now marks the grants failed (form shown, server decides). Store transition tests (ready, loading on change and sign-out, failed), red without the fix. Contract clarification states the failed-read behaviour for the owner.
This commit is contained in:
1 parent
f04bfdd040
commit
e39f69ee6d
3 files changed
+30
-3
No files matched your search
@@ -210,6 +210,8 @@ function applyAuthEvent(
|
||||
profile: null,
|
||||
roles: [],
|
||||
workspace: { status: 'error', failure: classifyRecordError(error) },
|
||||
// The grant read never ran: no page waits on it forever.
|
||||
catalogGrantsStatus: 'failed',
|
||||
})
|
||||
})
|
||||
}, 0)
|
||||
|
||||
@@ -105,13 +105,16 @@ describe('authStore', () => {
|
||||
await flush()
|
||||
await flush()
|
||||
expect(useAuthStore.getState().catalogGrants).toEqual([grant])
|
||||
expect(useAuthStore.getState().catalogGrantsStatus).toBe('ready')
|
||||
fake.emit('SIGNED_IN', fakeSession(fakeUser({ id: 'user-2' })))
|
||||
expect(useAuthStore.getState().catalogGrants).toEqual([])
|
||||
expect(useAuthStore.getState().catalogGrantsStatus).toBe('loading')
|
||||
await flush()
|
||||
await flush()
|
||||
expect(useAuthStore.getState().catalogGrants).toEqual([])
|
||||
fake.emit('SIGNED_OUT', null)
|
||||
expect(useAuthStore.getState().catalogGrants).toEqual([])
|
||||
expect(useAuthStore.getState().catalogGrantsStatus).toBe('loading')
|
||||
})
|
||||
|
||||
it('updateProfile writes the row and keeps the store in sync', async () => {
|
||||
@@ -220,6 +223,25 @@ describe('authStore', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('marks the own grants failed when the account itself cannot be read', async () => {
|
||||
const from = fake.client.from.bind(fake.client)
|
||||
// Any chain on profile_roles answers an error, as a dropped request would.
|
||||
const failed: unknown = new Proxy(() => undefined, {
|
||||
get: (_, key) =>
|
||||
key === 'then'
|
||||
? (resolve: (v: unknown) => void) =>
|
||||
resolve({ data: null, error: { code: '', message: 'FetchError' }, status: 0 })
|
||||
: () => failed,
|
||||
})
|
||||
;(fake.client as unknown as { from: (t: string) => unknown }).from = (table: string) =>
|
||||
table === 'profile_roles' ? failed : from(table as never)
|
||||
stop = useAuthStore.getState().start()
|
||||
fake.emit('SIGNED_IN', fakeSession())
|
||||
await flush()
|
||||
await flush()
|
||||
expect(useAuthStore.getState().catalogGrantsStatus).toBe('failed')
|
||||
})
|
||||
|
||||
it('reports a failed read as an error kind and reads again on refresh', async () => {
|
||||
const from = fake.client.from.bind(fake.client)
|
||||
let failing = true
|
||||
|
||||
Reference in new issue
Block a user