emberflow 1.4.22 → 1.4.23
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.
- package/lib/index-utils.d.ts +1 -1
- package/lib/index-utils.js +6 -29
- package/lib/index-utils.js.map +1 -1
- package/lib/index.js +17 -129
- package/lib/index.js.map +1 -1
- package/lib/logics/view-logics.d.ts +1 -1
- package/lib/logics/view-logics.js +26 -4
- package/lib/logics/view-logics.js.map +1 -1
- package/lib/tests/index-utils.test.js +0 -39
- package/lib/tests/index-utils.test.js.map +1 -1
- package/lib/tests/index.test.js +8 -464
- package/lib/tests/index.test.js.map +1 -1
- package/lib/tests/logics/view-logics.test.js +1 -1
- package/lib/tests/logics/view-logics.test.js.map +1 -1
- package/lib/tests/utils/distribution.test.js +4 -0
- package/lib/tests/utils/distribution.test.js.map +1 -1
- package/lib/types.d.ts +0 -1
- package/lib/utils/distribution.js +4 -2
- package/lib/utils/distribution.js.map +1 -1
- package/lib/utils/paths.d.ts +0 -1
- package/lib/utils/paths.js +1 -5
- package/lib/utils/paths.js.map +1 -1
- package/package.json +1 -1
package/lib/tests/index.test.js
CHANGED
|
@@ -129,41 +129,6 @@ describe("onFormSubmit", () => {
|
|
|
129
129
|
nestedField2: "oldValue",
|
|
130
130
|
},
|
|
131
131
|
};
|
|
132
|
-
const equation = "totalTodos = notStartedCount + inProgressCount + toVerifyCount + requestChangesCount + doneCount";
|
|
133
|
-
const now = Timestamp.fromDate(new Date());
|
|
134
|
-
const journalEntry = {
|
|
135
|
-
date: now,
|
|
136
|
-
ledgerEntries: [
|
|
137
|
-
{
|
|
138
|
-
account: "totalTodos",
|
|
139
|
-
debit: 1,
|
|
140
|
-
credit: 0,
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
account: "notStartedCount",
|
|
144
|
-
debit: 0,
|
|
145
|
-
credit: 1,
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
equation: equation,
|
|
149
|
-
};
|
|
150
|
-
const recordedJournalEntry = {
|
|
151
|
-
date: now,
|
|
152
|
-
ledgerEntries: [
|
|
153
|
-
{
|
|
154
|
-
account: "inProgressCount",
|
|
155
|
-
debit: 1,
|
|
156
|
-
credit: 0,
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
account: "doneCount",
|
|
160
|
-
debit: 0,
|
|
161
|
-
credit: 1,
|
|
162
|
-
},
|
|
163
|
-
],
|
|
164
|
-
equation: equation,
|
|
165
|
-
recordEntry: true,
|
|
166
|
-
};
|
|
167
132
|
beforeEach(() => {
|
|
168
133
|
jest.spyOn(indexUtils._mockable, "createMetricExecution").mockResolvedValue();
|
|
169
134
|
jest.spyOn(index_1._mockable, "createNowTimestamp").mockReturnValue(Timestamp.now());
|
|
@@ -527,387 +492,6 @@ describe("onFormSubmit", () => {
|
|
|
527
492
|
docMock.update.mockReset();
|
|
528
493
|
txnGetFnMock.mockClear();
|
|
529
494
|
});
|
|
530
|
-
it("should write journal entries first", async () => {
|
|
531
|
-
const consoleErrorSpy = jest.spyOn(console, "error").mockImplementation();
|
|
532
|
-
const consoleInfoSpy = jest.spyOn(console, "info").mockImplementation();
|
|
533
|
-
const queueRunViewLogicsSpy = jest.spyOn(viewLogics, "queueRunViewLogics").mockResolvedValue();
|
|
534
|
-
jest.spyOn(indexutils, "runBusinessLogics").mockImplementation(async (txnGet, action) => {
|
|
535
|
-
return {
|
|
536
|
-
status: "done",
|
|
537
|
-
logicResults,
|
|
538
|
-
};
|
|
539
|
-
});
|
|
540
|
-
const distributionMock = jest.spyOn(distribution, "queueForDistributionLater").mockImplementation(async () => {
|
|
541
|
-
console.log("distribute");
|
|
542
|
-
});
|
|
543
|
-
let logicResults = [
|
|
544
|
-
{
|
|
545
|
-
name: "logic 1",
|
|
546
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
547
|
-
status: "finished",
|
|
548
|
-
documents: [
|
|
549
|
-
{ action: "merge", priority: "normal", dstPath: "path1/doc1" },
|
|
550
|
-
],
|
|
551
|
-
},
|
|
552
|
-
];
|
|
553
|
-
const docPath = "users/user-1";
|
|
554
|
-
const form = {
|
|
555
|
-
"formData": JSON.stringify({
|
|
556
|
-
"@actionType": "create",
|
|
557
|
-
"name": "test",
|
|
558
|
-
"@docPath": docPath,
|
|
559
|
-
}),
|
|
560
|
-
"@status": "submit",
|
|
561
|
-
};
|
|
562
|
-
const event = createEvent(form);
|
|
563
|
-
await (0, index_1.onFormSubmit)(event);
|
|
564
|
-
expect(consoleInfoSpy).toHaveBeenCalledWith("No journal entries to write");
|
|
565
|
-
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
566
|
-
expect(txnGetFnMock).toBeCalledTimes(2);
|
|
567
|
-
logicResults = [
|
|
568
|
-
{
|
|
569
|
-
name: "logic 1",
|
|
570
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
571
|
-
status: "finished",
|
|
572
|
-
documents: [
|
|
573
|
-
{ action: "delete", priority: "normal", dstPath: "path1/doc1", journalEntries: [journalEntry] },
|
|
574
|
-
],
|
|
575
|
-
},
|
|
576
|
-
];
|
|
577
|
-
await (0, index_1.onFormSubmit)(event);
|
|
578
|
-
expect(consoleInfoSpy).toHaveBeenCalledWith("No journal entries to write");
|
|
579
|
-
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
580
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(11);
|
|
581
|
-
expect(txnGetFnMock).toBeCalledTimes(4);
|
|
582
|
-
logicResults = [
|
|
583
|
-
{
|
|
584
|
-
name: "logic 1",
|
|
585
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
586
|
-
status: "finished",
|
|
587
|
-
documents: [
|
|
588
|
-
{ action: "merge", priority: "normal", dstPath: "", journalEntries: [journalEntry] },
|
|
589
|
-
],
|
|
590
|
-
},
|
|
591
|
-
];
|
|
592
|
-
await (0, index_1.onFormSubmit)(event);
|
|
593
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith("Dst path has no docId");
|
|
594
|
-
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
595
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(14);
|
|
596
|
-
expect(txnGetFnMock).toHaveBeenCalledTimes(6);
|
|
597
|
-
logicResults = [
|
|
598
|
-
{
|
|
599
|
-
name: "logic 1",
|
|
600
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
601
|
-
status: "finished",
|
|
602
|
-
documents: [
|
|
603
|
-
{ action: "merge", priority: "high", dstPath: "path1/doc5", doc: { totalTodos: 1 }, journalEntries: [journalEntry] },
|
|
604
|
-
],
|
|
605
|
-
},
|
|
606
|
-
];
|
|
607
|
-
await (0, index_1.onFormSubmit)(event);
|
|
608
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith("Doc cannot have keys that are the same as account names");
|
|
609
|
-
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
610
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(17);
|
|
611
|
-
expect(txnGetFnMock).toHaveBeenCalledTimes(8);
|
|
612
|
-
logicResults = [
|
|
613
|
-
{
|
|
614
|
-
name: "logic 1",
|
|
615
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
616
|
-
status: "finished",
|
|
617
|
-
documents: [
|
|
618
|
-
{ action: "merge", priority: "high", dstPath: "path1/doc5", instructions: { totalTodos: "+1" }, journalEntries: [journalEntry] },
|
|
619
|
-
],
|
|
620
|
-
},
|
|
621
|
-
];
|
|
622
|
-
await (0, index_1.onFormSubmit)(event);
|
|
623
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith("Instructions cannot have keys that are the same as account names");
|
|
624
|
-
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
625
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(20);
|
|
626
|
-
expect(txnGetFnMock).toHaveBeenCalledTimes(10);
|
|
627
|
-
const unbalancedJournalEntry = {
|
|
628
|
-
date: index_1._mockable.createNowTimestamp(),
|
|
629
|
-
ledgerEntries: [
|
|
630
|
-
{
|
|
631
|
-
account: "totalTodos",
|
|
632
|
-
debit: 1,
|
|
633
|
-
credit: 0,
|
|
634
|
-
},
|
|
635
|
-
{
|
|
636
|
-
account: "notStartedCount",
|
|
637
|
-
debit: 0,
|
|
638
|
-
credit: 1,
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
account: "inProgressCount",
|
|
642
|
-
debit: 0,
|
|
643
|
-
credit: 1,
|
|
644
|
-
},
|
|
645
|
-
],
|
|
646
|
-
equation: equation,
|
|
647
|
-
};
|
|
648
|
-
logicResults = [
|
|
649
|
-
{
|
|
650
|
-
name: "logic 1",
|
|
651
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
652
|
-
status: "finished",
|
|
653
|
-
documents: [
|
|
654
|
-
{ action: "merge", priority: "high", dstPath: "path1/doc5", journalEntries: [unbalancedJournalEntry] },
|
|
655
|
-
],
|
|
656
|
-
},
|
|
657
|
-
];
|
|
658
|
-
await (0, index_1.onFormSubmit)(event);
|
|
659
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith("Debit and credit should be equal");
|
|
660
|
-
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
661
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(23);
|
|
662
|
-
expect(txnGetFnMock).toHaveBeenCalledTimes(12);
|
|
663
|
-
txnGetFnMock.mockRestore();
|
|
664
|
-
transactionSetMock.mockRestore();
|
|
665
|
-
transactionUpdateMock.mockRestore();
|
|
666
|
-
const docRef = index_1.db.doc("path1/doc1");
|
|
667
|
-
logicResults = [
|
|
668
|
-
{
|
|
669
|
-
name: "logic 1",
|
|
670
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
671
|
-
status: "finished",
|
|
672
|
-
documents: [
|
|
673
|
-
{ action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field: "value" }, journalEntries: [journalEntry] },
|
|
674
|
-
],
|
|
675
|
-
},
|
|
676
|
-
];
|
|
677
|
-
const user = {
|
|
678
|
-
"@id": "forDistribution",
|
|
679
|
-
"username": "forDistribution",
|
|
680
|
-
};
|
|
681
|
-
txnGetFnMock
|
|
682
|
-
.mockResolvedValueOnce({ data: () => (document) })
|
|
683
|
-
.mockResolvedValueOnce({ data: () => (user) })
|
|
684
|
-
.mockReturnValueOnce({ data: () => undefined });
|
|
685
|
-
await (0, index_1.onFormSubmit)(event);
|
|
686
|
-
expect(txnGetFnMock).toHaveBeenCalledTimes(3);
|
|
687
|
-
expect(txnGetFnMock).toHaveBeenCalledWith(docRef);
|
|
688
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(4);
|
|
689
|
-
expect(transactionSetMock).toHaveBeenCalledWith(docRef, { "field": "value", "@forDeletionLater": true });
|
|
690
|
-
expect(transactionUpdateMock).toHaveBeenCalledTimes(2);
|
|
691
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(1, docRef, {
|
|
692
|
-
"totalTodos": 1,
|
|
693
|
-
"@forDeletionLater": FieldValue.delete(),
|
|
694
|
-
});
|
|
695
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(2, docRef, {
|
|
696
|
-
"notStartedCount": 1,
|
|
697
|
-
"@forDeletionLater": FieldValue.delete(),
|
|
698
|
-
});
|
|
699
|
-
expect(queueRunViewLogicsSpy).toHaveBeenCalledTimes(1);
|
|
700
|
-
expect(queueRunViewLogicsSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, logicResults[0].documents[0]), { doc: {
|
|
701
|
-
field: "value",
|
|
702
|
-
totalTodos: 1,
|
|
703
|
-
notStartedCount: 1,
|
|
704
|
-
} }));
|
|
705
|
-
queueRunViewLogicsSpy.mockReset();
|
|
706
|
-
txnGetFnMock.mockRestore();
|
|
707
|
-
transactionSetMock.mockRestore();
|
|
708
|
-
transactionUpdateMock.mockRestore();
|
|
709
|
-
logicResults = [
|
|
710
|
-
{
|
|
711
|
-
name: "logic 1",
|
|
712
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
713
|
-
status: "finished",
|
|
714
|
-
documents: [
|
|
715
|
-
{ action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field: "value" }, journalEntries: [journalEntry] },
|
|
716
|
-
],
|
|
717
|
-
},
|
|
718
|
-
];
|
|
719
|
-
txnGetFnMock
|
|
720
|
-
.mockResolvedValueOnce({ data: () => (document) })
|
|
721
|
-
.mockResolvedValueOnce({ data: () => (user) })
|
|
722
|
-
.mockResolvedValueOnce({
|
|
723
|
-
data: () => ({
|
|
724
|
-
"totalTodos": 1,
|
|
725
|
-
"notStartedCount": 1,
|
|
726
|
-
}),
|
|
727
|
-
});
|
|
728
|
-
await (0, index_1.onFormSubmit)(event);
|
|
729
|
-
expect(txnGetFnMock).toHaveBeenCalledTimes(3);
|
|
730
|
-
expect(txnGetFnMock).toHaveBeenCalledWith(docRef);
|
|
731
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(3);
|
|
732
|
-
expect(transactionUpdateMock).toHaveBeenCalledTimes(3);
|
|
733
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(1, docRef, { "field": "value", "@forDeletionLater": true });
|
|
734
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(2, docRef, {
|
|
735
|
-
"totalTodos": 2,
|
|
736
|
-
"@forDeletionLater": FieldValue.delete(),
|
|
737
|
-
});
|
|
738
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(3, docRef, {
|
|
739
|
-
"notStartedCount": 2,
|
|
740
|
-
"@forDeletionLater": FieldValue.delete(),
|
|
741
|
-
});
|
|
742
|
-
expect(queueRunViewLogicsSpy).toHaveBeenCalledTimes(1);
|
|
743
|
-
expect(queueRunViewLogicsSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, logicResults[0].documents[0]), { doc: {
|
|
744
|
-
field: "value",
|
|
745
|
-
totalTodos: 2,
|
|
746
|
-
notStartedCount: 2,
|
|
747
|
-
} }));
|
|
748
|
-
queueRunViewLogicsSpy.mockReset();
|
|
749
|
-
txnGetFnMock.mockRestore();
|
|
750
|
-
transactionSetMock.mockRestore();
|
|
751
|
-
transactionUpdateMock.mockRestore();
|
|
752
|
-
txnGetFnMock
|
|
753
|
-
.mockResolvedValueOnce({ data: () => (document) })
|
|
754
|
-
.mockResolvedValueOnce({ data: () => (user) })
|
|
755
|
-
.mockResolvedValueOnce({
|
|
756
|
-
data: () => ({
|
|
757
|
-
"totalTodos": 2,
|
|
758
|
-
"notStartedCount": 0,
|
|
759
|
-
"inProgressCount": 2,
|
|
760
|
-
}),
|
|
761
|
-
});
|
|
762
|
-
const zeroJournalEntry = {
|
|
763
|
-
date: index_1._mockable.createNowTimestamp(),
|
|
764
|
-
ledgerEntries: [
|
|
765
|
-
{
|
|
766
|
-
account: "notStartedCount",
|
|
767
|
-
debit: 1,
|
|
768
|
-
credit: 1,
|
|
769
|
-
},
|
|
770
|
-
{
|
|
771
|
-
account: "inProgressCount",
|
|
772
|
-
debit: 1,
|
|
773
|
-
credit: 1,
|
|
774
|
-
},
|
|
775
|
-
],
|
|
776
|
-
equation: equation,
|
|
777
|
-
};
|
|
778
|
-
logicResults = [
|
|
779
|
-
{
|
|
780
|
-
name: "logic 1",
|
|
781
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
782
|
-
status: "finished",
|
|
783
|
-
documents: [
|
|
784
|
-
{ action: "merge", priority: "normal", dstPath: "path1/doc1", journalEntries: [zeroJournalEntry] },
|
|
785
|
-
],
|
|
786
|
-
},
|
|
787
|
-
];
|
|
788
|
-
await (0, index_1.onFormSubmit)(event);
|
|
789
|
-
expect(txnGetFnMock).toHaveBeenCalledTimes(3);
|
|
790
|
-
expect(txnGetFnMock).toHaveBeenCalledWith(docRef);
|
|
791
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(3);
|
|
792
|
-
expect(transactionUpdateMock).toHaveBeenCalledTimes(3);
|
|
793
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(1, docRef, { "@forDeletionLater": true });
|
|
794
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(2, docRef, { "@forDeletionLater": FieldValue.delete() });
|
|
795
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(3, docRef, { "@forDeletionLater": FieldValue.delete() });
|
|
796
|
-
distributionMock.mockRestore();
|
|
797
|
-
const errorMock = jest.spyOn(global, "Error").mockImplementation();
|
|
798
|
-
txnGetFnMock.mockRestore();
|
|
799
|
-
transactionSetMock.mockRestore();
|
|
800
|
-
transactionUpdateMock.mockRestore();
|
|
801
|
-
txnGetFnMock
|
|
802
|
-
.mockResolvedValueOnce({ data: () => (document) })
|
|
803
|
-
.mockResolvedValueOnce({ data: () => (user) })
|
|
804
|
-
.mockResolvedValueOnce({
|
|
805
|
-
data: () => ({
|
|
806
|
-
"totalTodos": 2,
|
|
807
|
-
"notStartedCount": 0,
|
|
808
|
-
"inProgressCount": 2,
|
|
809
|
-
}),
|
|
810
|
-
});
|
|
811
|
-
const changeStatusJournalEntry = {
|
|
812
|
-
date: index_1._mockable.createNowTimestamp(),
|
|
813
|
-
ledgerEntries: [
|
|
814
|
-
{
|
|
815
|
-
account: "notStartedCount",
|
|
816
|
-
debit: 1,
|
|
817
|
-
credit: 0,
|
|
818
|
-
},
|
|
819
|
-
{
|
|
820
|
-
account: "inProgressCount",
|
|
821
|
-
debit: 0,
|
|
822
|
-
credit: 1,
|
|
823
|
-
},
|
|
824
|
-
],
|
|
825
|
-
equation: equation,
|
|
826
|
-
};
|
|
827
|
-
logicResults = [
|
|
828
|
-
{
|
|
829
|
-
name: "logic 1",
|
|
830
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
831
|
-
status: "finished",
|
|
832
|
-
documents: [
|
|
833
|
-
{ action: "merge", priority: "normal", dstPath: "path1/doc1", journalEntries: [changeStatusJournalEntry] },
|
|
834
|
-
],
|
|
835
|
-
},
|
|
836
|
-
];
|
|
837
|
-
try {
|
|
838
|
-
await (0, index_1.onFormSubmit)(event);
|
|
839
|
-
}
|
|
840
|
-
catch (e) {
|
|
841
|
-
console.log("Expect this error");
|
|
842
|
-
}
|
|
843
|
-
expect(txnGetFnMock).toHaveBeenCalledTimes(3);
|
|
844
|
-
expect(txnGetFnMock).toHaveBeenCalledWith(docRef);
|
|
845
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(3);
|
|
846
|
-
expect(transactionUpdateMock).toHaveBeenCalledTimes(1);
|
|
847
|
-
expect(transactionUpdateMock).toHaveBeenCalledWith(docRef, { "@forDeletionLater": true });
|
|
848
|
-
expect(errorMock).toHaveBeenCalledTimes(1);
|
|
849
|
-
expect(errorMock).toHaveBeenCalledWith("Account value cannot be negative");
|
|
850
|
-
errorMock.mockRestore();
|
|
851
|
-
txnGetFnMock.mockRestore();
|
|
852
|
-
transactionSetMock.mockRestore();
|
|
853
|
-
transactionUpdateMock.mockRestore();
|
|
854
|
-
txnGetFnMock
|
|
855
|
-
.mockResolvedValueOnce({ data: () => (document) })
|
|
856
|
-
.mockResolvedValueOnce({ data: () => (user) })
|
|
857
|
-
.mockResolvedValueOnce({
|
|
858
|
-
data: () => ({
|
|
859
|
-
"totalTodos": 2,
|
|
860
|
-
"notStartedCount": 1,
|
|
861
|
-
"inProgressCount": 1,
|
|
862
|
-
"doneCount": 0,
|
|
863
|
-
}),
|
|
864
|
-
});
|
|
865
|
-
logicResults = [
|
|
866
|
-
{
|
|
867
|
-
name: "logic 1",
|
|
868
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
869
|
-
status: "finished",
|
|
870
|
-
documents: [
|
|
871
|
-
{ action: "merge", priority: "normal", dstPath: "path1/doc1", journalEntries: [recordedJournalEntry] },
|
|
872
|
-
],
|
|
873
|
-
},
|
|
874
|
-
];
|
|
875
|
-
await (0, index_1.onFormSubmit)(event);
|
|
876
|
-
expect(txnGetFnMock).toHaveBeenCalledTimes(3);
|
|
877
|
-
expect(txnGetFnMock).toHaveBeenCalledWith(docRef);
|
|
878
|
-
expect(transactionUpdateMock).toHaveBeenCalledTimes(3);
|
|
879
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(1, docRef, { "@forDeletionLater": true });
|
|
880
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(2, docRef, {
|
|
881
|
-
"inProgressCount": 0,
|
|
882
|
-
"@forDeletionLater": FieldValue.delete(),
|
|
883
|
-
});
|
|
884
|
-
expect(transactionUpdateMock).toHaveBeenNthCalledWith(3, docRef, {
|
|
885
|
-
"doneCount": 1,
|
|
886
|
-
"@forDeletionLater": FieldValue.delete(),
|
|
887
|
-
});
|
|
888
|
-
expect(transactionSetMock).toHaveBeenCalledTimes(5);
|
|
889
|
-
expect(transactionSetMock).toHaveBeenNthCalledWith(4, index_1.db.doc("path/doc1/@ledgers/doc100"), {
|
|
890
|
-
"journalEntryId": "doc10",
|
|
891
|
-
"account": "inProgressCount",
|
|
892
|
-
"debit": 1,
|
|
893
|
-
"credit": 0,
|
|
894
|
-
"date": expect.any(Timestamp),
|
|
895
|
-
"equation": equation,
|
|
896
|
-
});
|
|
897
|
-
expect(transactionSetMock).toHaveBeenNthCalledWith(5, index_1.db.doc("path/doc1/@ledgers/doc101"), {
|
|
898
|
-
"journalEntryId": "doc10",
|
|
899
|
-
"account": "doneCount",
|
|
900
|
-
"debit": 0,
|
|
901
|
-
"credit": 1,
|
|
902
|
-
"date": expect.any(Timestamp),
|
|
903
|
-
"equation": equation,
|
|
904
|
-
});
|
|
905
|
-
expect(queueRunViewLogicsSpy).toHaveBeenCalledTimes(1);
|
|
906
|
-
expect(queueRunViewLogicsSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, logicResults[0].documents[0]), { doc: {
|
|
907
|
-
inProgressCount: 0,
|
|
908
|
-
doneCount: 1,
|
|
909
|
-
} }));
|
|
910
|
-
}, 15000);
|
|
911
495
|
it("should execute the sequence of operations correctly", async () => {
|
|
912
496
|
refUpdateMock.mockRestore();
|
|
913
497
|
setMock.mockRestore();
|
|
@@ -917,7 +501,7 @@ describe("onFormSubmit", () => {
|
|
|
917
501
|
jest.spyOn(indexutils, "getFormModifiedFields").mockReturnValue({ "field1": "value1", "field2": "value2" });
|
|
918
502
|
jest.spyOn(indexutils, "getSecurityFn").mockReturnValue(() => Promise.resolve({ status: "allowed" }));
|
|
919
503
|
jest.spyOn(indexutils, "delayFormSubmissionAndCheckIfCancelled").mockResolvedValue(false);
|
|
920
|
-
jest.spyOn(indexutils, "distributeFnNonTransactional").mockResolvedValue();
|
|
504
|
+
jest.spyOn(indexutils, "distributeFnNonTransactional").mockResolvedValue([]);
|
|
921
505
|
jest.spyOn(indexutils, "distributeLater").mockResolvedValue();
|
|
922
506
|
jest.spyOn(viewLogics, "queueRunViewLogics").mockResolvedValue();
|
|
923
507
|
jest.spyOn(distribution, "convertInstructionsToDbValues").mockResolvedValue({
|
|
@@ -1023,37 +607,6 @@ describe("onFormSubmit", () => {
|
|
|
1023
607
|
priority: "low",
|
|
1024
608
|
},
|
|
1025
609
|
];
|
|
1026
|
-
const recordedJournalEntry = {
|
|
1027
|
-
date: index_1._mockable.createNowTimestamp(),
|
|
1028
|
-
ledgerEntries: [
|
|
1029
|
-
{
|
|
1030
|
-
account: "inProgressCount",
|
|
1031
|
-
debit: 1,
|
|
1032
|
-
credit: 0,
|
|
1033
|
-
},
|
|
1034
|
-
{
|
|
1035
|
-
account: "doneCount",
|
|
1036
|
-
debit: 0,
|
|
1037
|
-
credit: 1,
|
|
1038
|
-
},
|
|
1039
|
-
],
|
|
1040
|
-
equation: equation,
|
|
1041
|
-
recordEntry: true,
|
|
1042
|
-
};
|
|
1043
|
-
const journalDocs = [
|
|
1044
|
-
{
|
|
1045
|
-
action: "merge",
|
|
1046
|
-
priority: "normal",
|
|
1047
|
-
dstPath: "journal/doc1",
|
|
1048
|
-
journalEntries: [recordedJournalEntry, journalEntry],
|
|
1049
|
-
},
|
|
1050
|
-
{
|
|
1051
|
-
action: "merge",
|
|
1052
|
-
priority: "normal",
|
|
1053
|
-
dstPath: "journal/doc2",
|
|
1054
|
-
journalEntries: [journalEntry],
|
|
1055
|
-
},
|
|
1056
|
-
];
|
|
1057
610
|
const logicResults = [
|
|
1058
611
|
{
|
|
1059
612
|
name: "testLogic",
|
|
@@ -1071,12 +624,6 @@ describe("onFormSubmit", () => {
|
|
|
1071
624
|
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
1072
625
|
documents: [...transactionalDocs],
|
|
1073
626
|
transactional: true,
|
|
1074
|
-
}, {
|
|
1075
|
-
name: "journalLogic",
|
|
1076
|
-
status: "finished",
|
|
1077
|
-
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
1078
|
-
documents: [...journalDocs],
|
|
1079
|
-
transactional: true,
|
|
1080
627
|
},
|
|
1081
628
|
];
|
|
1082
629
|
const runBusinessLogicsSpy = jest.spyOn(indexutils, "runBusinessLogics").mockImplementation(async (txnGet, action) => {
|
|
@@ -1102,7 +649,6 @@ describe("onFormSubmit", () => {
|
|
|
1102
649
|
const lowPriorityDstPathLogicDocsMap = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(lowPriorityDocs);
|
|
1103
650
|
const { docsByDocPath: lowPriorityDocsByDocPath, otherDocsByDocPath: lowPriorityOtherDocsByDocPath, } = (0, index_utils_1.groupDocsByTargetDocPath)(lowPriorityDstPathLogicDocsMap, docPath);
|
|
1104
651
|
const transactionalDstPathLogicDocsMap = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(transactionalDocs);
|
|
1105
|
-
const journalDstPathLogicDocsMap = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(journalDocs);
|
|
1106
652
|
const viewLogicResults = [{
|
|
1107
653
|
name: "User ViewLogic",
|
|
1108
654
|
status: "finished",
|
|
@@ -1110,7 +656,6 @@ describe("onFormSubmit", () => {
|
|
|
1110
656
|
documents: logicResults.map((result) => result.documents).flat(),
|
|
1111
657
|
}];
|
|
1112
658
|
jest.spyOn(indexutils, "expandConsolidateAndGroupByDstPath")
|
|
1113
|
-
.mockResolvedValueOnce(journalDstPathLogicDocsMap)
|
|
1114
659
|
.mockResolvedValueOnce(transactionalDstPathLogicDocsMap)
|
|
1115
660
|
.mockResolvedValueOnce(highPriorityDstPathLogicDocsMap)
|
|
1116
661
|
.mockResolvedValueOnce(normalPriorityDstPathLogicDocsMap)
|
|
@@ -1139,26 +684,25 @@ describe("onFormSubmit", () => {
|
|
|
1139
684
|
expect(refMock.update).toHaveBeenNthCalledWith(2, { "@status": "submitted" });
|
|
1140
685
|
expect(refMock.update).toHaveBeenNthCalledWith(3, { "@status": "finished" });
|
|
1141
686
|
// Test that the functions are called in the correct sequence
|
|
1142
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(1, journalDocs);
|
|
1143
687
|
console.debug("set", transactionSetMock.mock.calls);
|
|
1144
688
|
console.debug("update", transactionUpdateMock.mock.calls);
|
|
1145
|
-
expect(transactionMock.set).toHaveBeenCalledTimes(
|
|
1146
|
-
expect(transactionMock.update).toHaveBeenCalledTimes(
|
|
1147
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(
|
|
689
|
+
expect(transactionMock.set).toHaveBeenCalledTimes(18);
|
|
690
|
+
expect(transactionMock.update).toHaveBeenCalledTimes(0);
|
|
691
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(1, transactionalDocs);
|
|
1148
692
|
expect(transactionMock.delete).toHaveBeenCalledTimes(1);
|
|
1149
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(
|
|
693
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(2, highPriorityDocs);
|
|
1150
694
|
expect(indexutils.groupDocsByTargetDocPath).toHaveBeenNthCalledWith(1, highPriorityDstPathLogicDocsMap, docPath);
|
|
1151
695
|
expect(indexutils.distributeFnNonTransactional).toHaveBeenNthCalledWith(1, highPriorityDocsByDocPath);
|
|
1152
696
|
expect(indexutils.distributeFnNonTransactional).toHaveBeenNthCalledWith(2, highPriorityOtherDocsByDocPath);
|
|
1153
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(
|
|
697
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(3, [...normalPriorityDocs, ...additionalNormalPriorityDocs]);
|
|
1154
698
|
expect(indexutils.groupDocsByTargetDocPath).toHaveBeenNthCalledWith(2, normalPriorityDstPathLogicDocsMap, docPath);
|
|
1155
699
|
expect(indexutils.distributeFnNonTransactional).toHaveBeenNthCalledWith(3, normalPriorityDocsByDocPath);
|
|
1156
700
|
expect(indexutils.distributeLater).toHaveBeenNthCalledWith(1, normalPriorityOtherDocsByDocPath);
|
|
1157
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(
|
|
701
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(4, lowPriorityDocs);
|
|
1158
702
|
expect(indexutils.groupDocsByTargetDocPath).toHaveBeenNthCalledWith(3, lowPriorityDstPathLogicDocsMap, docPath);
|
|
1159
703
|
expect(indexutils.distributeLater).toHaveBeenNthCalledWith(2, lowPriorityDocsByDocPath);
|
|
1160
704
|
expect(indexutils.distributeLater).toHaveBeenNthCalledWith(3, lowPriorityOtherDocsByDocPath);
|
|
1161
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenCalledTimes(
|
|
705
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenCalledTimes(4);
|
|
1162
706
|
expect(updateMock).toHaveBeenCalledTimes(1);
|
|
1163
707
|
expect(updateMock.mock.calls[0][0]).toEqual({
|
|
1164
708
|
execTime: expect.any(Number),
|