emberflow 1.3.76 → 1.3.78
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.js +6 -60
- package/lib/index-utils.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +116 -1
- package/lib/index.js.map +1 -1
- package/lib/tests/index-utils.test.js +0 -121
- package/lib/tests/index-utils.test.js.map +1 -1
- package/lib/tests/index.test.js +428 -13
- package/lib/tests/index.test.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +1 -1
package/lib/tests/index.test.js
CHANGED
|
@@ -34,6 +34,7 @@ const adminClient = __importStar(require("emberflow-admin-client/lib"));
|
|
|
34
34
|
var Timestamp = firebase_admin_1.firestore.Timestamp;
|
|
35
35
|
const index_utils_1 = require("../index-utils");
|
|
36
36
|
const distribution = __importStar(require("../utils/distribution"));
|
|
37
|
+
var FieldValue = firebase_admin_1.firestore.FieldValue;
|
|
37
38
|
const projectConfig = {
|
|
38
39
|
projectId: "your-project-id",
|
|
39
40
|
budgetAlertTopicName: "budget-alerts",
|
|
@@ -55,8 +56,9 @@ const getMock = {
|
|
|
55
56
|
data: dataMock,
|
|
56
57
|
};
|
|
57
58
|
const updateMock = jest.fn();
|
|
59
|
+
const setMock = jest.fn();
|
|
58
60
|
const docMock = {
|
|
59
|
-
set:
|
|
61
|
+
set: setMock,
|
|
60
62
|
get: jest.fn().mockResolvedValue(getMock),
|
|
61
63
|
update: updateMock,
|
|
62
64
|
collection: jest.fn(() => collectionMock),
|
|
@@ -64,9 +66,13 @@ const docMock = {
|
|
|
64
66
|
const collectionMock = {
|
|
65
67
|
doc: jest.fn(() => docMock),
|
|
66
68
|
};
|
|
69
|
+
const transactionGetMock = jest.fn();
|
|
70
|
+
const transactionSetMock = jest.fn();
|
|
71
|
+
const transactionUpdateMock = jest.fn();
|
|
67
72
|
const transactionMock = {
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
get: transactionGetMock,
|
|
74
|
+
set: transactionSetMock,
|
|
75
|
+
update: transactionUpdateMock,
|
|
70
76
|
delete: jest.fn(),
|
|
71
77
|
};
|
|
72
78
|
jest.spyOn(admin, "firestore")
|
|
@@ -85,8 +91,9 @@ jest.spyOn(admin, "database")
|
|
|
85
91
|
});
|
|
86
92
|
admin.initializeApp();
|
|
87
93
|
(0, index_1.initializeEmberFlow)(projectConfig, admin, db_structure_1.dbStructure, db_structure_1.Entity, {}, {}, []);
|
|
94
|
+
const refUpdateMock = jest.fn();
|
|
88
95
|
const refMock = {
|
|
89
|
-
update:
|
|
96
|
+
update: refUpdateMock,
|
|
90
97
|
};
|
|
91
98
|
function createDocumentSnapshot(form) {
|
|
92
99
|
return {
|
|
@@ -128,6 +135,41 @@ describe("onFormSubmit", () => {
|
|
|
128
135
|
nestedField2: "oldValue",
|
|
129
136
|
},
|
|
130
137
|
};
|
|
138
|
+
const equation = "totalTodos = notStartedCount + inProgressCount + toVerifyCount + requestChangesCount + doneCount";
|
|
139
|
+
const now = Timestamp.fromDate(new Date());
|
|
140
|
+
const journalEntry = {
|
|
141
|
+
date: now,
|
|
142
|
+
ledgerEntries: [
|
|
143
|
+
{
|
|
144
|
+
account: "totalTodos",
|
|
145
|
+
debit: 1,
|
|
146
|
+
credit: 0,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
account: "notStartedCount",
|
|
150
|
+
debit: 0,
|
|
151
|
+
credit: 1,
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
equation: equation,
|
|
155
|
+
};
|
|
156
|
+
const recordedJournalEntry = {
|
|
157
|
+
date: now,
|
|
158
|
+
ledgerEntries: [
|
|
159
|
+
{
|
|
160
|
+
account: "inProgressCount",
|
|
161
|
+
debit: 1,
|
|
162
|
+
credit: 0,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
account: "doneCount",
|
|
166
|
+
debit: 0,
|
|
167
|
+
credit: 1,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
equation: equation,
|
|
171
|
+
recordEntry: true,
|
|
172
|
+
};
|
|
131
173
|
beforeEach(() => {
|
|
132
174
|
jest.spyOn(index_1._mockable, "createNowTimestamp").mockReturnValue(Timestamp.now());
|
|
133
175
|
jest.spyOn(console, "log").mockImplementation();
|
|
@@ -138,6 +180,14 @@ describe("onFormSubmit", () => {
|
|
|
138
180
|
});
|
|
139
181
|
refMock.update.mockReset();
|
|
140
182
|
updateMock.mockReset();
|
|
183
|
+
transactionGetMock.mockResolvedValue({
|
|
184
|
+
data: () => ({
|
|
185
|
+
totalTodos: 3,
|
|
186
|
+
notStartedCount: 1,
|
|
187
|
+
inProgressCount: 1,
|
|
188
|
+
doneCount: 1,
|
|
189
|
+
}),
|
|
190
|
+
});
|
|
141
191
|
});
|
|
142
192
|
afterEach(() => {
|
|
143
193
|
jest.restoreAllMocks();
|
|
@@ -502,7 +552,330 @@ describe("onFormSubmit", () => {
|
|
|
502
552
|
docMock.set.mockReset();
|
|
503
553
|
docMock.update.mockReset();
|
|
504
554
|
});
|
|
555
|
+
it("should write journal entries first", async () => {
|
|
556
|
+
const consoleErrorSpy = jest.spyOn(console, "error").mockImplementation();
|
|
557
|
+
const consoleInfoSpy = jest.spyOn(console, "info").mockImplementation();
|
|
558
|
+
jest.spyOn(indexutils, "runBusinessLogics").mockImplementation(async (actionRef, action, distributeFn) => {
|
|
559
|
+
await distributeFn(actionRef, logicResults, 0);
|
|
560
|
+
return "done";
|
|
561
|
+
});
|
|
562
|
+
let logicResults = [
|
|
563
|
+
{
|
|
564
|
+
name: "logic 1",
|
|
565
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
566
|
+
status: "finished",
|
|
567
|
+
documents: [
|
|
568
|
+
{ action: "merge", priority: "normal", dstPath: "path1/doc1" },
|
|
569
|
+
],
|
|
570
|
+
},
|
|
571
|
+
];
|
|
572
|
+
const docPath = "users/user-1";
|
|
573
|
+
const form = {
|
|
574
|
+
"formData": JSON.stringify({
|
|
575
|
+
"@actionType": "create",
|
|
576
|
+
"name": "test",
|
|
577
|
+
"@docPath": docPath,
|
|
578
|
+
}),
|
|
579
|
+
"@status": "submit",
|
|
580
|
+
};
|
|
581
|
+
const event = createEvent(form);
|
|
582
|
+
await (0, index_1.onFormSubmit)(event);
|
|
583
|
+
expect(consoleInfoSpy).toHaveBeenCalledWith("No journal entries to write");
|
|
584
|
+
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
585
|
+
expect(transactionSetMock).not.toHaveBeenCalled();
|
|
586
|
+
expect(transactionGetMock).not.toHaveBeenCalled();
|
|
587
|
+
logicResults = [
|
|
588
|
+
{
|
|
589
|
+
name: "logic 1",
|
|
590
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
591
|
+
status: "finished",
|
|
592
|
+
documents: [
|
|
593
|
+
{ action: "merge", priority: "normal", dstPath: "", journalEntries: [journalEntry] },
|
|
594
|
+
],
|
|
595
|
+
},
|
|
596
|
+
];
|
|
597
|
+
await (0, index_1.onFormSubmit)(event);
|
|
598
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith("Dst path has no docId");
|
|
599
|
+
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
600
|
+
expect(transactionSetMock).not.toHaveBeenCalled();
|
|
601
|
+
expect(transactionGetMock).not.toHaveBeenCalled();
|
|
602
|
+
logicResults = [
|
|
603
|
+
{
|
|
604
|
+
name: "logic 1",
|
|
605
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
606
|
+
status: "finished",
|
|
607
|
+
documents: [
|
|
608
|
+
{ action: "merge", priority: "high", dstPath: "path1/doc5", doc: { totalTodos: 1 }, journalEntries: [journalEntry] },
|
|
609
|
+
],
|
|
610
|
+
},
|
|
611
|
+
];
|
|
612
|
+
await (0, index_1.onFormSubmit)(event);
|
|
613
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith("Doc cannot have keys that are the same as account names");
|
|
614
|
+
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
615
|
+
expect(transactionSetMock).not.toHaveBeenCalled();
|
|
616
|
+
expect(transactionGetMock).not.toHaveBeenCalled();
|
|
617
|
+
logicResults = [
|
|
618
|
+
{
|
|
619
|
+
name: "logic 1",
|
|
620
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
621
|
+
status: "finished",
|
|
622
|
+
documents: [
|
|
623
|
+
{ action: "merge", priority: "high", dstPath: "path1/doc5", instructions: { totalTodos: "+1" }, journalEntries: [journalEntry] },
|
|
624
|
+
],
|
|
625
|
+
},
|
|
626
|
+
];
|
|
627
|
+
await (0, index_1.onFormSubmit)(event);
|
|
628
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith("Instructions cannot have keys that are the same as account names");
|
|
629
|
+
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
630
|
+
expect(transactionSetMock).not.toHaveBeenCalled();
|
|
631
|
+
expect(transactionGetMock).not.toHaveBeenCalled();
|
|
632
|
+
const unbalancedJournalEntry = {
|
|
633
|
+
date: index_1._mockable.createNowTimestamp(),
|
|
634
|
+
ledgerEntries: [
|
|
635
|
+
{
|
|
636
|
+
account: "totalTodos",
|
|
637
|
+
debit: 1,
|
|
638
|
+
credit: 0,
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
account: "notStartedCount",
|
|
642
|
+
debit: 0,
|
|
643
|
+
credit: 1,
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
account: "inProgressCount",
|
|
647
|
+
debit: 0,
|
|
648
|
+
credit: 1,
|
|
649
|
+
},
|
|
650
|
+
],
|
|
651
|
+
equation: equation,
|
|
652
|
+
};
|
|
653
|
+
logicResults = [
|
|
654
|
+
{
|
|
655
|
+
name: "logic 1",
|
|
656
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
657
|
+
status: "finished",
|
|
658
|
+
documents: [
|
|
659
|
+
{ action: "merge", priority: "high", dstPath: "path1/doc5", journalEntries: [unbalancedJournalEntry] },
|
|
660
|
+
],
|
|
661
|
+
},
|
|
662
|
+
];
|
|
663
|
+
await (0, index_1.onFormSubmit)(event);
|
|
664
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith("Debit and credit should be equal");
|
|
665
|
+
expect(transactionUpdateMock).not.toHaveBeenCalled();
|
|
666
|
+
expect(transactionSetMock).not.toHaveBeenCalled();
|
|
667
|
+
expect(transactionGetMock).not.toHaveBeenCalled();
|
|
668
|
+
transactionGetMock.mockRestore();
|
|
669
|
+
transactionSetMock.mockRestore();
|
|
670
|
+
transactionUpdateMock.mockRestore();
|
|
671
|
+
transactionGetMock.mockResolvedValueOnce({
|
|
672
|
+
data: () => undefined,
|
|
673
|
+
});
|
|
674
|
+
const docRef = index_1.db.doc("path1/doc1");
|
|
675
|
+
logicResults = [
|
|
676
|
+
{
|
|
677
|
+
name: "logic 1",
|
|
678
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
679
|
+
status: "finished",
|
|
680
|
+
documents: [
|
|
681
|
+
{ action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field: "value" }, journalEntries: [journalEntry] },
|
|
682
|
+
],
|
|
683
|
+
},
|
|
684
|
+
];
|
|
685
|
+
await (0, index_1.onFormSubmit)(event);
|
|
686
|
+
expect(transactionGetMock).toHaveBeenCalledTimes(1);
|
|
687
|
+
expect(transactionGetMock).toHaveBeenCalledWith(docRef);
|
|
688
|
+
expect(transactionSetMock).toHaveBeenCalledTimes(1);
|
|
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
|
+
transactionGetMock.mockRestore();
|
|
700
|
+
transactionSetMock.mockRestore();
|
|
701
|
+
transactionUpdateMock.mockRestore();
|
|
702
|
+
transactionGetMock.mockResolvedValueOnce({
|
|
703
|
+
data: () => ({
|
|
704
|
+
"totalTodos": 1,
|
|
705
|
+
"notStartedCount": 1,
|
|
706
|
+
}),
|
|
707
|
+
});
|
|
708
|
+
logicResults = [
|
|
709
|
+
{
|
|
710
|
+
name: "logic 1",
|
|
711
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
712
|
+
status: "finished",
|
|
713
|
+
documents: [
|
|
714
|
+
{ action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field: "value" }, journalEntries: [journalEntry] },
|
|
715
|
+
],
|
|
716
|
+
},
|
|
717
|
+
];
|
|
718
|
+
await (0, index_1.onFormSubmit)(event);
|
|
719
|
+
expect(transactionGetMock).toHaveBeenCalledTimes(1);
|
|
720
|
+
expect(transactionGetMock).toHaveBeenCalledWith(docRef);
|
|
721
|
+
expect(transactionSetMock).not.toHaveBeenCalled();
|
|
722
|
+
expect(transactionUpdateMock).toHaveBeenCalledTimes(3);
|
|
723
|
+
expect(transactionUpdateMock).toHaveBeenNthCalledWith(1, docRef, { "field": "value", "@forDeletionLater": true });
|
|
724
|
+
expect(transactionUpdateMock).toHaveBeenNthCalledWith(2, docRef, {
|
|
725
|
+
"totalTodos": 2,
|
|
726
|
+
"@forDeletionLater": FieldValue.delete(),
|
|
727
|
+
});
|
|
728
|
+
expect(transactionUpdateMock).toHaveBeenNthCalledWith(3, docRef, {
|
|
729
|
+
"notStartedCount": 2,
|
|
730
|
+
"@forDeletionLater": FieldValue.delete(),
|
|
731
|
+
});
|
|
732
|
+
transactionGetMock.mockRestore();
|
|
733
|
+
transactionSetMock.mockRestore();
|
|
734
|
+
transactionUpdateMock.mockRestore();
|
|
735
|
+
transactionGetMock.mockResolvedValueOnce({
|
|
736
|
+
data: () => ({
|
|
737
|
+
"totalTodos": 2,
|
|
738
|
+
"notStartedCount": 0,
|
|
739
|
+
"inProgressCount": 2,
|
|
740
|
+
}),
|
|
741
|
+
});
|
|
742
|
+
const zeroJournalEntry = {
|
|
743
|
+
date: index_1._mockable.createNowTimestamp(),
|
|
744
|
+
ledgerEntries: [
|
|
745
|
+
{
|
|
746
|
+
account: "notStartedCount",
|
|
747
|
+
debit: 1,
|
|
748
|
+
credit: 1,
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
account: "inProgressCount",
|
|
752
|
+
debit: 1,
|
|
753
|
+
credit: 1,
|
|
754
|
+
},
|
|
755
|
+
],
|
|
756
|
+
equation: equation,
|
|
757
|
+
};
|
|
758
|
+
logicResults = [
|
|
759
|
+
{
|
|
760
|
+
name: "logic 1",
|
|
761
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
762
|
+
status: "finished",
|
|
763
|
+
documents: [
|
|
764
|
+
{ action: "merge", priority: "normal", dstPath: "path1/doc1", journalEntries: [zeroJournalEntry] },
|
|
765
|
+
],
|
|
766
|
+
},
|
|
767
|
+
];
|
|
768
|
+
await (0, index_1.onFormSubmit)(event);
|
|
769
|
+
expect(transactionGetMock).toHaveBeenCalledTimes(1);
|
|
770
|
+
expect(transactionGetMock).toHaveBeenCalledWith(docRef);
|
|
771
|
+
expect(transactionSetMock).not.toHaveBeenCalled();
|
|
772
|
+
expect(transactionUpdateMock).toHaveBeenCalledTimes(3);
|
|
773
|
+
expect(transactionUpdateMock).toHaveBeenNthCalledWith(1, docRef, { "@forDeletionLater": true });
|
|
774
|
+
expect(transactionUpdateMock).toHaveBeenNthCalledWith(2, docRef, { "@forDeletionLater": FieldValue.delete() });
|
|
775
|
+
expect(transactionUpdateMock).toHaveBeenNthCalledWith(3, docRef, { "@forDeletionLater": FieldValue.delete() });
|
|
776
|
+
const errorMock = jest.spyOn(global, "Error")
|
|
777
|
+
.mockImplementation();
|
|
778
|
+
transactionGetMock.mockRestore();
|
|
779
|
+
transactionSetMock.mockRestore();
|
|
780
|
+
transactionUpdateMock.mockRestore();
|
|
781
|
+
transactionGetMock.mockResolvedValueOnce({
|
|
782
|
+
data: () => ({
|
|
783
|
+
"totalTodos": 2,
|
|
784
|
+
"notStartedCount": 0,
|
|
785
|
+
"inProgressCount": 2,
|
|
786
|
+
}),
|
|
787
|
+
});
|
|
788
|
+
const changeStatusJournalEntry = {
|
|
789
|
+
date: index_1._mockable.createNowTimestamp(),
|
|
790
|
+
ledgerEntries: [
|
|
791
|
+
{
|
|
792
|
+
account: "notStartedCount",
|
|
793
|
+
debit: 1,
|
|
794
|
+
credit: 0,
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
account: "inProgressCount",
|
|
798
|
+
debit: 0,
|
|
799
|
+
credit: 1,
|
|
800
|
+
},
|
|
801
|
+
],
|
|
802
|
+
equation: equation,
|
|
803
|
+
};
|
|
804
|
+
logicResults = [
|
|
805
|
+
{
|
|
806
|
+
name: "logic 1",
|
|
807
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
808
|
+
status: "finished",
|
|
809
|
+
documents: [
|
|
810
|
+
{ action: "merge", priority: "normal", dstPath: "path1/doc1", journalEntries: [changeStatusJournalEntry] },
|
|
811
|
+
],
|
|
812
|
+
},
|
|
813
|
+
];
|
|
814
|
+
await (0, index_1.onFormSubmit)(event);
|
|
815
|
+
expect(transactionGetMock).toHaveBeenCalledTimes(1);
|
|
816
|
+
expect(transactionGetMock).toHaveBeenCalledWith(docRef);
|
|
817
|
+
expect(transactionSetMock).not.toHaveBeenCalled();
|
|
818
|
+
expect(transactionUpdateMock).toHaveBeenCalledTimes(1);
|
|
819
|
+
expect(transactionUpdateMock).toHaveBeenCalledWith(docRef, { "@forDeletionLater": true });
|
|
820
|
+
expect(errorMock).toHaveBeenCalledTimes(1);
|
|
821
|
+
expect(errorMock).toHaveBeenCalledWith("Account value cannot be negative");
|
|
822
|
+
transactionGetMock.mockRestore();
|
|
823
|
+
transactionSetMock.mockRestore();
|
|
824
|
+
transactionUpdateMock.mockRestore();
|
|
825
|
+
transactionGetMock.mockResolvedValueOnce({
|
|
826
|
+
data: () => ({
|
|
827
|
+
"totalTodos": 2,
|
|
828
|
+
"notStartedCount": 1,
|
|
829
|
+
"inProgressCount": 1,
|
|
830
|
+
"doneCount": 0,
|
|
831
|
+
}),
|
|
832
|
+
});
|
|
833
|
+
logicResults = [
|
|
834
|
+
{
|
|
835
|
+
name: "logic 1",
|
|
836
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
837
|
+
status: "finished",
|
|
838
|
+
documents: [
|
|
839
|
+
{ action: "merge", priority: "normal", dstPath: "path1/doc1", journalEntries: [recordedJournalEntry] },
|
|
840
|
+
],
|
|
841
|
+
},
|
|
842
|
+
];
|
|
843
|
+
await (0, index_1.onFormSubmit)(event);
|
|
844
|
+
expect(transactionGetMock).toHaveBeenCalledTimes(1);
|
|
845
|
+
expect(transactionGetMock).toHaveBeenCalledWith(docRef);
|
|
846
|
+
expect(transactionUpdateMock).toHaveBeenCalledTimes(3);
|
|
847
|
+
expect(transactionUpdateMock).toHaveBeenNthCalledWith(1, docRef, { "@forDeletionLater": true });
|
|
848
|
+
expect(transactionUpdateMock).toHaveBeenNthCalledWith(2, docRef, {
|
|
849
|
+
"inProgressCount": 0,
|
|
850
|
+
"@forDeletionLater": FieldValue.delete(),
|
|
851
|
+
});
|
|
852
|
+
expect(transactionUpdateMock).toHaveBeenNthCalledWith(3, docRef, {
|
|
853
|
+
"doneCount": 1,
|
|
854
|
+
"@forDeletionLater": FieldValue.delete(),
|
|
855
|
+
});
|
|
856
|
+
expect(transactionSetMock).toHaveBeenCalledTimes(2);
|
|
857
|
+
expect(transactionSetMock).toHaveBeenNthCalledWith(1, index_1.db.doc("path/doc1/@ledgers/doc100"), {
|
|
858
|
+
"journalEntryId": "doc10",
|
|
859
|
+
"account": "inProgressCount",
|
|
860
|
+
"debit": 1,
|
|
861
|
+
"credit": 0,
|
|
862
|
+
"date": expect.any(Timestamp),
|
|
863
|
+
"equation": equation,
|
|
864
|
+
});
|
|
865
|
+
expect(transactionSetMock).toHaveBeenNthCalledWith(2, index_1.db.doc("path/doc1/@ledgers/doc101"), {
|
|
866
|
+
"journalEntryId": "doc10",
|
|
867
|
+
"account": "doneCount",
|
|
868
|
+
"debit": 0,
|
|
869
|
+
"credit": 1,
|
|
870
|
+
"date": expect.any(Timestamp),
|
|
871
|
+
"equation": equation,
|
|
872
|
+
});
|
|
873
|
+
}, 10000);
|
|
505
874
|
it("should execute the sequence of operations correctly", async () => {
|
|
875
|
+
refUpdateMock.mockRestore();
|
|
876
|
+
setMock.mockRestore();
|
|
877
|
+
transactionSetMock.mockRestore();
|
|
878
|
+
transactionUpdateMock.mockRestore();
|
|
506
879
|
jest.spyOn(indexutils, "validateForm").mockResolvedValue([false, {}]);
|
|
507
880
|
jest.spyOn(indexutils, "getFormModifiedFields").mockReturnValue({ "field1": "value1", "field2": "value2" });
|
|
508
881
|
jest.spyOn(indexutils, "getSecurityFn").mockReturnValue(() => Promise.resolve({ status: "allowed" }));
|
|
@@ -512,7 +885,7 @@ describe("onFormSubmit", () => {
|
|
|
512
885
|
jest.spyOn(viewLogics, "queueRunViewLogics").mockResolvedValue();
|
|
513
886
|
jest.spyOn(distribution, "convertInstructionsToDbValues").mockReturnValue({
|
|
514
887
|
updateData: {
|
|
515
|
-
transactions:
|
|
888
|
+
transactions: FieldValue.increment(-1),
|
|
516
889
|
},
|
|
517
890
|
removeData: {},
|
|
518
891
|
});
|
|
@@ -613,6 +986,37 @@ describe("onFormSubmit", () => {
|
|
|
613
986
|
priority: "low",
|
|
614
987
|
},
|
|
615
988
|
];
|
|
989
|
+
const recordedJournalEntry = {
|
|
990
|
+
date: index_1._mockable.createNowTimestamp(),
|
|
991
|
+
ledgerEntries: [
|
|
992
|
+
{
|
|
993
|
+
account: "inProgressCount",
|
|
994
|
+
debit: 1,
|
|
995
|
+
credit: 0,
|
|
996
|
+
},
|
|
997
|
+
{
|
|
998
|
+
account: "doneCount",
|
|
999
|
+
debit: 0,
|
|
1000
|
+
credit: 1,
|
|
1001
|
+
},
|
|
1002
|
+
],
|
|
1003
|
+
equation: equation,
|
|
1004
|
+
recordEntry: true,
|
|
1005
|
+
};
|
|
1006
|
+
const journalDocs = [
|
|
1007
|
+
{
|
|
1008
|
+
action: "merge",
|
|
1009
|
+
priority: "normal",
|
|
1010
|
+
dstPath: "journal/doc1",
|
|
1011
|
+
journalEntries: [recordedJournalEntry, journalEntry],
|
|
1012
|
+
},
|
|
1013
|
+
{
|
|
1014
|
+
action: "merge",
|
|
1015
|
+
priority: "normal",
|
|
1016
|
+
dstPath: "journal/doc2",
|
|
1017
|
+
journalEntries: [journalEntry],
|
|
1018
|
+
},
|
|
1019
|
+
];
|
|
616
1020
|
const logicResults = [
|
|
617
1021
|
{
|
|
618
1022
|
name: "testLogic",
|
|
@@ -630,6 +1034,12 @@ describe("onFormSubmit", () => {
|
|
|
630
1034
|
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
631
1035
|
documents: [...transactionalDocs],
|
|
632
1036
|
transactional: true,
|
|
1037
|
+
}, {
|
|
1038
|
+
name: "journalLogic",
|
|
1039
|
+
status: "finished",
|
|
1040
|
+
timeFinished: index_1._mockable.createNowTimestamp(),
|
|
1041
|
+
documents: [...journalDocs],
|
|
1042
|
+
transactional: true,
|
|
633
1043
|
},
|
|
634
1044
|
];
|
|
635
1045
|
const runBusinessLogicsSpy = jest.spyOn(indexutils, "runBusinessLogics").mockImplementation(async (actionRef, action, distributeFn) => {
|
|
@@ -653,6 +1063,7 @@ describe("onFormSubmit", () => {
|
|
|
653
1063
|
const lowPriorityDstPathLogicDocsMap = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(lowPriorityDocs);
|
|
654
1064
|
const { docsByDocPath: lowPriorityDocsByDocPath, otherDocsByDocPath: lowPriorityOtherDocsByDocPath, } = (0, index_utils_1.groupDocsByTargetDocPath)(lowPriorityDstPathLogicDocsMap, docPath);
|
|
655
1065
|
const transactionalDstPathLogicDocsMap = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(transactionalDocs);
|
|
1066
|
+
const journalDstPathLogicDocsMap = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(journalDocs);
|
|
656
1067
|
const viewLogicResults = [{
|
|
657
1068
|
name: "User ViewLogic",
|
|
658
1069
|
status: "finished",
|
|
@@ -660,6 +1071,7 @@ describe("onFormSubmit", () => {
|
|
|
660
1071
|
documents: logicResults.map((result) => result.documents).flat(),
|
|
661
1072
|
}];
|
|
662
1073
|
jest.spyOn(indexutils, "expandConsolidateAndGroupByDstPath")
|
|
1074
|
+
.mockResolvedValueOnce(journalDstPathLogicDocsMap)
|
|
663
1075
|
.mockResolvedValueOnce(transactionalDstPathLogicDocsMap)
|
|
664
1076
|
.mockResolvedValueOnce(highPriorityDstPathLogicDocsMap)
|
|
665
1077
|
.mockResolvedValueOnce(normalPriorityDstPathLogicDocsMap)
|
|
@@ -683,29 +1095,32 @@ describe("onFormSubmit", () => {
|
|
|
683
1095
|
await (0, index_1.onFormSubmit)(event);
|
|
684
1096
|
// Test that the runBusinessLogics function was called with the correct parameters
|
|
685
1097
|
expect(runBusinessLogicsSpy).toHaveBeenCalled();
|
|
686
|
-
expect(
|
|
1098
|
+
expect(setMock).toHaveBeenCalledTimes(18);
|
|
687
1099
|
expect(refMock.update).toHaveBeenCalledTimes(3);
|
|
688
1100
|
expect(refMock.update).toHaveBeenNthCalledWith(1, { "@status": "processing" });
|
|
689
1101
|
expect(refMock.update).toHaveBeenNthCalledWith(2, { "@status": "submitted" });
|
|
690
1102
|
expect(refMock.update).toHaveBeenNthCalledWith(3, { "@status": "finished" });
|
|
691
1103
|
// Test that the functions are called in the correct sequence
|
|
692
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(1,
|
|
693
|
-
|
|
694
|
-
|
|
1104
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(1, journalDocs);
|
|
1105
|
+
console.debug("set", transactionSetMock.mock.calls);
|
|
1106
|
+
console.debug("update", transactionUpdateMock.mock.calls);
|
|
1107
|
+
expect(transactionMock.set).toHaveBeenCalledTimes(3);
|
|
1108
|
+
expect(transactionMock.update).toHaveBeenCalledTimes(11);
|
|
1109
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(2, transactionalDocs);
|
|
695
1110
|
expect(transactionMock.delete).toHaveBeenCalledTimes(1);
|
|
696
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(
|
|
1111
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(3, highPriorityDocs);
|
|
697
1112
|
expect(indexutils.groupDocsByTargetDocPath).toHaveBeenNthCalledWith(1, highPriorityDstPathLogicDocsMap, docPath);
|
|
698
1113
|
expect(indexutils.distribute).toHaveBeenNthCalledWith(1, highPriorityDocsByDocPath);
|
|
699
1114
|
expect(indexutils.distribute).toHaveBeenNthCalledWith(2, highPriorityOtherDocsByDocPath);
|
|
700
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(
|
|
1115
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(4, [...normalPriorityDocs, ...additionalNormalPriorityDocs]);
|
|
701
1116
|
expect(indexutils.groupDocsByTargetDocPath).toHaveBeenNthCalledWith(2, normalPriorityDstPathLogicDocsMap, docPath);
|
|
702
1117
|
expect(indexutils.distribute).toHaveBeenNthCalledWith(3, normalPriorityDocsByDocPath);
|
|
703
1118
|
expect(indexutils.distributeLater).toHaveBeenNthCalledWith(1, normalPriorityOtherDocsByDocPath);
|
|
704
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(
|
|
1119
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenNthCalledWith(5, lowPriorityDocs);
|
|
705
1120
|
expect(indexutils.groupDocsByTargetDocPath).toHaveBeenNthCalledWith(3, lowPriorityDstPathLogicDocsMap, docPath);
|
|
706
1121
|
expect(indexutils.distributeLater).toHaveBeenNthCalledWith(2, lowPriorityDocsByDocPath);
|
|
707
1122
|
expect(indexutils.distributeLater).toHaveBeenNthCalledWith(3, lowPriorityOtherDocsByDocPath);
|
|
708
|
-
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenCalledTimes(
|
|
1123
|
+
expect(indexutils.expandConsolidateAndGroupByDstPath).toHaveBeenCalledTimes(5);
|
|
709
1124
|
expect(updateMock).toHaveBeenCalledTimes(1);
|
|
710
1125
|
expect(updateMock.mock.calls[0][0]).toEqual({ status: "finished" });
|
|
711
1126
|
});
|