Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions functions/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,6 @@

'use strict';

// [START functions_http_helloworld]
/**
* Responds to any HTTP request that can provide a "message" field in the body.
*
* @param {Object} req ExpressJS object containing the received HTTP request.
* @param {Object} res ExpressJS object containing the HTTP response to send.
*/
exports.helloWorld = (req, res) => {
if (req.body.message === undefined) {
// This is an error case, as "message" is required
res.status(400).send('No message defined!');
} else {
// Everything is ok - call request-terminating method to signal function
// completion. (Otherwise, the function may continue to run until timeout.)
console.log(req.body.message);
res.status(200).end();
}
};
// [END functions_http_helloworld]

// [START functions_http_content]
/**
* Responds to an HTTP request using data from the request body parsed according
Expand Down
26 changes: 0 additions & 26 deletions functions/http/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,6 @@ function getMocks () {
test.beforeEach(tools.stubConsole);
test.afterEach.always(tools.restoreConsole);

test.serial(`http:helloworld: should error with no message`, (t) => {
const mocks = getMocks();
const httpSample = getSample();
mocks.req.body = {};
httpSample.sample.helloWorld(mocks.req, mocks.res);

t.true(mocks.res.status.calledOnce);
t.is(mocks.res.status.firstCall.args[0], 400);
t.true(mocks.res.send.calledOnce);
t.is(mocks.res.send.firstCall.args[0], `No message defined!`);
});

test.serial(`http:helloworld: should log message`, (t) => {
const mocks = getMocks();
const httpSample = getSample();
mocks.req.body = {
message: `hi`
};
httpSample.sample.helloWorld(mocks.req, mocks.res);

t.true(mocks.res.status.calledOnce);
t.is(mocks.res.status.firstCall.args[0], 200);
t.true(mocks.res.end.calledOnce);
t.true(console.log.calledWith(`hi`));
});

test.serial(`http:helloHttp: should handle GET`, (t) => {
const mocks = getMocks();
const httpSample = getSample();
Expand Down