Files
faunosteo/apps/app/tests/unit/core.sheetDocumentOps.test.ts
T
bchanot bbab0e61cb feat(domain): sheet.empty free op for a new sheet's document (V1-2.5 C)
Wraps create_empty_sheet_document; refusals invalid_shape / invalid_json; ts-rs SheetEmptyInput, core-wasm proof, app wrapper emptySheetDocument.
2026-11-02 16:19:49 +01:00

38 lines
1.2 KiB
TypeScript

/**
* V1-2.5: the new sheet's document comes from the core (contract §7.4), through the
* page's runtime; the wrapper maps the input names and passes the closed refusal on.
*/
import { beforeAll, describe, expect, it } from 'vitest'
import { setCoreRuntime } from '@/core/runtime'
import { emptySheetDocument } from '@/core/sheetDocumentOps'
import { testCoreRuntime } from '../helpers/core'
const name = { fr: 'Nouvelle fiche', en: 'New sheet' }
beforeAll(async () => {
setCoreRuntime(await testCoreRuntime())
})
describe('emptySheetDocument', () => {
it('answers the empty document of the species, named', () => {
const outcome = emptySheetDocument({ speciesId: 'equine', name })
expect(outcome.ok).toBe(true)
if (!outcome.ok) return
expect(outcome.value.species_id).toBe('equine')
expect(outcome.value.name).toEqual(name)
expect(outcome.value.views.map((view) => view.id)).toEqual(['view-main'])
})
it('refuses an invalid species id or an empty label', () => {
for (const input of [
{ speciesId: 'Not An Id', name },
{ speciesId: 'equine', name: { fr: name.fr, en: '' } },
]) {
expect(emptySheetDocument(input)).toMatchObject({
ok: false,
kind: 'invalid_shape',
})
}
})
})