feat: schema builder's create flow
This commit is contained in:
1 parent
f514146fed
commit
083cc9e23e
71 files changed
+7223
-61
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { ApiError } from '@/composables/useApi'
|
||||
import { useContentTypes } from '@/composables/useContentTypes'
|
||||
import { useSchemaGate, type SchemaGateScope } from '@/composables/useSchemaGate'
|
||||
import { useContentTypesStore } from '@/stores/contentTypes'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
|
||||
vi.mock('@/composables/useContentTypes', () => ({ useContentTypes: vi.fn() }))
|
||||
|
||||
const listContentTypes = vi.fn()
|
||||
const listBuiltinTypes = vi.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia())
|
||||
listContentTypes.mockReset()
|
||||
listBuiltinTypes.mockReset()
|
||||
vi.mocked(useContentTypes).mockReturnValue({ listContentTypes, listBuiltinTypes })
|
||||
const session = useSessionStore()
|
||||
session.$patch({ status: 'ready', session: { role: 'owner' } })
|
||||
})
|
||||
|
||||
async function gate(scope: SchemaGateScope) {
|
||||
const store = useContentTypesStore()
|
||||
await store.load({ builtin: true })
|
||||
return useSchemaGate(scope)
|
||||
}
|
||||
|
||||
describe('schema gate forbidden', () => {
|
||||
it.each([
|
||||
['custom', true],
|
||||
['builtin', false],
|
||||
['all', true],
|
||||
] as const)('scope %s with custom 403 is %s', async (scope, expected) => {
|
||||
listContentTypes.mockRejectedValue(new ApiError(403))
|
||||
listBuiltinTypes.mockResolvedValue([])
|
||||
|
||||
expect((await gate(scope)).forbidden.value).toBe(expected)
|
||||
})
|
||||
|
||||
it.each([
|
||||
['custom', false],
|
||||
['builtin', true],
|
||||
['all', true],
|
||||
] as const)('scope %s with builtin 403 is %s', async (scope, expected) => {
|
||||
listContentTypes.mockResolvedValue([])
|
||||
listBuiltinTypes.mockRejectedValue(new ApiError(403))
|
||||
|
||||
expect((await gate(scope)).forbidden.value).toBe(expected)
|
||||
})
|
||||
|
||||
it('is forbidden for a session that cannot manage content, whatever the scope', async () => {
|
||||
listContentTypes.mockResolvedValue([])
|
||||
listBuiltinTypes.mockResolvedValue([])
|
||||
useSessionStore().$patch({ session: { role: 'user' } })
|
||||
|
||||
expect((await gate('custom')).forbidden.value).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user