Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('ap', () => {
const fab = pipe(
H.header('a', 'a'),
H.map(() => (s: string): number => s.length),
)
const fa = pipe(
H.header('b', 'b'),
H.map(() => 'foo'),
)
const m = pipe(
fab,
H.ap(fa),
)
const c = new MockConnection(new MockRequest())
return assertSuccess(m, c, 3, [
{ type: 'setHeader', name: 'a', value: 'a' },
{ type: 'setHeader', name: 'b', value: 'b' },
])
})
it('should write the headers', () => {
const m = H.header('name', 'value')
const c = new MockConnection(new MockRequest())
return assertSuccess(m, c, undefined, [{ type: 'setHeader', name: 'name', value: 'value' }])
})
})
it('ap', () => {
const fab = pipe(
H.header('a', 'a'),
H.map(() => (s: string): number => s.length),
)
const fa = pipe(
H.header('b', 'b'),
H.map(() => 'foo'),
)
const m = pipe(
fab,
H.ap(fa),
)
const c = new MockConnection(new MockRequest())
return assertSuccess(m, c, 3, [
{ type: 'setHeader', name: 'a', value: 'a' },
{ type: 'setHeader', name: 'b', value: 'b' },
])
})
it('should add the cookie', () => {
const m = H.cookie('name', 'value', {})
const c = new MockConnection(new MockRequest())
return assertSuccess(m, c, undefined, [
{ type: 'setCookie', name: 'name', value: 'value', options: {} },
])
})
})
it('should clear the cookie', () => {
const m = pipe(
H.cookie('name', 'value', {}),
H.ichain(() => H.clearCookie('name', {})),
)
const c = new MockConnection(new MockRequest())
return assertSuccess(m, c, undefined, [
{ type: 'setCookie', name: 'name', value: 'value', options: {} },
{ type: 'clearCookie', name: 'name', options: {} },
])
})
})
it('should validate the body (success case)', () => {
const m = H.decodeBody(t.number.decode)
const c = new MockConnection(new MockRequest({}, undefined, 1))
return assertSuccess(m, c, 1, [])
})
it('should validate the body (failure case)', () => {
const m = H.decodeBody(t.number.decode)
const c = new MockConnection(new MockRequest({}, undefined, 'a'))
return assertFailure(m, c, errors => {
assert.deepStrictEqual(failure(errors), ['Invalid value "a" supplied to : number'])
})
})
})
it('should validate a header (failure case)', () => {
const m = H.decodeHeader('token', t.string.decode)
const c = new MockConnection(new MockRequest({}, undefined, undefined, {}))
return assertFailure(m, c, errors => {
assert.deepStrictEqual(failure(errors), ['Invalid value undefined supplied to : string'])
})
})
})
it('should validate a header (success case)', () => {
const m = H.decodeHeader('token', t.string.decode)
const c = new MockConnection(
new MockRequest({}, undefined, undefined, { token: 'mytoken' }),
)
return assertSuccess(m, c, 'mytoken', [])
})
it('should validate a param (failure case)', () => {
const m = H.decodeParam('foo', t.number.decode)
const c = new MockConnection(new MockRequest({ foo: 'a' }))
return assertFailure(m, c, errors => {
assert.deepStrictEqual(failure(errors), ['Invalid value "a" supplied to : number'])
})
})