Skip to content

Commit

Permalink
Add missing sample that got inlined into the docs. (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry authored Jun 23, 2016
1 parent a6c2db5 commit b02fcb6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
20 changes: 19 additions & 1 deletion functions/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ exports.helloWorld = function helloWorld (context, data) {
var request = require('request-promise');

/**
* Background Cloud Function that returns a Promise.
* Background Cloud Function that returns a Promise. Note that we don't pass
* a "context" argument to the function.
*
* @param {Object} data Request data, provided by a trigger.
* @returns {Promise}
Expand All @@ -48,3 +49,20 @@ exports.helloPromise = function helloPromise (data) {
});
};
// [END helloPromise]

// [START helloSynchronous]
/**
* Background Cloud Function that returns synchronously. Note that we don't pass
* a "context" argument to the function.
*
* @param {Object} data Request data, provided by a trigger.
*/
exports.helloSynchronous = function helloSynchronous (data) {
// This function returns synchronously
if (data.something === true) {
return 'Something is true!';
} else {
throw new Error('Something was not true!');
}
};
// [END helloSynchronous]
14 changes: 14 additions & 0 deletions test/functions/background.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ test.cb.serial('should make a promise request', function (t) {
t.fail();
});
});
test('should return synchronously', function (t) {
var backgroundSample = getSample();
t.is(backgroundSample.sample.helloSynchronous({
something: true
}), 'Something is true!');
});
test('should throw an error', function (t) {
var backgroundSample = getSample();
t.throws(function () {
backgroundSample.sample.helloSynchronous({
something: false
})
}, Error, 'Something was not true!');
});

test.after(function () {
console.error.restore();
Expand Down

0 comments on commit b02fcb6

Please sign in to comment.