Skip to content

Commit d2afd7a

Browse files
authored
Support null value in makeDataSnapshot and update dependencies (#53)
1 parent c720e2f commit d2afd7a

File tree

6 files changed

+67
-9
lines changed

6 files changed

+67
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The `firebase-functions-test` is unit testing library for Cloud Functions for Firebase. It is a companion to [firebase-functions](https://github.com/Firebase/firebase-functions).
44

5-
_NOTE: This library can only be used with `firebase-functions` v1.0.0 or above._
5+
_NOTE: This library can only be used with `firebase-functions` v2.0.0 or above._
66

77
## Learn more
88

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@
3737
"@types/chai": "~4.2.4",
3838
"@types/mocha": "^5.2.7",
3939
"chai": "^4.2.0",
40-
"firebase-admin": "~8.6.1",
40+
"firebase-admin": "~8.9.0",
4141
"firebase-functions": "^3.3.0",
4242
"mocha": "^6.2.2",
4343
"sinon": "^7.5.0",
4444
"tslint": "^5.20.0",
4545
"typescript": "^3.6.4"
4646
},
4747
"peerDependencies": {
48-
"firebase-functions": ">1.0.1",
49-
"firebase-admin": ">5.12.0"
48+
"firebase-functions": ">=2.0.0",
49+
"firebase-admin": ">=6.0.0"
5050
},
5151
"engines": {
5252
"node": ">=6.0.0"

spec/index.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { expect } from 'chai';
2525

2626
describe('index', () => {
2727
/* tslint:disable-next-line:no-var-requires */
28-
const indexExport = require('../src')({ projectId: 'fakeProject' }, 'fakeServiceAccount');
28+
const indexExport = require('../src')({projectId: 'fakeProject'}, 'fakeServiceAccount');
2929
after(() => {
3030
// Call cleanup (handles case of cleanup function not existing)
3131
indexExport.cleanup && indexExport.cleanup();
@@ -48,7 +48,7 @@ describe('index', () => {
4848
});
4949

5050
it('should set env variables based parameters SDK was initialized with', () => {
51-
expect(process.env.FIREBASE_CONFIG).to.equal(JSON.stringify({ projectId: 'fakeProject' }));
51+
expect(process.env.FIREBASE_CONFIG).to.equal(JSON.stringify({projectId: 'fakeProject'}));
5252
expect(process.env.GOOGLE_APPLICATION_CREDENTIALS).to.equal('fakeServiceAccount');
5353
});
5454

@@ -63,10 +63,10 @@ import './lifecycle.spec';
6363
import './main.spec';
6464
import './app.spec';
6565
import './providers/https.spec';
66+
import './providers/firestore.spec';
67+
import './providers/database.spec';
6668
// import './providers/analytics.spec';
6769
// import './providers/auth.spec';
68-
// import './providers/database.spec';
69-
// import './providers/firestore.spec';
7070
// import './providers/https.spec';
7171
// import './providers/pubsub.spec';
7272
// import './providers/storage.spec';

spec/providers/database.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect } from 'chai';
2+
import { FirebaseFunctionsTest } from '../../src/lifecycle';
3+
import { makeDataSnapshot } from '../../src/providers/database';
4+
5+
describe('providers/database', () => {
6+
let test;
7+
8+
before(() => {
9+
test = new FirebaseFunctionsTest();
10+
test.init();
11+
});
12+
13+
after(() => {
14+
test.cleanup();
15+
});
16+
17+
it('produces the right snapshot with makeDataSnapshot', async () => {
18+
const snapshot = makeDataSnapshot({
19+
foo: 'bar',
20+
}, 'path');
21+
22+
expect(snapshot.val()).to.deep.equal({foo: 'bar'});
23+
expect(snapshot.ref.key).to.equal('path');
24+
});
25+
26+
it('should allow null value in makeDataSnapshot', async () => {
27+
const snapshot = makeDataSnapshot(null, 'path');
28+
29+
expect(snapshot.val()).to.deep.equal(null);
30+
expect(snapshot.ref.key).to.equal('path');
31+
});
32+
});

spec/providers/firestore.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect } from 'chai';
2+
import fft = require('../../src/index');
3+
4+
describe('providers/firestore', () => {
5+
it('produces the right snapshot with makeDocumentSnapshot', async () => {
6+
const test = fft();
7+
8+
const snapshot = test.firestore.makeDocumentSnapshot({
9+
email_address: '[email protected]',
10+
}, 'collection/doc-id');
11+
12+
expect(snapshot.data()).to.deep.equal({
13+
email_address: '[email protected]',
14+
});
15+
expect(snapshot.id).to.equal('doc-id');
16+
});
17+
18+
it('should allow empty document in makeDocumentSnapshot', async () => {
19+
const test = fft();
20+
21+
const snapshot = test.firestore.makeDocumentSnapshot({}, 'collection/doc-id');
22+
23+
expect(snapshot.data()).to.deep.equal(undefined);
24+
expect(snapshot.id).to.equal('doc-id');
25+
});
26+
});

src/providers/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { testApp } from '../app';
2828
/** Create a DataSnapshot. */
2929
export function makeDataSnapshot(
3030
/** Value of data for the snapshot. */
31-
val: string | number | boolean | any[] | object,
31+
val: string | number | boolean | any[] | object | null,
3232
/** Full path of the reference (e.g. 'users/alovelace'). */
3333
refPath: string,
3434
/** The Firebase app that the database belongs to.

0 commit comments

Comments
 (0)