|
1 | 1 | import { expect } from 'chai';
|
2 | 2 | import * as firebase from 'firebase-admin';
|
| 3 | +import * as sinon from 'sinon'; |
| 4 | +import * as http from 'http'; |
3 | 5 | import { FeaturesList } from '../../src/features';
|
4 | 6 | import fft = require('../../src/index');
|
5 | 7 |
|
6 | 8 | describe('providers/firestore', () => {
|
7 | 9 | let test: FeaturesList;
|
| 10 | + let fakeHttpRequestMethod; |
| 11 | + let fakeHttpResponse; |
8 | 12 |
|
9 | 13 | beforeEach(() => {
|
10 | 14 | test = fft();
|
| 15 | + fakeHttpResponse = { |
| 16 | + statusCode: 200, |
| 17 | + on: ((event, cb) => cb()) |
| 18 | + }; |
| 19 | + fakeHttpRequestMethod = sinon.fake((config, cb) => { |
| 20 | + cb(fakeHttpResponse); |
| 21 | + }); |
| 22 | + sinon.replace(http, 'request', fakeHttpRequestMethod); |
| 23 | + }); |
| 24 | + |
| 25 | + afterEach(() => { |
| 26 | + sinon.restore(); |
11 | 27 | });
|
12 | 28 |
|
13 | 29 | it('produces the right snapshot with makeDocumentSnapshot', async () => {
|
@@ -71,4 +87,30 @@ describe('providers/firestore', () => {
|
71 | 87 | );
|
72 | 88 | expect(snapshot.data().ref.toString()).to.equal(ref.toString());
|
73 | 89 | });
|
| 90 | + |
| 91 | + it('should use host name from FIRESTORE_EMULATOR_HOST env in clearFirestoreData', async () => { |
| 92 | + process.env.FIRESTORE_EMULATOR_HOST = 'not-local-host:8080'; |
| 93 | + |
| 94 | + await test.firestore.clearFirestoreData({projectId: 'not-a-project'}); |
| 95 | + |
| 96 | + expect(fakeHttpRequestMethod.calledOnceWith({ |
| 97 | + hostname: 'not-local-host', |
| 98 | + method: 'DELETE', |
| 99 | + path: '/emulator/v1/projects/not-a-project/databases/(default)/documents', |
| 100 | + port: '8080' |
| 101 | + })).to.be.true; |
| 102 | + }); |
| 103 | + |
| 104 | + it('should use host name from FIREBASE_FIRESTORE_EMULATOR_ADDRESS env in clearFirestoreData', async () => { |
| 105 | + process.env.FIREBASE_FIRESTORE_EMULATOR_ADDRESS = 'custom-host:9090'; |
| 106 | + |
| 107 | + await test.firestore.clearFirestoreData({projectId: 'not-a-project'}); |
| 108 | + |
| 109 | + expect(fakeHttpRequestMethod.calledOnceWith({ |
| 110 | + hostname: 'custom-host', |
| 111 | + method: 'DELETE', |
| 112 | + path: '/emulator/v1/projects/not-a-project/databases/(default)/documents', |
| 113 | + port: '9090' |
| 114 | + })).to.be.true; |
| 115 | + }); |
74 | 116 | });
|
0 commit comments