| 1 | import { assert, describe, it } from "@effect/vitest" |
| 2 | import { SchemaRepresentation } from "effect" |
| 3 | import { throws } from "../../utils/assert.ts" |
| 4 | |
| 5 | describe("SchemaRepresentation.fromJsonMultiDocument", () => { |
| 6 | it("decodes every root in order", () => { |
| 7 | const input = { |
| 8 | representations: [ |
| 9 | { _tag: "String", checks: [] }, |
| 10 | { _tag: "Number", checks: [] }, |
| 11 | { _tag: "Literal", literal: { type: "string", value: "1" }, checks: [] }, |
| 12 | { _tag: "Literal", literal: { type: "bigint", value: "1" }, checks: [] } |
| 13 | ], |
| 14 | references: {} |
| 15 | } as const |
| 16 | |
| 17 | assert.deepStrictEqual(SchemaRepresentation.fromJsonMultiDocument(input), { |
| 18 | representations: [ |
| 19 | { _tag: "String", checks: [] }, |
| 20 | { _tag: "Number", checks: [] }, |
| 21 | { _tag: "Literal", literal: "1", checks: [] }, |
| 22 | { _tag: "Literal", literal: 1n, checks: [] } |
| 23 | ], |
| 24 | references: {} |
| 25 | }) |
| 26 | }) |
| 27 | |
| 28 | it("decodes shared references", () => { |
| 29 | const input = { |
| 30 | representations: [ |
| 31 | { _tag: "Reference", $ref: "Shared" }, |
| 32 | { _tag: "Reference", $ref: "Shared" } |
| 33 | ], |
| 34 | references: { |
| 35 | Shared: { _tag: "String", checks: [] } |
| 36 | } |
| 37 | } as const |
| 38 | |
| 39 | assert.deepStrictEqual(SchemaRepresentation.fromJsonMultiDocument(input), input) |
| 40 | }) |
| 41 | |
| 42 | it("rejects an empty roots array", () => { |
| 43 | throws( |
| 44 | () => SchemaRepresentation.fromJsonMultiDocument({ representations: [], references: {} }), |
| 45 | `Missing key\n at ["representations"][0]` |
| 46 | ) |
| 47 | }) |
| 48 | }) |