|
1 | 1 | import { expect } from 'chai'; |
| 2 | +import * as firebase from 'firebase-admin'; |
2 | 3 | import fft = require('../../src/index'); |
3 | 4 |
|
4 | 5 | describe('providers/firestore', () => { |
@@ -29,4 +30,47 @@ describe('providers/firestore', () => { |
29 | 30 | expect(snapshot.data()).to.deep.equal(undefined); |
30 | 31 | expect(snapshot.id).to.equal('doc-id'); |
31 | 32 | }); |
| 33 | + |
| 34 | + it('should allow geopoints with makeDocumentSnapshot', () => { |
| 35 | + const test = fft(); |
| 36 | + |
| 37 | + const hq = new firebase.firestore.GeoPoint(47.6703, 122.1971); |
| 38 | + const snapshot = test.firestore.makeDocumentSnapshot( |
| 39 | + { geopoint: hq }, |
| 40 | + 'collection/doc-id' |
| 41 | + ); |
| 42 | + |
| 43 | + expect(snapshot.data()).to.deep.equal({ geopoint: hq }); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should allow timestmaps with makeDocumentSnapshot', () => { |
| 47 | + const test = fft(); |
| 48 | + |
| 49 | + const time = new Date(); |
| 50 | + const snapshot = test.firestore.makeDocumentSnapshot( |
| 51 | + { time }, |
| 52 | + 'collection/doc-id' |
| 53 | + ); |
| 54 | + |
| 55 | + expect(snapshot.data().time).to.be.instanceof(firebase.firestore.Timestamp); |
| 56 | + expect(snapshot.data().time.toDate()).to.deep.equal(time); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should allow references with makeDocumentSnapshot', () => { |
| 60 | + const test = fft(); |
| 61 | + firebase.initializeApp({ |
| 62 | + projectId: 'not-a-project', |
| 63 | + }); |
| 64 | + |
| 65 | + const ref = firebase.firestore().doc('collection/doc-id'); |
| 66 | + const snapshot = test.firestore.makeDocumentSnapshot( |
| 67 | + { ref }, |
| 68 | + 'collection/doc-id' |
| 69 | + ); |
| 70 | + |
| 71 | + expect(snapshot.data().ref).to.be.instanceOf( |
| 72 | + firebase.firestore.DocumentReference |
| 73 | + ); |
| 74 | + expect(snapshot.data().ref.toString()).to.equal(ref.toString()); |
| 75 | + }); |
32 | 76 | }); |
0 commit comments