Skip to content

Instantly share code, notes, and snippets.

@websoftwares
Created October 26, 2017 08:50
Show Gist options
  • Save websoftwares/068590cb104aa7271e74a34ba7b22bcb to your computer and use it in GitHub Desktop.
Save websoftwares/068590cb104aa7271e74a34ba7b22bcb to your computer and use it in GitHub Desktop.
webtask-full-http-control-test
module.exports = function (context, req, res) {
res.writeHead(200, { 'Content-Type': 'text/html ' })
res.end('<h1>Hello, world!</h1>')
}
'use strict'
const tape = require('tape')
const fullHttpControl = require('./full-http-control')
const contextMock = {}
const reqMock = {}
const responseMock = (t, expected) => {
return {
writeHead: (statusCode, contentType) => {
t.equal(
expected.statusCode,
statusCode,
`Assert expected: ${expected.statusCode} matches actual: ${statusCode}`
)
t.deepEquals(
expected.contentType,
contentType,
`Assert expected: ${JSON.stringify(expected.contentType)} matches actual: ${JSON.stringify(contentType)}`
)
},
end: (response) => {
t.equal(
expected.response,
response,
`Assert expected: ${expected.response} matches actual: ${response}`
)
}
}
}
tape('Full http control test cases', (t) => {
const expected = {
statusCode: 200,
contentType: { 'Content-Type': 'text/html ' },
response: '<h1>Hello, world!</h1>'
}
fullHttpControl(contextMock, reqMock, responseMock(t, expected))
t.end()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment