Skip to content

Commit d76c4a7

Browse files
chore(lint): Clean up firestore tests
1 parent f35dcbc commit d76c4a7

File tree

5 files changed

+155
-146
lines changed

5 files changed

+155
-146
lines changed

src/firestore/collection-group/collection-group.spec.ts

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { AngularFireModule, FirebaseApp } from '@angular/fire';
22
import { AngularFirestore, AngularFirestoreCollectionGroup, AngularFirestoreModule, SETTINGS } from '../public_api';
33
import { Query, QueryGroupFn } from '../interfaces';
4-
import { BehaviorSubject, Subscription } from 'rxjs';
4+
import { BehaviorSubject } from 'rxjs';
55
import { skip, switchMap, take } from 'rxjs/operators';
6-
import { inject, TestBed } from '@angular/core/testing';
6+
import { TestBed } from '@angular/core/testing';
77
import { COMMON_CONFIG } from '../../test-config';
88
import 'firebase/firestore';
99

@@ -23,7 +23,6 @@ async function collectionHarness(afs: AngularFirestore, items: number, queryGrou
2323
describe('AngularFirestoreCollectionGroup', () => {
2424
let app: FirebaseApp;
2525
let afs: AngularFirestore;
26-
let sub: Subscription;
2726

2827
beforeEach(() => {
2928
TestBed.configureTestingModule({
@@ -35,10 +34,9 @@ describe('AngularFirestoreCollectionGroup', () => {
3534
{ provide: SETTINGS, useValue: { host: 'localhost:8080', ssl: false } }
3635
]
3736
});
38-
inject([FirebaseApp, AngularFirestore], (_app: FirebaseApp, _afs: AngularFirestore) => {
39-
app = _app;
40-
afs = _afs;
41-
})();
37+
38+
app = TestBed.inject(FirebaseApp);
39+
afs = TestBed.inject(AngularFirestore);
4240
});
4341

4442
afterEach(() => {
@@ -49,7 +47,7 @@ describe('AngularFirestoreCollectionGroup', () => {
4947

5048
it('should get unwrapped snapshot', async (done: any) => {
5149
const ITEMS = 4;
52-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
50+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
5351

5452
const sub = stocks.valueChanges().subscribe(data => {
5553
// unsub immediately as we will be deleting data at the bottom
@@ -73,9 +71,10 @@ describe('AngularFirestoreCollectionGroup', () => {
7371

7472
it('should handle multiple subscriptions (hot)', async (done: any) => {
7573
const ITEMS = 4;
76-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
74+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
7775
const changes = stocks.valueChanges();
78-
const sub = changes.subscribe(() => {}).add(
76+
const sub = changes.subscribe(() => {
77+
}).add(
7978
changes.pipe(take(1)).subscribe(data => {
8079
expect(data.length).toEqual(ITEMS);
8180
sub.unsubscribe();
@@ -87,10 +86,11 @@ describe('AngularFirestoreCollectionGroup', () => {
8786

8887
it('should handle multiple subscriptions (warm)', async (done: any) => {
8988
const ITEMS = 4;
90-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
89+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
9190
const changes = stocks.valueChanges();
92-
changes.pipe(take(1)).subscribe(() => {}).add(() => {
93-
const sub = changes.pipe(take(1)).subscribe(data => {
91+
changes.pipe(take(1)).subscribe(() => {
92+
}).add(() => {
93+
changes.pipe(take(1)).subscribe(data => {
9494
expect(data.length).toEqual(ITEMS);
9595
}).add(() => {
9696
deleteThemAll(names, ref).then(done).catch(done.fail);
@@ -101,8 +101,8 @@ describe('AngularFirestoreCollectionGroup', () => {
101101
it('should handle dynamic queries that return empty sets', async (done) => {
102102
const ITEMS = 10;
103103
let count = 0;
104-
const firstIndex = 0;
105-
const pricefilter$ = new BehaviorSubject<number|null>(null);
104+
105+
const pricefilter$ = new BehaviorSubject<number | null>(null);
106106
const randomCollectionName = randomName(afs.firestore);
107107
const ref = afs.firestore.collection(`${randomCollectionName}`);
108108
const names = await createRandomStocks(afs.firestore, ref, ITEMS);
@@ -131,14 +131,13 @@ describe('AngularFirestoreCollectionGroup', () => {
131131
it('should listen to all snapshotChanges() by default', async (done) => {
132132
const ITEMS = 10;
133133
let count = 0;
134-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
134+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
135135
const sub = stocks.snapshotChanges().subscribe(data => {
136-
const ids = data.map(d => d.payload.doc.id);
137136
count = count + 1;
138137
// the first time should all be 'added'
139138
if (count === 1) {
140139
// make an update
141-
ref.doc(names[0]).update({ price: 2});
140+
ref.doc(names[0]).update({ price: 2 });
142141
}
143142
// on the second round, make sure the array is still the same
144143
// length but the updated item is now modified
@@ -154,9 +153,10 @@ describe('AngularFirestoreCollectionGroup', () => {
154153

155154
it('should handle multiple subscriptions (hot)', async (done: any) => {
156155
const ITEMS = 4;
157-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
156+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
158157
const changes = stocks.snapshotChanges();
159-
const sub = changes.subscribe(() => {}).add(
158+
const sub = changes.subscribe(() => {
159+
}).add(
160160
changes.pipe(take(1)).subscribe(data => {
161161
expect(data.length).toEqual(ITEMS);
162162
sub.unsubscribe();
@@ -168,10 +168,11 @@ describe('AngularFirestoreCollectionGroup', () => {
168168

169169
it('should handle multiple subscriptions (warm)', async (done: any) => {
170170
const ITEMS = 4;
171-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
171+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
172172
const changes = stocks.snapshotChanges();
173-
changes.pipe(take(1)).subscribe(() => {}).add(() => {
174-
const sub = changes.pipe(take(1)).subscribe(data => {
173+
changes.pipe(take(1)).subscribe(() => {
174+
}).add(() => {
175+
changes.pipe(take(1)).subscribe(data => {
175176
expect(data.length).toEqual(ITEMS);
176177
}).add(() => {
177178
deleteThemAll(names, ref).then(done).catch(done.fail);
@@ -183,7 +184,7 @@ describe('AngularFirestoreCollectionGroup', () => {
183184
const ITEMS = 10;
184185
let count = 0;
185186
let firstIndex = 0;
186-
const { randomCollectionName, ref, stocks, names } =
187+
const { ref, stocks, names } =
187188
await collectionHarness(afs, ITEMS, ref => ref.orderBy('price', 'desc'));
188189
const sub = stocks.snapshotChanges().subscribe(data => {
189190
count = count + 1;
@@ -208,7 +209,7 @@ describe('AngularFirestoreCollectionGroup', () => {
208209

209210
it('should be able to filter snapshotChanges() types - modified', async (done) => {
210211
const ITEMS = 10;
211-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
212+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
212213

213214
const sub = stocks.snapshotChanges(['modified']).pipe(skip(1)).subscribe(data => {
214215
sub.unsubscribe();
@@ -224,7 +225,9 @@ describe('AngularFirestoreCollectionGroup', () => {
224225

225226
it('should be able to filter snapshotChanges() types - added', async (done) => {
226227
const ITEMS = 10;
227-
let { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
228+
const harness = await collectionHarness(afs, ITEMS);
229+
const { randomCollectionName, ref, stocks } = harness;
230+
let { names } = harness;
228231
const nextId = ref.doc('a').id;
229232

230233
const sub = stocks.snapshotChanges(['added']).pipe(skip(1)).subscribe(data => {
@@ -265,20 +268,24 @@ describe('AngularFirestoreCollectionGroup', () => {
265268

266269
it('should be able to filter snapshotChanges() types - added/modified', async (done) => {
267270
const ITEMS = 10;
268-
let { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
271+
272+
const harness = await collectionHarness(afs, ITEMS);
273+
const { ref, stocks } = harness;
274+
let { names } = harness;
275+
269276
const nextId = ref.doc('a').id;
270277
let count = 0;
271278

272-
const sub = stocks.snapshotChanges(['added', 'modified']).pipe(skip(1), take(2)).subscribe(data => {
279+
stocks.snapshotChanges(['added', 'modified']).pipe(skip(1), take(2)).subscribe(data => {
273280
count += 1;
274-
if (count == 1) {
281+
if (count === 1) {
275282
const change = data.filter(x => x.payload.doc.id === nextId)[0];
276283
expect(data.length).toEqual(ITEMS + 1);
277284
expect(change.payload.doc.data().price).toEqual(2);
278285
expect(change.type).toEqual('added');
279286
delayUpdate(ref, names[0], { price: 2 });
280287
}
281-
if (count == 2) {
288+
if (count === 2) {
282289
const change = data.filter(x => x.payload.doc.id === names[0])[0];
283290
expect(data.length).toEqual(ITEMS + 1);
284291
expect(change.payload.doc.data().price).toEqual(2);
@@ -294,7 +301,7 @@ describe('AngularFirestoreCollectionGroup', () => {
294301

295302
it('should be able to filter snapshotChanges() types - removed', async (done) => {
296303
const ITEMS = 10;
297-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
304+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
298305

299306
const sub = stocks.snapshotChanges(['added', 'removed']).pipe(skip(1)).subscribe(data => {
300307
sub.unsubscribe();
@@ -314,7 +321,7 @@ describe('AngularFirestoreCollectionGroup', () => {
314321

315322
it('should get stateChanges() updates', async (done: any) => {
316323
const ITEMS = 10;
317-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
324+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
318325

319326
const sub = stocks.stateChanges().subscribe(data => {
320327
// unsub immediately as we will be deleting data at the bottom
@@ -337,11 +344,11 @@ describe('AngularFirestoreCollectionGroup', () => {
337344
it('should listen to all stateChanges() by default', async (done) => {
338345
const ITEMS = 10;
339346
let count = 0;
340-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
341-
const sub = stocks.stateChanges().subscribe(data => {
347+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
348+
stocks.stateChanges().subscribe(data => {
342349
count = count + 1;
343350
if (count === 1) {
344-
ref.doc(names[0]).update({ price: 2});
351+
ref.doc(names[0]).update({ price: 2 });
345352
}
346353
if (count === 2) {
347354
expect(data.length).toEqual(1);
@@ -353,9 +360,10 @@ describe('AngularFirestoreCollectionGroup', () => {
353360

354361
it('should handle multiple subscriptions (hot)', async (done: any) => {
355362
const ITEMS = 4;
356-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
363+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
357364
const changes = stocks.stateChanges();
358-
const sub = changes.subscribe(() => {}).add(
365+
const sub = changes.subscribe(() => {
366+
}).add(
359367
changes.pipe(take(1)).subscribe(data => {
360368
expect(data.length).toEqual(ITEMS);
361369
sub.unsubscribe();
@@ -367,10 +375,11 @@ describe('AngularFirestoreCollectionGroup', () => {
367375

368376
it('should handle multiple subscriptions (warm)', async (done: any) => {
369377
const ITEMS = 4;
370-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
378+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
371379
const changes = stocks.stateChanges();
372-
changes.pipe(take(1)).subscribe(() => {}).add(() => {
373-
const sub = changes.pipe(take(1)).subscribe(data => {
380+
changes.pipe(take(1)).subscribe(() => {
381+
}).add(() => {
382+
changes.pipe(take(1)).subscribe(data => {
374383
expect(data.length).toEqual(ITEMS);
375384
}).add(() => {
376385
deleteThemAll(names, ref).then(done).catch(done.fail);
@@ -380,8 +389,7 @@ describe('AngularFirestoreCollectionGroup', () => {
380389

381390
it('should be able to filter stateChanges() types - modified', async (done) => {
382391
const ITEMS = 10;
383-
const count = 0;
384-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
392+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
385393

386394
const sub = stocks.stateChanges(['modified']).subscribe(data => {
387395
sub.unsubscribe();
@@ -397,8 +405,11 @@ describe('AngularFirestoreCollectionGroup', () => {
397405

398406
it('should be able to filter stateChanges() types - added', async (done) => {
399407
const ITEMS = 10;
400-
const count = 0;
401-
let { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
408+
409+
const harness = await collectionHarness(afs, ITEMS);
410+
const { ref, stocks } = harness;
411+
let { names } = harness;
412+
402413

403414
const sub = stocks.stateChanges(['added']).pipe(skip(1)).subscribe(data => {
404415
sub.unsubscribe();
@@ -416,7 +427,7 @@ describe('AngularFirestoreCollectionGroup', () => {
416427

417428
it('should be able to filter stateChanges() types - removed', async (done) => {
418429
const ITEMS = 10;
419-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
430+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
420431

421432
const sub = stocks.stateChanges(['removed']).subscribe(data => {
422433
sub.unsubscribe();
@@ -434,11 +445,11 @@ describe('AngularFirestoreCollectionGroup', () => {
434445
it('should listen to all events for auditTrail() by default', async (done) => {
435446
const ITEMS = 10;
436447
let count = 0;
437-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
448+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
438449
const sub = stocks.auditTrail().subscribe(data => {
439450
count = count + 1;
440451
if (count === 1) {
441-
ref.doc(names[0]).update({ price: 2});
452+
ref.doc(names[0]).update({ price: 2 });
442453
}
443454
if (count === 2) {
444455
sub.unsubscribe();
@@ -451,7 +462,7 @@ describe('AngularFirestoreCollectionGroup', () => {
451462

452463
it('should be able to filter auditTrail() types - removed', async (done) => {
453464
const ITEMS = 10;
454-
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
465+
const { ref, stocks, names } = await collectionHarness(afs, ITEMS);
455466

456467
const sub = stocks.auditTrail(['removed']).subscribe(data => {
457468
sub.unsubscribe();

0 commit comments

Comments
 (0)