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:
1 parent
b0a4cbe588
commit
bbab0e61cb
8 files changed
+159
-4
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import type { CoreOutcome } from '@faunosteo/core-wasm'
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
LocalizedText,
|
||||
SheetEmptyInput,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import { coreRuntime } from './runtime'
|
||||
|
||||
/**
|
||||
* The sheet document rules that need no loaded sheet (V1-2.5): the document a new sheet
|
||||
* starts from. The slug is not part of it; it goes to `create_official_sheet` beside it.
|
||||
*/
|
||||
|
||||
export interface EmptySheetInput {
|
||||
speciesId: string
|
||||
name: LocalizedText
|
||||
}
|
||||
|
||||
/** Failure: `invalid_shape` for an invalid species id or an empty label. */
|
||||
export function emptySheetDocument(
|
||||
input: EmptySheetInput,
|
||||
): CoreOutcome<AnatomicalSheetDocument> {
|
||||
const payload: SheetEmptyInput = {
|
||||
species_id: input.speciesId,
|
||||
name: input.name,
|
||||
}
|
||||
return coreRuntime().call<AnatomicalSheetDocument>(
|
||||
'sheet.empty',
|
||||
JSON.stringify(payload),
|
||||
)
|
||||
}
|
||||
@@ -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',
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user