test: Add test for buffer support
continuous-integration/appveyor/branch AppVeyor build succeeded Details

master
Jonatan Nilsson 2023-05-11 11:12:23 +00:00
parent 7401b3bd2c
commit 6d4d62e79c
1 changed files with 32 additions and 0 deletions

View File

@ -91,6 +91,38 @@ t.describe('#requestEnd()', function() {
flaska.requestEnd(null, ctx)
})
t.test('call res and end correctly when dealing with buffers', function(cb) {
const assertStatus = 202
// Calculated manually just in case
const assertBodyLength = 11
const assertBody = Buffer.from('hello world')
let onFinish = cb.finish(function(body) {
assert.strictEqual(ctx.status, assertStatus)
assert.strictEqual(ctx.body, assertBody)
assert.strictEqual(ctx.headers['Content-Type'], 'application/octet-stream')
assert.strictEqual(ctx.headers['Content-Length'], assertBodyLength)
if (method === 'GET') {
assert.ok(body)
assert.strictEqual(body, assertBody)
} else {
assert.notOk(body)
}
assert.ok(ctx.res.writeHead.called)
assert.strictEqual(ctx.res.writeHead.firstCall[0], ctx.status)
assert.strictEqual(ctx.res.writeHead.firstCall[1], ctx.headers)
})
const ctx = createCtx({
method: method,
status: assertStatus,
}, onFinish)
ctx.body = assertBody
let flaska = new Flaska({}, fakerHttp, fakeStream)
flaska.requestEnd(null, ctx)
})
t.test('call res and end correctly when dealing with null and no status override', function(cb) {
// Calculated manually just in case
const assertBodyLength = 0