| 1 | import { SchemaGetter, SchemaTransformation } from "effect" |
| 2 | import { describe, it } from "vitest" |
| 3 | import { assertFalse, assertTrue, strictEqual } from "../utils/assert.ts" |
| 4 | |
| 5 | describe("SchemaTransformation", () => { |
| 6 | it("isTransformation", () => { |
| 7 | assertTrue(SchemaTransformation.isTransformation(SchemaTransformation.passthrough())) |
| 8 | assertFalse(SchemaTransformation.isTransformation({ "~effect/SchemaTransformation/Transformation": false })) |
| 9 | }) |
| 10 | |
| 11 | it("pipe", () => { |
| 12 | const transformation = SchemaTransformation.passthrough<string>() |
| 13 | const middleware = new SchemaTransformation.Middleware<string, string, never, never, never, never>( |
| 14 | (effect) => effect, |
| 15 | (effect) => effect |
| 16 | ) |
| 17 | |
| 18 | strictEqual(transformation.pipe((self) => self), transformation) |
| 19 | strictEqual(middleware.pipe((self) => self), middleware) |
| 20 | }) |
| 21 | |
| 22 | it("makeTransformation preserves an existing transformation", () => { |
| 23 | const transformation = SchemaTransformation.makeTransformation({ |
| 24 | decode: SchemaGetter.transform(Number), |
| 25 | encode: SchemaGetter.transform(String) |
| 26 | }) |
| 27 | |
| 28 | strictEqual(SchemaTransformation.makeTransformation(transformation), transformation) |
| 29 | }) |
| 30 | }) |