Created
October 26, 2017 08:50
-
-
Save websoftwares/068590cb104aa7271e74a34ba7b22bcb to your computer and use it in GitHub Desktop.
webtask-full-http-control-test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (context, req, res) { | |
res.writeHead(200, { 'Content-Type': 'text/html ' }) | |
res.end('<h1>Hello, world!</h1>') | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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