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.
This commit is contained in:
bchanot committed 2026-11-02 16:19:49 +01:00
1 parent b0a4cbe588
commit bbab0e61cb
8 files changed
+159 -4

No files matched your search

@@ -0,0 +1,37 @@
/**
* 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',
})
}
})
})