Skip to content

Support null value in makeDataSnapshot and update dependencies #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 3, 2020
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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).

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

## Learn more

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
"@types/chai": "~4.2.4",
"@types/mocha": "^5.2.7",
"chai": "^4.2.0",
"firebase-admin": "~8.6.1",
"firebase-admin": "~8.9.0",
"firebase-functions": "^3.3.0",
"mocha": "^6.2.2",
"sinon": "^7.5.0",
"tslint": "^5.20.0",
"typescript": "^3.6.4"
},
"peerDependencies": {
"firebase-functions": ">1.0.1",
"firebase-admin": ">5.12.0"
"firebase-functions": ">=2.0.0",
"firebase-admin": ">=6.0.0"
},
"engines": {
"node": ">=6.0.0"
Expand Down
8 changes: 4 additions & 4 deletions spec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { expect } from 'chai';

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

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

Expand All @@ -63,10 +63,10 @@ import './lifecycle.spec';
import './main.spec';
import './app.spec';
import './providers/https.spec';
import './providers/firestore.spec';
import './providers/database.spec';
// import './providers/analytics.spec';
// import './providers/auth.spec';
// import './providers/database.spec';
// import './providers/firestore.spec';
// import './providers/https.spec';
// import './providers/pubsub.spec';
// import './providers/storage.spec';
Expand Down
32 changes: 32 additions & 0 deletions spec/providers/database.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect } from 'chai';
import { FirebaseFunctionsTest } from '../../src/lifecycle';
import { makeDataSnapshot } from '../../src/providers/database';

describe('providers/database', () => {
let test;

before(() => {
test = new FirebaseFunctionsTest();
test.init();
});

after(() => {
test.cleanup();
});

it('produces the right snapshot with makeDataSnapshot', async () => {
const snapshot = makeDataSnapshot({
foo: 'bar',
}, 'path');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - add a newline after this to separate the act and assert steps of this test.


expect(snapshot.val()).to.deep.equal({foo: 'bar'});
expect(snapshot.ref.key).to.equal('path');
});

it('should allow null value in makeDataSnapshot', async () => {
const snapshot = makeDataSnapshot(null, 'path');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - add a newline after this line to separate the act and assert steps of this test.


expect(snapshot.val()).to.deep.equal(null);
expect(snapshot.ref.key).to.equal('path');
});
});
26 changes: 26 additions & 0 deletions spec/providers/firestore.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect } from 'chai';
import fft = require('../../src/index');

describe('providers/firestore', () => {
it('produces the right snapshot with makeDocumentSnapshot', async () => {
const test = fft();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - add a newline after this line and after you call makeDocumentSnapshot, to split up the arrange ,act, and assert steps of this test


const snapshot = test.firestore.makeDocumentSnapshot({
email_address: '[email protected]',
}, 'collection/doc-id');

expect(snapshot.data()).to.deep.equal({
email_address: '[email protected]',
});
expect(snapshot.id).to.equal('doc-id');
});

it('should allow empty document in makeDocumentSnapshot', async () => {
const test = fft();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - add a newline after this line and after you call makeDocumentSnapshot, to split up the arrange ,act, and assert steps of this test


const snapshot = test.firestore.makeDocumentSnapshot({}, 'collection/doc-id');

expect(snapshot.data()).to.deep.equal(undefined);
expect(snapshot.id).to.equal('doc-id');
});
});
2 changes: 1 addition & 1 deletion src/providers/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { testApp } from '../app';
/** Create a DataSnapshot. */
export function makeDataSnapshot(
/** Value of data for the snapshot. */
val: string | number | boolean | any[] | object,
val: string | number | boolean | any[] | object | null,
/** Full path of the reference (e.g. 'users/alovelace'). */
refPath: string,
/** The Firebase app that the database belongs to.
Expand Down