|
1 | 1 | import { AngularFireModule, FirebaseApp } from '@angular/fire';
|
2 | 2 | import { AngularFirestore, SETTINGS } from '../firestore';
|
3 | 3 | import { AngularFirestoreModule } from '../firestore.module';
|
| 4 | +import { Subscription } from 'rxjs'; |
4 | 5 | import { AngularFirestoreDocument } from './document';
|
5 | 6 | import { take } from 'rxjs/operators';
|
6 | 7 |
|
@@ -33,32 +34,67 @@ describe('AngularFirestoreDocument', () => {
|
33 | 34 | app.delete();
|
34 | 35 | });
|
35 | 36 |
|
36 |
| - it('should get action updates', async (done: any) => { |
37 |
| - const randomCollectionName = randomName(afs.firestore); |
38 |
| - const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`); |
39 |
| - const stock = new AngularFirestoreDocument<Stock>(ref, afs); |
40 |
| - await stock.set(FAKE_STOCK_DATA); |
41 |
| - const sub = stock |
42 |
| - .snapshotChanges() |
43 |
| - .subscribe(async a => { |
44 |
| - sub.unsubscribe(); |
45 |
| - if (a.payload.exists) { |
46 |
| - expect(a.payload.data()).toEqual(FAKE_STOCK_DATA); |
47 |
| - stock.delete().then(done).catch(done.fail); |
48 |
| - } |
| 37 | + describe('valueChanges()', () => { |
| 38 | + |
| 39 | + it('should get unwrapped snapshot', async (done: any) => { |
| 40 | + const randomCollectionName = afs.firestore.collection('a').doc().id; |
| 41 | + const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`); |
| 42 | + const stock = new AngularFirestoreDocument<Stock>(ref, afs); |
| 43 | + await stock.set(FAKE_STOCK_DATA); |
| 44 | + const obs$ = stock.valueChanges(); |
| 45 | + obs$.pipe(take(1)).subscribe(async data => { |
| 46 | + expect(data).toEqual(FAKE_STOCK_DATA); |
| 47 | + stock.delete().then(done).catch(done.fail); |
49 | 48 | });
|
| 49 | + }); |
| 50 | + |
| 51 | + /* TODO(jamesdaniels): test is flaking, look into this |
| 52 | + it('should optionally map the doc ID to the emitted data object', async (done: any) => { |
| 53 | + const randomCollectionName = afs.firestore.collection('a').doc().id; |
| 54 | + const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`); |
| 55 | + const stock = new AngularFirestoreDocument<Stock>(ref, afs); |
| 56 | + await stock.set(FAKE_STOCK_DATA); |
| 57 | + const idField = 'myCustomID'; |
| 58 | + const obs$ = stock.valueChanges({ idField }); |
| 59 | + obs$.pipe(take(1)).subscribe(async data => { |
| 60 | + expect(data[idField]).toBeDefined(); |
| 61 | + expect(data).toEqual(jasmine.objectContaining(FAKE_STOCK_DATA)); |
| 62 | + stock.delete().then(done).catch(done.fail); |
| 63 | + }); |
| 64 | + });*/ |
| 65 | + |
50 | 66 | });
|
51 | 67 |
|
52 |
| - it('should get unwrapped snapshot', async (done: any) => { |
53 |
| - const randomCollectionName = afs.firestore.collection('a').doc().id; |
54 |
| - const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`); |
55 |
| - const stock = new AngularFirestoreDocument<Stock>(ref, afs); |
56 |
| - await stock.set(FAKE_STOCK_DATA); |
57 |
| - const obs$ = stock.valueChanges(); |
58 |
| - obs$.pipe(take(1)).subscribe(async data => { |
59 |
| - expect(data).toEqual(FAKE_STOCK_DATA); |
60 |
| - stock.delete().then(done).catch(done.fail); |
| 68 | + describe('snapshotChanges()', () => { |
| 69 | + |
| 70 | + it('should get action updates', async (done: any) => { |
| 71 | + const randomCollectionName = randomName(afs.firestore); |
| 72 | + const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`); |
| 73 | + const stock = new AngularFirestoreDocument<Stock>(ref, afs); |
| 74 | + await stock.set(FAKE_STOCK_DATA); |
| 75 | + const sub = stock |
| 76 | + .snapshotChanges() |
| 77 | + .subscribe(async a => { |
| 78 | + sub.unsubscribe(); |
| 79 | + if (a.payload.exists) { |
| 80 | + expect(a.payload.data()).toEqual(FAKE_STOCK_DATA); |
| 81 | + stock.delete().then(done).catch(done.fail); |
| 82 | + } |
| 83 | + }); |
61 | 84 | });
|
| 85 | + |
| 86 | + it('should get unwrapped snapshot', async (done: any) => { |
| 87 | + const randomCollectionName = afs.firestore.collection('a').doc().id; |
| 88 | + const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`); |
| 89 | + const stock = new AngularFirestoreDocument<Stock>(ref, afs); |
| 90 | + await stock.set(FAKE_STOCK_DATA); |
| 91 | + const obs$ = stock.valueChanges(); |
| 92 | + obs$.pipe(take(1)).subscribe(async data => { |
| 93 | + expect(data).toEqual(FAKE_STOCK_DATA); |
| 94 | + stock.delete().then(done).catch(done.fail); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
62 | 98 | });
|
63 | 99 |
|
64 | 100 | });
|
0 commit comments