| 1 | import { assert, describe, it } from "@effect/vitest" |
| 2 | import { Schema, SchemaRepresentation } from "effect" |
| 3 | |
| 4 | describe("HTTP schema representations", () => { |
| 5 | it("generates code for declaration schemas", () => { |
| 6 | const document = SchemaRepresentation.toRepresentations([ |
| 7 | Schema.Headers.ast, |
| 8 | Schema.Cookies.ast, |
| 9 | Schema.Cookie.ast, |
| 10 | Schema.UrlParams.ast |
| 11 | ]) |
| 12 | |
| 13 | assert.deepStrictEqual( |
| 14 | document.representations.map((representation) => |
| 15 | representation._tag === "Declaration" ? representation.representation : undefined |
| 16 | ), |
| 17 | [ |
| 18 | { id: "effect/http/Headers", payload: null }, |
| 19 | { id: "effect/http/Cookies", payload: null }, |
| 20 | { id: "effect/http/Cookie", payload: null }, |
| 21 | { id: "effect/http/UrlParams", payload: null } |
| 22 | ] |
| 23 | ) |
| 24 | |
| 25 | const output = SchemaRepresentation.toCodeDocument(document) |
| 26 | |
| 27 | assert.deepStrictEqual(output.codes, [ |
| 28 | { runtime: `Schema.Headers.annotate({ "expected": "Headers" })`, Type: "Headers.Headers" }, |
| 29 | { runtime: `Schema.Cookies.annotate({ "expected": "Cookies" })`, Type: "Cookies.Cookies" }, |
| 30 | { runtime: `Schema.Cookie.annotate({ "expected": "Cookie" })`, Type: "Cookies.Cookie" }, |
| 31 | { runtime: `Schema.UrlParams.annotate({ "expected": "UrlParams" })`, Type: "UrlParams.UrlParams" } |
| 32 | ]) |
| 33 | assert.deepStrictEqual(output.artifacts, [ |
| 34 | { |
| 35 | _tag: "Import", |
| 36 | importDeclaration: `import * as Headers from "effect/http/Headers"` |
| 37 | }, |
| 38 | { |
| 39 | _tag: "Import", |
| 40 | importDeclaration: `import * as Cookies from "effect/http/Cookies"` |
| 41 | }, |
| 42 | { |
| 43 | _tag: "Import", |
| 44 | importDeclaration: `import * as UrlParams from "effect/http/UrlParams"` |
| 45 | } |
| 46 | ]) |
| 47 | }) |
| 48 | }) |