functions-samples: Updating to latest Firebase SDK to causes tests to fail in quickstart/uppercase

Steps to reproduce

  1. Upgrade libraries to the latest Firebase SDK in /quickstarts/uppercase/functions/package.json
...
  "dependencies": {
    "firebase-admin": "5.4.3",
    "firebase-functions": "0.7.1"
  },
...
  1. Run npm install
  2. Run npm run test

Expected behavior

Tests should pass

Actual behavior

The tests fail with the following error message. As far as I can tell, this was introduced by the 5.5.0 version of firebase-admin. The tests do not fail on version 5.4.3.

The devDependency libraries are also really out-of-date, but updating them to the latest chai, mocha and sinon does not fix the problem.

> mocha --reporter spec

  Cloud Functions
    makeUpperCase
Uppercasing undefined null
      1) should upper case input and write it to /uppercase
    addMessage
      2) should return a 303 redirect


  0 passing (312ms)
  2 failing

  1) Cloud Functions makeUpperCase should upper case input and write it to /uppercase:
     TypeError: Cannot read property 'toUpperCase' of null
      at exports.makeUppercase.functions.database.ref.onWrite.event (index.js:57:33)
      at Object.<anonymous> (node_modules/firebase-functions/lib/cloud-functions.js:59:27)
      at Generator.next (<anonymous>)
      at node_modules/firebase-functions/lib/cloud-functions.js:28:71
      at __awaiter (node_modules/firebase-functions/lib/cloud-functions.js:24:12)
      at Object.cloudFunction [as makeUppercase] (node_modules/firebase-functions/lib/cloud-functions.js:53:36)
      at Context.it (test/test.js:112:50)

  2) Cloud Functions addMessage should return a 303 redirect:
     TypeError: Attempted to wrap undefined property database as function
      at checkWrappedMethod (node_modules/sinon/lib/sinon/util/core.js:78:29)
      at Object.wrapMethod (node_modules/sinon/lib/sinon/util/core.js:129:21)
      at Object.stub (node_modules/sinon/lib/sinon/stub.js:67:26)
      at Context.it (test/test.js:130:28)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

Ok I was able to get it to work.

First you need the latest version of sinon:

npm install --save sinon@latest

Then change the way we stub admin.database because it is a getter and not a property:

Change test.js L.131 from:

databaseStub.returns( { ref: refStub });

to:

databaseStub.get(() => (() => ({ ref: refStub })));

I’ll try to get the docs updated tomorrow.

I had the same problem. In the makeUpperCase test. The DeltaSnapshot interface has changed with the new update. It now requires an extra parameter ‘instance’. To make the test pass change line 84 from data: new functions.database.DeltaSnapshot(null, null, null, 'input'), to data: new functions.database.DeltaSnapshot(null, null, null, null, 'input'),

I have not looked into why addMessage fails.