Skip to content

Commit

Permalink
fix(firestore): do not return idField on valueChanges if document doe…
Browse files Browse the repository at this point in the history
…s not exists
  • Loading branch information
KingDarBoja committed Mar 14, 2021
1 parent a26676c commit 9b1873e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
21 changes: 4 additions & 17 deletions src/firestore/document/document.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('AngularFirestoreDocument', () => {

it('should get unwrapped snapshot', async (done: any) => {
const randomCollectionName = afs.firestore.collection('a').doc().id;
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`) as firebase.firestore.DocumentReference<Stock>;
const stock = new AngularFirestoreDocument(ref, afs);
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`) as DocumentReference<Stock>;
const stock = new AngularFirestoreDocument<Stock>(ref, afs);
await stock.set(FAKE_STOCK_DATA);
const obs$ = stock.valueChanges();
obs$.pipe(take(1)).subscribe(async data => {
Expand All @@ -46,10 +46,9 @@ describe('AngularFirestoreDocument', () => {
});
});

/* TODO(jamesdaniels): test is flaking, look into this
it('should optionally map the doc ID to the emitted data object', async (done: any) => {
const randomCollectionName = afs.firestore.collection('a').doc().id;
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`);
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`) as DocumentReference<Stock>;
const stock = new AngularFirestoreDocument<Stock>(ref, afs);
await stock.set(FAKE_STOCK_DATA);
const idField = 'myCustomID';
Expand All @@ -59,7 +58,7 @@ describe('AngularFirestoreDocument', () => {
expect(data).toEqual(jasmine.objectContaining(FAKE_STOCK_DATA));
stock.delete().then(done).catch(done.fail);
});
});*/
});

});

Expand All @@ -81,18 +80,6 @@ describe('AngularFirestoreDocument', () => {
});
});

it('should get unwrapped snapshot', async (done: any) => {
const randomCollectionName = afs.firestore.collection('a').doc().id;
const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`) as DocumentReference<Stock>;
const stock = new AngularFirestoreDocument<Stock>(ref, afs);
await stock.set(FAKE_STOCK_DATA);
const obs$ = stock.valueChanges();
obs$.pipe(take(1)).subscribe(async data => {
expect(data).toEqual(FAKE_STOCK_DATA);
stock.delete().then(done).catch(done.fail);
});
});

});

});
2 changes: 1 addition & 1 deletion src/firestore/document/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class AngularFirestoreDocument<T = DocumentData> {
valueChanges<K extends string>(options: { idField?: K } = {}): Observable<T | undefined> {
return this.snapshotChanges().pipe(
map(({ payload }) =>
options.idField ? {
options.idField && payload.exists ? {
...payload.data(),
...{ [options.idField]: payload.id }
} as T & { [T in K]: string } : payload.data()
Expand Down

0 comments on commit 9b1873e

Please sign in to comment.