From d99d75a7ae00b84191d0b835b85a3cbf6c2262d2 Mon Sep 17 00:00:00 2001 From: Guga Guichard Date: Fri, 24 May 2024 20:41:31 -0300 Subject: [PATCH] test: Add a test for applySchema over withSchema --- src/tests/constructors.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tests/constructors.test.ts b/src/tests/constructors.test.ts index 27fd5c19..14da023e 100644 --- a/src/tests/constructors.test.ts +++ b/src/tests/constructors.test.ts @@ -458,4 +458,19 @@ describe('applySchema', () => { assertEquals(await handler({ id: 1 }, { uid: 2 }), success([1, 2])) }) + + it('can be used as a layer on top of withSchema fn', async () => { + const fn = withSchema(z.object({ id: z.number() }))(({ id }) => id + 1) + const prepareSchema = z.string().transform((v) => ({ id: Number(v) })) + const handler = applySchema(prepareSchema)(fn) + type _R = Expect< + Equal< + typeof handler, + Composable<(input?: unknown, environment?: unknown) => number> + > + > + + const result = await handler('1') + assertEquals(result, success(2)) + }) })