( firestore: firebase.firestore.Firestore, collectionRef: firebase.firestore.CollectionReference, numberOfItems )
| 12 | export const randomName = (firestore): string => firestore.collection('a').doc().id; |
| 13 | |
| 14 | export const createRandomStocks = async ( |
| 15 | firestore: firebase.firestore.Firestore, |
| 16 | collectionRef: firebase.firestore.CollectionReference, |
| 17 | numberOfItems |
| 18 | ) => { |
| 19 | // Create a batch to update everything at once |
| 20 | const batch = TestBed.runInInjectionContext(() => firestore.batch()); |
| 21 | // Store the random names to delete them later |
| 22 | let names: string[] = []; |
| 23 | Array.from(Array(numberOfItems)).forEach(() => { |
| 24 | const name = randomName(firestore); |
| 25 | TestBed.runInInjectionContext(() => batch.set(collectionRef.doc(name), FAKE_STOCK_DATA)); |
| 26 | names = [...names, name]; |
| 27 | }); |
| 28 | // Create the batch entries |
| 29 | // Commit! |
| 30 | await TestBed.runInInjectionContext(() => batch.commit()); |
| 31 | return names; |
| 32 | }; |
| 33 | |
| 34 | export function deleteThemAll(names, ref) { |
| 35 | const promises = names.map(name => ref.doc(name).delete()); |
no test coverage detected