fix(arktype-validator): add failing test for cookie header
parent
abb260632f
commit
1b7e645c3d
|
@ -35,6 +35,17 @@ describe('Basic', () => {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
app.get(
|
||||||
|
'/headers',
|
||||||
|
arktypeValidator(
|
||||||
|
'header',
|
||||||
|
type({
|
||||||
|
'User-Agent': 'string',
|
||||||
|
})
|
||||||
|
),
|
||||||
|
(c) => c.json({ success: true, userAgent: c.header('User-Agent') })
|
||||||
|
)
|
||||||
|
|
||||||
type Actual = ExtractSchema<typeof route>
|
type Actual = ExtractSchema<typeof route>
|
||||||
type Expected = {
|
type Expected = {
|
||||||
'/author': {
|
'/author': {
|
||||||
|
@ -98,6 +109,23 @@ describe('Basic', () => {
|
||||||
const data = (await res.json()) as { success: boolean }
|
const data = (await res.json()) as { success: boolean }
|
||||||
expect(data['success']).toBe(false)
|
expect(data['success']).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("doesn't return cookies after headers validation", async () => {
|
||||||
|
const req = new Request('http://localhost/headers', {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'invalid',
|
||||||
|
Cookie: 'SECRET=123',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const res = await app.request(req)
|
||||||
|
expect(res).not.toBeNull()
|
||||||
|
expect(res.status).toBe(400)
|
||||||
|
const data = (await res.json()) as { succcess: false; errors: type.errors }
|
||||||
|
expect(data.errors).toHaveLength(1)
|
||||||
|
console.log(data.errors)
|
||||||
|
expect(data.errors[0].data).not.toHaveProperty('cookie')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('With Hook', () => {
|
describe('With Hook', () => {
|
||||||
|
|
|
@ -23,7 +23,7 @@ export const arktypeValidator = <
|
||||||
} = {
|
} = {
|
||||||
in: HasUndefined<I> extends true ? { [K in Target]?: I } : { [K in Target]: I }
|
in: HasUndefined<I> extends true ? { [K in Target]?: I } : { [K in Target]: I }
|
||||||
out: { [K in Target]: O }
|
out: { [K in Target]: O }
|
||||||
}
|
},
|
||||||
>(
|
>(
|
||||||
target: Target,
|
target: Target,
|
||||||
schema: T,
|
schema: T,
|
||||||
|
|
Loading…
Reference in New Issue