MCPcopy
hub / github.com/angular/angularfire / createRandomStocks

Function createRandomStocks

src/compat/firestore/utils.spec.ts:14–32  ·  view source on GitHub ↗
(
  firestore: firebase.firestore.Firestore,
  collectionRef: firebase.firestore.CollectionReference,
  numberOfItems
)

Source from the content-addressed store, hash-verified

12export const randomName = (firestore): string => firestore.collection('a').doc().id;
13
14export 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
34export function deleteThemAll(names, ref) {
35 const promises = names.map(name => ref.doc(name).delete());

Callers 4

collectionHarnessFunction · 0.90
collection.spec.tsFile · 0.90
collectionHarnessFunction · 0.90

Calls 4

randomNameFunction · 0.85
forEachMethod · 0.65
setMethod · 0.65
docMethod · 0.45

Tested by

no test coverage detected