2021-10-10 20:38:12 +00:00
|
|
|
import { Eltro as t, assert} from 'eltro'
|
2022-03-16 10:41:25 +00:00
|
|
|
import { QueryHandler, JsonHandler } from '../flaska.mjs'
|
2021-10-10 20:38:12 +00:00
|
|
|
|
|
|
|
t.describe('#QueryHandler()', function() {
|
|
|
|
let queryHandler = QueryHandler()
|
|
|
|
|
|
|
|
t.test('should return a handler', function() {
|
|
|
|
assert.strictEqual(typeof(queryHandler), 'function')
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('should support separating query from request url', function() {
|
|
|
|
const assertItem1 = 'safdsfdsag'
|
|
|
|
const assertItem2 = 'hello%20world'
|
|
|
|
const ctx = {
|
|
|
|
req: {
|
|
|
|
url: `/some/path?item1=${assertItem1}&ITEM2=${assertItem2}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
queryHandler(ctx)
|
|
|
|
assert.strictEqual(ctx.query.get('item1'), assertItem1)
|
|
|
|
assert.strictEqual(ctx.query.get('ITEM2'), 'hello world')
|
|
|
|
})
|
|
|
|
})
|
2022-03-16 10:41:25 +00:00
|
|
|
|
|
|
|
t.describe('#JsonHandler()', function() {
|
|
|
|
let jsonHandler = JsonHandler()
|
|
|
|
|
|
|
|
t.test('should return a handler', function() {
|
|
|
|
assert.strictEqual(typeof(jsonHandler), 'function')
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('should support separating query from request url', async function() {
|
|
|
|
const assertBody = { a: 1, temp: 'test', hello: 'world'}
|
|
|
|
let parsed = JSON.stringify(assertBody)
|
|
|
|
|
|
|
|
const ctx = {
|
|
|
|
req: [
|
|
|
|
Promise.resolve(Buffer.from(parsed.slice(0, parsed.length / 2))),
|
|
|
|
Promise.resolve(Buffer.from(parsed.slice(parsed.length / 2))),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
await jsonHandler(ctx)
|
|
|
|
assert.notStrictEqual(ctx.req.body, assertBody)
|
|
|
|
assert.deepStrictEqual(ctx.req.body, assertBody)
|
|
|
|
})
|
|
|
|
})
|