Skip to content

Commit d59d49f

Browse files
committed
added tests for clearFirestoreData
1 parent d3ea67b commit d59d49f

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"pretest": "node_modules/.bin/tsc",
1212
"test": "mocha .tmp/spec/index.spec.js",
1313
"posttest": "npm run lint && rm -rf .tmp",
14+
"preintegrationTest": "node_modules/.bin/tsc",
15+
"integrationTest": "firebase emulators:exec --project=not-a-project --only firestore 'mocha .tmp/spec/integration/**/*.spec.js'",
16+
"postintegrationTest": "rm -rf .tmp",
1417
"format": "prettier --check '**/*.{json,ts,yml,yaml}'",
1518
"format:fix": "prettier --write '**/*.{json,ts,yml,yaml}'"
1619
},
@@ -44,6 +47,7 @@
4447
"chai": "^4.2.0",
4548
"firebase-admin": "~8.9.0",
4649
"firebase-functions": "^3.3.0",
50+
"firebase-tools": "^8.9.2",
4751
"mocha": "^6.2.2",
4852
"prettier": "^1.19.1",
4953
"sinon": "^7.5.0",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { expect } from 'chai';
2+
import { firestore, initializeApp } from 'firebase-admin';
3+
import fft = require('../../../src/index');
4+
5+
before(() => {
6+
initializeApp();
7+
});
8+
9+
describe('providers/firestore', () => {
10+
it('clears database with clearFirestoreData', async () => {
11+
const test = fft({ projectId: 'not-a-project' });
12+
const db = firestore();
13+
14+
await Promise.all([
15+
db
16+
.collection('test')
17+
.doc('doc1')
18+
.set({}),
19+
db
20+
.collection('test')
21+
.doc('doc1')
22+
.collection('test')
23+
.doc('doc2')
24+
.set({}),
25+
]);
26+
27+
await test.firestore.clearFirestoreData({ projectId: 'not-a-project' });
28+
29+
const docs = await Promise.all([
30+
db
31+
.collection('test')
32+
.doc('doc1')
33+
.get(),
34+
db
35+
.collection('test')
36+
.doc('doc1')
37+
.collection('test')
38+
.doc('doc2')
39+
.get(),
40+
]);
41+
expect(docs[0].exists).to.be.false;
42+
expect(docs[1].exists).to.be.false;
43+
});
44+
});

0 commit comments

Comments
 (0)