Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

row-shape.test.ts

42 lines1.5 KB

1import { describe, expect, it } from 'vitest'
2​
3import { openApiDocument } from './openapi.ts'
4import { MODEL_ROW_SHAPE, modelRowShapeHash } from './row-shape.ts'
5​
6type Schemas = Parameters<typeof modelRowShapeHash>[0]
7​
8function schemasCopy(): NonNullable<Schemas> {
9 return structuredClone(
10 openApiDocument.components.schemas,
11 ) as unknown as NonNullable<Schemas>
13​
14describe('MODEL_ROW_SHAPE', () => {
15 it('matches the row schemas in openapi.ts', async () => {
16 const hash = await modelRowShapeHash()
17 expect(
18 hash,
19 'The served model row changed shape. Bump MODEL_ROW_SHAPE.version, set its hash to this value, rewrite notes, and add a @modelschemas/client changeset (README "API stability").',
20 ).toBe(MODEL_ROW_SHAPE.hash)
21 })
22​
23 it('changes when a referenced schema changes shape', async () => {
24 const schemas = schemasCopy()
25 const before = await modelRowShapeHash(schemas)
26 const source = schemas.FactSource as {
27 properties: Record<string, unknown>
28 }
29 source.properties.extra = { type: 'string' }
30 expect(await modelRowShapeHash(schemas)).not.toBe(before)
31 })
32​
33 it('ignores a reworded description', async () => {
34 const schemas = schemasCopy()
35 const before = await modelRowShapeHash(schemas)
36 const model = schemas.Model as {
37 properties: { releasedAt: { description?: string } }
38 }
39 model.properties.releasedAt.description = 'Reworded.'
40 expect(await modelRowShapeHash(schemas)).toBe(before)
41 })
42})