diff --git a/functions/firebase/index.js b/functions/firebase/index.js index 96adf500fa..cc6280b707 100644 --- a/functions/firebase/index.js +++ b/functions/firebase/index.js @@ -18,18 +18,14 @@ * Triggered by a change to a Firebase RTDB reference. * * @param {!Object} event The Cloud Functions event. - * @param {!Function} The callback function. */ -exports.helloRTDB = (event, callback) => { +exports.helloRTDB = (event) => { const triggerResource = event.resource; console.log(`Function triggered by change to: ${triggerResource}`); console.log(`Admin?: ${!!event.auth.admin}`); console.log(`Delta:`); console.log(JSON.stringify(event.delta, null, 2)); - - // Don't forget to call the callback. - callback(); }; // [END functions_firebase_rtdb] @@ -38,9 +34,8 @@ exports.helloRTDB = (event, callback) => { * Triggered by a change to a Firestore document. * * @param {!Object} event The Cloud Functions event. - * @param {!Function} The callback function. */ -exports.helloFirestore = (event, callback) => { +exports.helloFirestore = (event) => { const triggerResource = event.resource; console.log(`Function triggered by event on: ${triggerResource}`); @@ -55,9 +50,6 @@ exports.helloFirestore = (event, callback) => { console.log(`\nNew value:`); console.log(JSON.stringify(event.data.value, null, 2)); } - - // Don't forget to call the callback. - callback(); }; // [END functions_firebase_firestore] @@ -66,9 +58,8 @@ exports.helloFirestore = (event, callback) => { * Triggered by a change to a Firebase Auth user object. * * @param {!Object} event The Cloud Functions event. - * @param {!Function} The callback function. */ -exports.helloAuth = (event, callback) => { +exports.helloAuth = (event) => { try { const data = event.data; console.log(`Function triggered by change to user: ${data.uid}`); @@ -80,8 +71,6 @@ exports.helloAuth = (event, callback) => { } catch (err) { console.error(err); } - // Don't forget to call the callback. - callback(); }; // [END functions_firebase_auth] @@ -93,7 +82,7 @@ const firestore = new Firestore({ }); // Converts strings added to /messages/{pushId}/original to uppercase -exports.makeUpperCase = (event, callback) => { +exports.makeUpperCase = (event) => { const resource = event.resource; const affectedDoc = firestore.doc(resource.split('/documents/')[1]); diff --git a/functions/firebase/test/index.test.js b/functions/firebase/test/index.test.js index c085331eb3..effa7be1ac 100644 --- a/functions/firebase/test/index.test.js +++ b/functions/firebase/test/index.test.js @@ -52,14 +52,12 @@ test(`should listen to RTDB`, t => { }, delta: delta }; - const cb = sinon.stub(); - sample.program.helloRTDB(event, cb); + sample.program.helloRTDB(event); t.true(console.log.calledWith(`Function triggered by change to: resource`)); t.true(console.log.calledWith(`Admin?: true`)); t.true(console.log.calledWith(JSON.stringify(delta, null, 2))); - t.true(cb.calledOnce); }); test(`should listen to Firestore`, t => { @@ -79,15 +77,13 @@ test(`should listen to Firestore`, t => { value: value } }; - const cb = sinon.stub(); - sample.program.helloFirestore(event, cb); + sample.program.helloFirestore(event); t.true(console.log.calledWith(`Function triggered by event on: resource`)); t.true(console.log.calledWith(`Event type: type`)); t.true(console.log.calledWith(JSON.stringify(oldValue, null, 2))); t.true(console.log.calledWith(JSON.stringify(value, null, 2))); - t.true(cb.calledOnce); }); test(`should listen to Auth events`, t => { @@ -103,14 +99,12 @@ test(`should listen to Auth events`, t => { } } }; - const cb = sinon.stub(); - sample.program.helloAuth(event, cb); + sample.program.helloAuth(event); t.true(console.log.calledWith(`Function triggered by change to user: me`)); t.true(console.log.calledWith(`Created at: ${date}`)); t.true(console.log.calledWith(`Email: me@example.com`)); - t.true(cb.calledOnce); }); test(`should update data in response to Firestore events`, t => { @@ -133,9 +127,8 @@ test(`should update data in response to Firestore events`, t => { } } }; - const cb = sinon.stub(); - sample.program.makeUpperCase(event, cb); + sample.program.makeUpperCase(event); t.true(sample.mocks.firestore.doc.calledWith('some/path')); t.true(console.log.calledWith(`Replacing value: foobar --> FOOBAR`));