Skip to content

Commit 899a066

Browse files
committed
chore(comments): Comment API
1 parent 164a723 commit 899a066

File tree

2 files changed

+423
-22
lines changed

2 files changed

+423
-22
lines changed

src/firestore/firestore.spec.ts

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import { FirebaseApp, FirebaseAppConfig, AngularFireModule} from 'angularfire2';
2-
import { AngularFirestore, AngularFirestoreModule } from 'angularfire2/firestore';
2+
import { AngularFirestore, AngularFirestoreModule, AngularFirestoreDocument, AngularFirestoreCollection } from 'angularfire2/firestore';
33
import * as firebase from 'firebase/app';
4+
import * as firestore from 'firestore';
5+
import { Observable } from 'rxjs/Observable';
6+
import { Subscription } from 'rxjs/Subscription';
47

58
import { TestBed, inject } from '@angular/core/testing';
69
import { COMMON_CONFIG } from './test-config';
710

8-
fdescribe('AngularFirestore', () => {
11+
interface Stock {
12+
name: string;
13+
price: number;
14+
}
15+
16+
const FAKE_STOCK_DATA = { name: 'FAKE', price: 1 };
17+
18+
fdescribe('Firestore', () => {
919
let app: firebase.app.App;
1020
let afs: AngularFirestore;
11-
21+
let stock: AngularFirestoreDocument<Stock>;
22+
let sub: Subscription;
23+
1224
beforeEach(() => {
1325
TestBed.configureTestingModule({
1426
imports: [
@@ -19,22 +31,67 @@ fdescribe('AngularFirestore', () => {
1931
inject([FirebaseApp, AngularFirestore], (_app: firebase.app.App, _afs: AngularFirestore) => {
2032
app = _app;
2133
afs = _afs;
34+
stock = afs.doc('stocks/FAKE');
2235
})();
2336
});
2437

25-
afterEach(done => {
26-
app.delete().then(done, done.fail);
27-
// ref.off();
28-
// ref.remove(done);
38+
afterEach(async (done) => {
39+
await app.delete();
40+
//await stock.delete();
41+
if(sub) {
42+
sub.unsubscribe();
43+
}
44+
done();
2945
});
3046

3147
describe('AngularFirestore', () => {
3248

33-
// document
49+
it('should be the properly initialized type', () => {
50+
expect(afs instanceof AngularFirestore).toBe(true);
51+
});
52+
3453
it('should have an initialized Firebase app', () => {
3554
expect(afs.app).toBeDefined();
3655
});
3756

57+
describe('AngularFirestore#document', () => {
58+
59+
it('should throw on an invalid path', () => {
60+
const singleWrapper = () => afs.doc('collection');
61+
const tripleWrapper = () => afs.doc('collection/doc/subcollection');
62+
expect(singleWrapper).toThrowError();
63+
expect(tripleWrapper).toThrowError();
64+
});
65+
66+
it('should get data as an Observable', async(done: any) => {
67+
//await stock.set(FAKE_STOCK_DATA);
68+
const obs$ = Observable.from(stock);
69+
obs$.catch(e => { console.log(e); return e; })
70+
.take(1) // this will unsubscribe after the first
71+
.subscribe(async (data: Stock) => {
72+
debugger;
73+
expect(JSON.stringify(data)).toBe(JSON.stringify(FAKE_STOCK_DATA));
74+
stock.delete().then(done).catch(done.fail);
75+
});
76+
});
77+
78+
it('should get realtime updates', async(done: Function) => {
79+
// pick a new stock
80+
//await stock.set(FAKE_STOCK_DATA);
81+
sub = stock
82+
.valueChanges()
83+
.subscribe(async a => {
84+
debugger;
85+
if(a.exists) {
86+
expect(a.data()).toEqual(FAKE_STOCK_DATA);
87+
await stock.delete();
88+
done();
89+
}
90+
});
91+
});
92+
93+
});
94+
3895
});
3996

4097
});

0 commit comments

Comments
 (0)