emberflow 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,7 @@ const validators_1 = require("../sample-custom/validators");
33
33
  const batch = __importStar(require("../utils/batch"));
34
34
  var Timestamp = firebase_admin_1.firestore.Timestamp;
35
35
  const paths_1 = require("../utils/paths");
36
+ const adminClient = __importStar(require("emberflow-admin-client/lib"));
36
37
  jest.spyOn(console, "log").mockImplementation();
37
38
  jest.spyOn(console, "info").mockImplementation();
38
39
  const projectConfig = {
@@ -78,6 +79,7 @@ describe("distribute", () => {
78
79
  "/users/test-user-id/documents/test-doc-id",
79
80
  {
80
81
  action: "merge",
82
+ priority: "normal",
81
83
  doc: { name: "test-doc-name-updated" },
82
84
  instructions: {
83
85
  "count": "++",
@@ -118,6 +120,74 @@ describe("distribute", () => {
118
120
  batchDeleteSpy.mockRestore();
119
121
  });
120
122
  });
123
+ describe("distributeLater", () => {
124
+ let submitFormSpy;
125
+ beforeEach(() => {
126
+ submitFormSpy = jest.spyOn(adminClient, "submitForm").mockImplementation();
127
+ (0, index_1.initializeEmberFlow)(projectConfig, admin, db_structure_1.dbStructure, db_structure_1.Entity, security_1.securityConfig, validators_1.validatorConfig, []);
128
+ });
129
+ afterEach(() => {
130
+ submitFormSpy.mockRestore();
131
+ });
132
+ it("should update docs priority from normal to high and submit form for later", async () => {
133
+ const doc1 = {
134
+ action: "merge",
135
+ priority: "normal",
136
+ doc: { name: "test-doc-name-updated" },
137
+ dstPath: "/users/test-user-id/documents/doc1",
138
+ };
139
+ const doc2 = {
140
+ action: "merge",
141
+ priority: "normal",
142
+ doc: { name: "test-doc-name-updated" },
143
+ dstPath: "/users/test-user-id/documents/doc2",
144
+ };
145
+ const usersDocsByDstPath = new Map([
146
+ ["/users/test-user-id/documents/doc1", doc1],
147
+ ["/users/test-user-id/documents/doc2", doc2],
148
+ ]);
149
+ const formId = "formId";
150
+ await (0, index_utils_1.distributeLater)(usersDocsByDstPath, formId);
151
+ expect(submitFormSpy).toHaveBeenCalledTimes(1);
152
+ expect(submitFormSpy.mock.calls[0][0]).toEqual({
153
+ "@docPath": `@internal/forDistribution/distributions/${formId}`,
154
+ "@actionType": "create",
155
+ "logicResultDocs": [
156
+ Object.assign(Object.assign({}, doc1), { priority: "high" }),
157
+ Object.assign(Object.assign({}, doc2), { priority: "high" }),
158
+ ],
159
+ });
160
+ });
161
+ it("should update docs priority from low to normal and submit form for later", async () => {
162
+ const doc1 = {
163
+ action: "merge",
164
+ priority: "low",
165
+ doc: { name: "test-doc-name-updated" },
166
+ dstPath: "/users/test-user-id/documents/doc1",
167
+ };
168
+ const doc2 = {
169
+ action: "merge",
170
+ priority: "low",
171
+ doc: { name: "test-doc-name-updated" },
172
+ dstPath: "/users/test-user-id/documents/doc2",
173
+ };
174
+ const usersDocsByDstPath = new Map([
175
+ ["/users/test-user-id/documents/doc1", doc1],
176
+ ["/users/test-user-id/documents/doc2", doc2],
177
+ ]);
178
+ const formId = "formId";
179
+ await (0, index_utils_1.distributeLater)(usersDocsByDstPath, formId);
180
+ expect(submitFormSpy).toHaveBeenCalledTimes(1);
181
+ expect(submitFormSpy.mock.calls[0][0]).toEqual({
182
+ "@docPath": `@internal/forDistribution/distributions/${formId}`,
183
+ "@actionType": "create",
184
+ "logicResultDocs": [
185
+ Object.assign(Object.assign({}, doc1), { priority: "normal" }),
186
+ Object.assign(Object.assign({}, doc2), { priority: "normal" }),
187
+ ],
188
+ });
189
+ });
190
+ });
121
191
  describe("validateForm", () => {
122
192
  it("returns an object with empty validationResult when document is valid", async () => {
123
193
  const entity = "user";
@@ -221,10 +291,24 @@ describe("runBusinessLogics", () => {
221
291
  timeCreated: firebase_admin_1.firestore.Timestamp.now(),
222
292
  modifiedFields: formModifiedFields,
223
293
  };
224
- it("should call all matching logics and return their results", async () => {
225
- const logicFn1 = jest.fn().mockResolvedValue({ status: "finished" });
226
- const logicFn2 = jest.fn().mockResolvedValue({ status: "finished" });
227
- const logicFn3 = jest.fn().mockResolvedValue({ status: "error", message: "Error message" });
294
+ let distributeFn;
295
+ let logicFn1;
296
+ let logicFn2;
297
+ let logicFn3;
298
+ beforeEach(() => {
299
+ distributeFn = jest.fn();
300
+ logicFn1 = jest.fn().mockResolvedValue({ status: "finished" });
301
+ logicFn2 = jest.fn().mockResolvedValue({ status: "finished" });
302
+ logicFn3 = jest.fn().mockResolvedValue({ status: "error", message: "Error message" });
303
+ });
304
+ afterEach(() => {
305
+ // Cleanup
306
+ logicFn1.mockRestore();
307
+ logicFn2.mockRestore();
308
+ logicFn3.mockRestore();
309
+ distributeFn.mockRestore();
310
+ });
311
+ it("should call all matching logics and pass their results to distributeFn", async () => {
228
312
  const logics = [
229
313
  {
230
314
  name: "Logic 1",
@@ -249,92 +333,145 @@ describe("runBusinessLogics", () => {
249
333
  },
250
334
  ];
251
335
  (0, index_1.initializeEmberFlow)(projectConfig, admin, db_structure_1.dbStructure, db_structure_1.Entity, security_1.securityConfig, validators_1.validatorConfig, logics);
252
- const results = await (0, index_utils_1.runBusinessLogics)(actionType, formModifiedFields, entity, action);
253
- expect(logicFn1).toHaveBeenCalledWith(action);
254
- expect(logicFn2).toHaveBeenCalledWith(action);
336
+ await (0, index_utils_1.runBusinessLogics)(actionType, formModifiedFields, entity, action, distributeFn);
337
+ expect(logicFn1).toHaveBeenCalledWith(action, undefined);
338
+ expect(logicFn2).toHaveBeenCalledWith(action, undefined);
255
339
  expect(logicFn3).not.toHaveBeenCalled();
256
- expect(results).toEqual([
340
+ expect(distributeFn).toHaveBeenCalledTimes(1);
341
+ expect(distributeFn).toHaveBeenCalledWith([
257
342
  expect.objectContaining({
258
343
  status: "finished",
259
344
  execTime: expect.any(Number),
260
345
  timeFinished: expect.any(Timestamp),
261
346
  }),
262
- expect.objectContaining({ status: "finished" }),
263
- ]);
347
+ expect.objectContaining({
348
+ status: "finished",
349
+ execTime: expect.any(Number),
350
+ timeFinished: expect.any(Timestamp),
351
+ }),
352
+ ], 0);
264
353
  });
265
- it("should return an empty array if no matching logics are found", async () => {
354
+ it("should recall logic when it returns \"partial-result\" status", async () => {
355
+ logicFn2.mockResolvedValueOnce({ status: "partial-result", nextPage: {} });
356
+ const logics = [
357
+ {
358
+ name: "Logic 1",
359
+ actionTypes: ["create"],
360
+ modifiedFields: ["field1"],
361
+ entities: ["user"],
362
+ logicFn: logicFn1,
363
+ },
364
+ {
365
+ name: "Logic 2",
366
+ actionTypes: "all",
367
+ modifiedFields: ["field2"],
368
+ entities: ["user"],
369
+ logicFn: logicFn2,
370
+ },
371
+ ];
372
+ (0, index_1.initializeEmberFlow)(projectConfig, admin, db_structure_1.dbStructure, db_structure_1.Entity, security_1.securityConfig, validators_1.validatorConfig, logics);
373
+ await (0, index_utils_1.runBusinessLogics)(actionType, formModifiedFields, entity, action, distributeFn);
374
+ expect(logicFn1).toHaveBeenCalledWith(action, undefined);
375
+ expect(logicFn2).toHaveBeenCalledWith(action, undefined);
376
+ expect(distributeFn).toHaveBeenCalledTimes(2);
377
+ expect(distributeFn.mock.calls[0]).toEqual([[
378
+ expect.objectContaining({
379
+ status: "partial-result",
380
+ nextPage: {},
381
+ execTime: expect.any(Number),
382
+ timeFinished: expect.any(Timestamp),
383
+ }),
384
+ expect.objectContaining({
385
+ status: "finished",
386
+ execTime: expect.any(Number),
387
+ timeFinished: expect.any(Timestamp),
388
+ }),
389
+ ], 0]);
390
+ expect(logicFn2).toHaveBeenCalledWith(action, {});
391
+ expect(distributeFn.mock.calls[1]).toEqual([[
392
+ expect.objectContaining({
393
+ status: "finished",
394
+ execTime: expect.any(Number),
395
+ timeFinished: expect.any(Timestamp),
396
+ }),
397
+ ], 1]);
398
+ });
399
+ it("should not call any logic when no matching logics are found", async () => {
266
400
  const logics = [
267
401
  {
268
402
  name: "Logic 1",
269
403
  actionTypes: ["create"],
270
404
  modifiedFields: ["field1"],
271
405
  entities: ["customentity"],
272
- logicFn: jest.fn(),
406
+ logicFn: logicFn1,
273
407
  },
274
408
  {
275
409
  name: "Logic 2",
276
410
  actionTypes: ["update"],
277
411
  modifiedFields: ["field2"],
278
412
  entities: ["customentity"],
279
- logicFn: jest.fn(),
413
+ logicFn: logicFn2,
280
414
  },
281
415
  {
282
416
  name: "Logic 3",
283
417
  actionTypes: ["delete"],
284
418
  modifiedFields: ["field3"],
285
419
  entities: ["customentity"],
286
- logicFn: jest.fn(),
420
+ logicFn: logicFn3,
287
421
  },
288
422
  ];
289
423
  (0, index_1.initializeEmberFlow)(projectConfig, admin, db_structure_1.dbStructure, db_structure_1.Entity, security_1.securityConfig, validators_1.validatorConfig, logics);
290
- const results = await (0, index_utils_1.runBusinessLogics)(actionType, formModifiedFields, entity, action);
291
- expect(results).toEqual([]);
424
+ await (0, index_utils_1.runBusinessLogics)(actionType, formModifiedFields, entity, action, distributeFn);
425
+ expect(logicFn1).not.toHaveBeenCalled();
426
+ expect(logicFn2).not.toHaveBeenCalled();
427
+ expect(logicFn3).not.toHaveBeenCalled();
428
+ expect(distributeFn).not.toHaveBeenCalled();
292
429
  });
293
430
  });
294
431
  describe("groupDocsByUserAndDstPath", () => {
295
432
  (0, index_1.initializeEmberFlow)(projectConfig, admin, db_structure_1.dbStructure, db_structure_1.Entity, {}, {}, []);
296
433
  const docsByDstPath = new Map([
297
- ["users/user123/document1", { action: "merge", dstPath: "users/user123/document1", doc: { field1: "value1", field2: "value2" } }],
298
- ["users/user123/document2", { action: "merge", dstPath: "users/user123/document2", doc: { field3: "value3", field6: "value6" } }],
299
- ["users/user456/document3", { action: "merge", dstPath: "users/user456/document3", doc: { field4: "value4" } }],
300
- ["users/user789/document4", { action: "delete", dstPath: "users/user789/document4" }],
301
- ["othercollection/document5", { action: "merge", dstPath: "othercollection/document5", doc: { field5: "value5" } }],
434
+ ["users/user123/document1", { action: "merge", priority: "normal", dstPath: "users/user123/document1", doc: { field1: "value1", field2: "value2" } }],
435
+ ["users/user123/document2", { action: "merge", priority: "normal", dstPath: "users/user123/document2", doc: { field3: "value3", field6: "value6" } }],
436
+ ["users/user456/document3", { action: "merge", priority: "normal", dstPath: "users/user456/document3", doc: { field4: "value4" } }],
437
+ ["users/user789/document4", { action: "delete", priority: "normal", dstPath: "users/user789/document4" }],
438
+ ["othercollection/document5", { action: "merge", priority: "normal", dstPath: "othercollection/document5", doc: { field5: "value5" } }],
302
439
  ]);
303
440
  it("should group documents by destination path and user", () => {
304
441
  const userId = "user123";
305
442
  const expectedResults = {
306
443
  userDocsByDstPath: new Map([
307
- ["users/user123/document1", { action: "merge", dstPath: "users/user123/document1", doc: { field1: "value1", field2: "value2" } }],
308
- ["users/user123/document2", { action: "merge", dstPath: "users/user123/document2", doc: { field3: "value3", field6: "value6" } }],
444
+ ["users/user123/document1", { action: "merge", priority: "normal", dstPath: "users/user123/document1", doc: { field1: "value1", field2: "value2" } }],
445
+ ["users/user123/document2", { action: "merge", priority: "normal", dstPath: "users/user123/document2", doc: { field3: "value3", field6: "value6" } }],
309
446
  ]),
310
447
  otherUsersDocsByDstPath: new Map([
311
- ["users/user456/document3", { action: "merge", dstPath: "users/user456/document3", doc: { field4: "value4" } }],
312
- ["users/user789/document4", { action: "delete", dstPath: "users/user789/document4" }],
313
- ["othercollection/document5", { action: "merge", dstPath: "othercollection/document5", doc: { field5: "value5" } }],
448
+ ["users/user456/document3", { action: "merge", priority: "normal", dstPath: "users/user456/document3", doc: { field4: "value4" } }],
449
+ ["users/user789/document4", { action: "delete", priority: "normal", dstPath: "users/user789/document4" }],
450
+ ["othercollection/document5", { action: "merge", priority: "normal", dstPath: "othercollection/document5", doc: { field5: "value5" } }],
314
451
  ]),
315
452
  };
316
453
  const results = (0, index_utils_1.groupDocsByUserAndDstPath)(docsByDstPath, userId);
317
454
  expect(results).toEqual(expectedResults);
318
455
  });
319
456
  });
320
- const friend = {
321
- "@id": "friendId",
322
- "name": "Friend Name",
323
- "games": 2,
324
- };
325
- const games = [
326
- {
327
- "@id": "game1Id",
328
- "name": "Dota 2",
329
- },
330
- {
331
- "@id": "game2Id",
332
- "name": "Farlight",
333
- },
334
- ];
335
457
  describe("expandConsolidateAndGroupByDstPath", () => {
336
458
  let dbSpy;
337
459
  let consoleWarnSpy;
460
+ const games = [
461
+ {
462
+ "@id": "game1Id",
463
+ "name": "Game 1",
464
+ },
465
+ {
466
+ "@id": "game2Id",
467
+ "name": "Game 2",
468
+ },
469
+ ];
470
+ const friend = {
471
+ "@id": "friendId",
472
+ "name": "Friend Name",
473
+ "games": games.length,
474
+ };
338
475
  beforeEach(() => {
339
476
  const dbDoc = (path) => {
340
477
  const pathArray = path.split("/");
@@ -378,8 +515,8 @@ describe("expandConsolidateAndGroupByDstPath", () => {
378
515
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
379
516
  status: "finished",
380
517
  documents: [
381
- { action: "merge", dstPath: "path1/doc1", doc: { field1: "value1" }, instructions: { field2: "++" } },
382
- { action: "delete", dstPath: "path2/doc2" },
518
+ { action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1" }, instructions: { field2: "++" } },
519
+ { action: "delete", priority: "normal", dstPath: "path2/doc2" },
383
520
  ],
384
521
  },
385
522
  {
@@ -387,11 +524,11 @@ describe("expandConsolidateAndGroupByDstPath", () => {
387
524
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
388
525
  status: "finished",
389
526
  documents: [
390
- { action: "merge", dstPath: "path1/doc1", doc: { field1: "value1a" }, instructions: { field2: "--" } },
391
- { action: "merge", dstPath: "path1/doc1", doc: { field3: "value3" }, instructions: { field4: "--" } },
392
- { action: "copy", srcPath: "path3/doc3", dstPath: "path4/doc4" },
393
- { action: "merge", dstPath: "path2/doc2", doc: { field4: "value4" } },
394
- { action: "merge", dstPath: "path7/doc7", doc: { field6: "value7" } },
527
+ { action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1a" }, instructions: { field2: "--" } },
528
+ { action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field3: "value3" }, instructions: { field4: "--" } },
529
+ { action: "copy", priority: "normal", srcPath: "path3/doc3", dstPath: "path4/doc4" },
530
+ { action: "merge", priority: "normal", dstPath: "path2/doc2", doc: { field4: "value4" } },
531
+ { action: "merge", priority: "normal", dstPath: "path7/doc7", doc: { field6: "value7" } },
395
532
  ],
396
533
  },
397
534
  {
@@ -399,10 +536,10 @@ describe("expandConsolidateAndGroupByDstPath", () => {
399
536
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
400
537
  status: "finished",
401
538
  documents: [
402
- { action: "copy", srcPath: "path5/doc5", dstPath: "path6/doc6" },
403
- { action: "delete", dstPath: "path7/doc7" },
404
- { action: "delete", dstPath: "path7/doc7" },
405
- { action: "copy", srcPath: "path3/doc3", dstPath: "path4/doc4" },
539
+ { action: "copy", priority: "normal", srcPath: "path5/doc5", dstPath: "path6/doc6" },
540
+ { action: "delete", priority: "normal", dstPath: "path7/doc7" },
541
+ { action: "delete", priority: "normal", dstPath: "path7/doc7" },
542
+ { action: "copy", priority: "normal", srcPath: "path3/doc3", dstPath: "path4/doc4" },
406
543
  ],
407
544
  },
408
545
  {
@@ -410,20 +547,21 @@ describe("expandConsolidateAndGroupByDstPath", () => {
410
547
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
411
548
  status: "finished",
412
549
  documents: [
413
- { action: "delete", dstPath: "path2/doc2" },
414
- { action: "copy", srcPath: "path3/doc3", dstPath: "path7/doc7" },
550
+ { action: "delete", priority: "normal", dstPath: "path2/doc2" },
551
+ { action: "copy", priority: "normal", srcPath: "path3/doc3", dstPath: "path7/doc7" },
415
552
  ],
416
553
  },
417
554
  ];
418
555
  // Act
419
- const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResults);
556
+ const logicResultDocs = logicResults.map((logicResult) => logicResult.documents).flat();
557
+ const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResultDocs);
420
558
  // Assert
421
559
  const expectedResult = new Map([
422
- ["path1/doc1", { action: "merge", dstPath: "path1/doc1", doc: { field1: "value1a", field3: "value3" }, instructions: { field2: "--", field4: "--" } }],
423
- ["path2/doc2", { action: "delete", dstPath: "path2/doc2" }],
424
- ["path4/doc4", { action: "merge", dstPath: "path4/doc4", doc: {}, instructions: {} }],
425
- ["path6/doc6", { action: "merge", dstPath: "path6/doc6", doc: {} }],
426
- ["path7/doc7", { action: "delete", dstPath: "path7/doc7" }],
560
+ ["path1/doc1", { action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1a", field3: "value3" }, instructions: { field2: "--", field4: "--" } }],
561
+ ["path2/doc2", { action: "delete", priority: "normal", dstPath: "path2/doc2" }],
562
+ ["path4/doc4", { action: "merge", priority: "normal", dstPath: "path4/doc4", doc: {}, instructions: {} }],
563
+ ["path6/doc6", { action: "merge", priority: "normal", dstPath: "path6/doc6", doc: {} }],
564
+ ["path7/doc7", { action: "delete", priority: "normal", dstPath: "path7/doc7" }],
427
565
  ]);
428
566
  expect(result).toEqual(expectedResult);
429
567
  // Verify that console.warn was called
@@ -444,7 +582,7 @@ describe("expandConsolidateAndGroupByDstPath", () => {
444
582
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
445
583
  status: "finished",
446
584
  documents: [
447
- { action: "recursive-copy", srcPath: "users/123/friends/123", dstPath: "users/456/friends/123" },
585
+ { action: "recursive-copy", priority: "normal", srcPath: "users/123/friends/123", dstPath: "users/456/friends/123" },
448
586
  ],
449
587
  },
450
588
  {
@@ -452,32 +590,37 @@ describe("expandConsolidateAndGroupByDstPath", () => {
452
590
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
453
591
  status: "finished",
454
592
  documents: [
455
- { action: "merge", dstPath: "path1/doc1", doc: { field1: "value1a" }, instructions: { field2: "--" } },
593
+ { action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1a" }, instructions: { field2: "--" } },
456
594
  ],
457
595
  },
458
596
  ];
459
597
  // Act
460
- const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResults);
598
+ const logicResultDocs = logicResults.map((logicResult) => logicResult.documents).flat();
599
+ const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResultDocs);
461
600
  // Assert
462
601
  const expectedResult = new Map([
463
602
  ["path1/doc1", {
464
603
  action: "merge",
604
+ priority: "normal",
465
605
  dstPath: "path1/doc1",
466
606
  doc: { field1: "value1a" },
467
607
  instructions: { field2: "--" },
468
608
  }],
469
609
  ["users/456/friends/123", {
470
610
  action: "merge",
611
+ priority: "normal",
471
612
  doc: friend,
472
613
  dstPath: "users/456/friends/123",
473
614
  }],
474
615
  ["users/456/friends/123/games/1", {
475
616
  action: "merge",
617
+ priority: "normal",
476
618
  doc: games[0],
477
619
  dstPath: "users/456/friends/123/games/1",
478
620
  }],
479
621
  ["users/456/friends/123/games/2", {
480
622
  action: "merge",
623
+ priority: "normal",
481
624
  doc: games[1],
482
625
  dstPath: "users/456/friends/123/games/2",
483
626
  }],
@@ -494,7 +637,7 @@ describe("expandConsolidateAndGroupByDstPath", () => {
494
637
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
495
638
  status: "finished",
496
639
  documents: [
497
- { action: "recursive-delete", dstPath: "users/123/friends/123" },
640
+ { action: "recursive-delete", priority: "normal", dstPath: "users/123/friends/123" },
498
641
  ],
499
642
  },
500
643
  {
@@ -502,7 +645,7 @@ describe("expandConsolidateAndGroupByDstPath", () => {
502
645
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
503
646
  status: "finished",
504
647
  documents: [
505
- { action: "merge", dstPath: "path1/doc1", doc: { field1: "value1a" }, instructions: { field2: "--" } },
648
+ { action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1a" }, instructions: { field2: "--" } },
506
649
  ],
507
650
  },
508
651
  {
@@ -510,30 +653,35 @@ describe("expandConsolidateAndGroupByDstPath", () => {
510
653
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
511
654
  status: "finished",
512
655
  documents: [
513
- { action: "merge", dstPath: "users/123/friends/123", instructions: { games: "--" } },
656
+ { action: "merge", priority: "normal", dstPath: "users/123/friends/123", instructions: { games: "--" } },
514
657
  ],
515
658
  },
516
659
  ];
517
660
  // Act
518
- const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResults);
661
+ const logicResultDocs = logicResults.map((logicResult) => logicResult.documents).flat();
662
+ const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResultDocs);
519
663
  // Assert
520
664
  const expectedResult = new Map([
521
665
  ["path1/doc1", {
522
666
  action: "merge",
667
+ priority: "normal",
523
668
  dstPath: "path1/doc1",
524
669
  doc: { field1: "value1a" },
525
670
  instructions: { field2: "--" },
526
671
  }],
527
672
  ["users/123/friends/123", {
528
673
  action: "delete",
674
+ priority: "normal",
529
675
  dstPath: "users/123/friends/123",
530
676
  }],
531
677
  ["users/123/friends/123/games/1", {
532
678
  action: "delete",
679
+ priority: "normal",
533
680
  dstPath: "users/123/friends/123/games/1",
534
681
  }],
535
682
  ["users/123/friends/123/games/2", {
536
683
  action: "delete",
684
+ priority: "normal",
537
685
  dstPath: "users/123/friends/123/games/2",
538
686
  }],
539
687
  ]);
@@ -552,8 +700,8 @@ describe("expandConsolidateAndGroupByDstPath", () => {
552
700
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
553
701
  status: "finished",
554
702
  documents: [
555
- { action: "copy", srcPath: "users/123/friends/123/games/1", dstPath: "users/456/friends/123/games/1" },
556
- { action: "copy", srcPath: "users/123/friends/123/games/2", dstPath: "users/456/friends/123/games/2" },
703
+ { action: "copy", priority: "normal", srcPath: "users/123/friends/123/games/1", dstPath: "users/456/friends/123/games/1" },
704
+ { action: "copy", priority: "normal", srcPath: "users/123/friends/123/games/2", dstPath: "users/456/friends/123/games/2" },
557
705
  ],
558
706
  },
559
707
  {
@@ -561,27 +709,31 @@ describe("expandConsolidateAndGroupByDstPath", () => {
561
709
  timeFinished: firebase_admin_1.firestore.Timestamp.now(),
562
710
  status: "finished",
563
711
  documents: [
564
- { action: "merge", dstPath: "path1/doc1", doc: { field1: "value1a" }, instructions: { field2: "--" } },
712
+ { action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1a" }, instructions: { field2: "--" } },
565
713
  ],
566
714
  },
567
715
  ];
568
716
  // Act
569
- const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResults);
717
+ const logicResultDocs = logicResults.map((logicResult) => logicResult.documents).flat();
718
+ const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResultDocs);
570
719
  // Assert
571
720
  const expectedResult = new Map([
572
721
  ["path1/doc1", {
573
722
  action: "merge",
723
+ priority: "normal",
574
724
  dstPath: "path1/doc1",
575
725
  doc: { field1: "value1a" },
576
726
  instructions: { field2: "--" },
577
727
  }],
578
728
  ["users/456/friends/123/games/1", {
579
729
  action: "merge",
730
+ priority: "normal",
580
731
  doc: games[0],
581
732
  dstPath: "users/456/friends/123/games/1",
582
733
  }],
583
734
  ["users/456/friends/123/games/2", {
584
735
  action: "merge",
736
+ priority: "normal",
585
737
  doc: games[1],
586
738
  dstPath: "users/456/friends/123/games/2",
587
739
  }],
@@ -617,11 +769,13 @@ describe("runViewLogics", () => {
617
769
  const dstPathLogicDocsMap = new Map();
618
770
  const logicResult1 = {
619
771
  action: "merge",
772
+ priority: "normal",
620
773
  doc: { name: "value1", sampleField2: "value2" },
621
774
  dstPath: "users/user123",
622
775
  };
623
776
  const logicResult2 = {
624
777
  action: "delete",
778
+ priority: "normal",
625
779
  dstPath: "users/user124",
626
780
  };
627
781
  dstPathLogicDocsMap.set(logicResult1.dstPath, logicResult1);