Skip to content

Commit

Permalink
test: Add a test for applySchema over withSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavoguichard committed May 24, 2024
1 parent c555054 commit d99d75a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/tests/constructors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

0 comments on commit d99d75a

Please sign in to comment.