|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | +// |
| 3 | +// Phase 2 of the spec-derived create-shape contract: the authoritative minimal |
| 4 | +// create seeds (packages/spec/src/kernel/metadata-create-seeds.ts) must reach |
| 5 | +// the Studio designer / CLI / API clients through the real `/meta/types` |
| 6 | +// registry response, so consumers derive their create defaults from the spec |
| 7 | +// instead of re-inventing them (the drift that produced the dashboard-`layout` |
| 8 | +// and action-`body` create-save 422s). Exercised end-to-end over real HTTP. |
| 9 | + |
| 10 | +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; |
| 11 | +import showcaseStack from '@objectstack/example-showcase'; |
| 12 | +import { bootStack, type VerifyStack } from '@objectstack/verify'; |
| 13 | +import { getMetadataCreateSeed, listMetadataCreateSeedTypes } from '@objectstack/spec/kernel'; |
| 14 | + |
| 15 | +describe('dogfood: /meta/types exposes authoritative create seeds (spec-derived create-shape contract)', () => { |
| 16 | + let stack: VerifyStack; |
| 17 | + let token: string; |
| 18 | + let entries: Array<Record<string, unknown>>; |
| 19 | + |
| 20 | + beforeAll(async () => { |
| 21 | + stack = await bootStack(showcaseStack); |
| 22 | + token = await stack.signIn(); |
| 23 | + const res = await stack.apiAs(token, 'GET', '/meta'); // GET {prefix} lists all metadata types (entries[]) |
| 24 | + expect(res.status).toBe(200); |
| 25 | + const body = (await res.json()) as { entries?: Array<Record<string, unknown>> }; |
| 26 | + entries = body.entries ?? []; |
| 27 | + expect(entries.length).toBeGreaterThan(0); |
| 28 | + }, 90_000); |
| 29 | + |
| 30 | + afterAll(async () => { |
| 31 | + await stack?.stop(); |
| 32 | + }); |
| 33 | + |
| 34 | + const entryFor = (type: string) => entries.find((e) => e.type === type); |
| 35 | + |
| 36 | + it('carries the dashboard create seed (widgets: [])', () => { |
| 37 | + const seed = entryFor('dashboard')?.createSeed as Record<string, unknown> | undefined; |
| 38 | + expect(seed).toBeDefined(); |
| 39 | + expect(seed).toMatchObject({ widgets: [] }); |
| 40 | + }); |
| 41 | + |
| 42 | + it('carries the action create seed with a valid executable body', () => { |
| 43 | + const seed = entryFor('action')?.createSeed as Record<string, unknown> | undefined; |
| 44 | + expect(seed).toBeDefined(); |
| 45 | + expect(seed?.type).toBe('script'); |
| 46 | + expect((seed?.body as Record<string, unknown>)?.language).toBe('js'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('omits a seed for report (a canvas-create type whose dataset is picked interactively)', () => { |
| 50 | + // report IS a registered type but is intentionally absent from the seed |
| 51 | + // registry — its minimal valid shape needs a dataset chosen on the canvas, |
| 52 | + // not a static literal. The designer falls back / uses canvas create. |
| 53 | + expect(entryFor('report')).toBeDefined(); |
| 54 | + expect(entryFor('report')?.createSeed).toBeUndefined(); |
| 55 | + }); |
| 56 | + |
| 57 | + it('every seeded type that is also a registered /meta/types entry exposes its exact seed', () => { |
| 58 | + for (const type of listMetadataCreateSeedTypes()) { |
| 59 | + const entry = entryFor(type); |
| 60 | + if (!entry) continue; // type may not be registered in this app — skip |
| 61 | + expect(entry.createSeed, `${type} entry is missing its create seed`).toEqual(getMetadataCreateSeed(type)); |
| 62 | + } |
| 63 | + }); |
| 64 | +}); |
0 commit comments