emberflow 1.3.7 → 1.3.9
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/db-structure.d.ts +2 -7
- package/lib/db-structure.js +1 -6
- package/lib/db-structure.js.map +1 -1
- package/lib/index-utils.d.ts +4 -3
- package/lib/index-utils.js +83 -118
- package/lib/index-utils.js.map +1 -1
- package/lib/index.d.ts +7 -0
- package/lib/index.js +70 -38
- package/lib/index.js.map +1 -1
- package/lib/logics/view-logics.d.ts +22 -2
- package/lib/logics/view-logics.js +107 -53
- package/lib/logics/view-logics.js.map +1 -1
- package/lib/tests/index-utils.test.js +233 -137
- package/lib/tests/index-utils.test.js.map +1 -1
- package/lib/tests/index.test.js +21 -17
- package/lib/tests/index.test.js.map +1 -1
- package/lib/tests/logics/view-logics.test.js +203 -24
- package/lib/tests/logics/view-logics.test.js.map +1 -1
- package/lib/tests/utils/distribution.test.d.ts +1 -0
- package/lib/tests/utils/distribution.test.js +206 -0
- package/lib/tests/utils/distribution.test.js.map +1 -0
- package/lib/tests/utils/forms.test.d.ts +1 -0
- package/lib/tests/utils/forms.test.js +113 -0
- package/lib/tests/utils/forms.test.js.map +1 -0
- package/lib/tests/utils/misc.test.js +138 -0
- package/lib/tests/utils/misc.test.js.map +1 -1
- package/lib/tests/utils/paths.test.js.map +1 -1
- package/lib/tests/utils/pubsub.test.d.ts +1 -0
- package/lib/tests/utils/pubsub.test.js +109 -0
- package/lib/tests/utils/pubsub.test.js.map +1 -0
- package/lib/types.d.ts +7 -1
- package/lib/utils/distribution.d.ts +9 -0
- package/lib/utils/distribution.js +119 -0
- package/lib/utils/distribution.js.map +1 -0
- package/lib/utils/forms.d.ts +4 -2
- package/lib/utils/forms.js +32 -101
- package/lib/utils/forms.js.map +1 -1
- package/lib/utils/misc.d.ts +17 -0
- package/lib/utils/misc.js +81 -1
- package/lib/utils/misc.js.map +1 -1
- package/lib/utils/pubsub.d.ts +9 -0
- package/lib/utils/pubsub.js +32 -0
- package/lib/utils/pubsub.js.map +1 -0
- package/package.json +3 -2
|
@@ -32,8 +32,9 @@ const security_1 = require("../sample-custom/security");
|
|
|
32
32
|
const validators_1 = require("../sample-custom/validators");
|
|
33
33
|
var Timestamp = firebase_admin_1.firestore.Timestamp;
|
|
34
34
|
const paths_1 = require("../utils/paths");
|
|
35
|
-
const adminClient = __importStar(require("emberflow-admin-client/lib"));
|
|
36
35
|
const batch_1 = require("../utils/batch");
|
|
36
|
+
const distribution = __importStar(require("../utils/distribution"));
|
|
37
|
+
const forms = __importStar(require("../utils/forms"));
|
|
37
38
|
jest.spyOn(console, "log").mockImplementation();
|
|
38
39
|
jest.spyOn(console, "info").mockImplementation();
|
|
39
40
|
const projectConfig = {
|
|
@@ -55,9 +56,123 @@ jest.mock("../utils/paths", () => {
|
|
|
55
56
|
const originalModule = jest.requireActual("../utils/paths");
|
|
56
57
|
return Object.assign(Object.assign({}, originalModule), { expandAndGroupDocPathsByEntity: jest.fn() });
|
|
57
58
|
});
|
|
59
|
+
describe("distributeDoc", () => {
|
|
60
|
+
let dbSpy;
|
|
61
|
+
let queueInstructionsSpy;
|
|
62
|
+
let docSetMock;
|
|
63
|
+
let docDeleteMock;
|
|
64
|
+
const batch = batch_1.BatchUtil.getInstance();
|
|
65
|
+
jest.spyOn(batch_1.BatchUtil, "getInstance").mockImplementation(() => batch);
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
docSetMock = jest.fn().mockResolvedValue({});
|
|
68
|
+
docDeleteMock = jest.fn().mockResolvedValue({});
|
|
69
|
+
const dbDoc = {
|
|
70
|
+
set: docSetMock,
|
|
71
|
+
delete: docDeleteMock,
|
|
72
|
+
id: "test-doc-id",
|
|
73
|
+
};
|
|
74
|
+
dbSpy = jest.spyOn(admin.firestore(), "doc").mockReturnValue(dbDoc);
|
|
75
|
+
queueInstructionsSpy = jest.spyOn(distribution, "queueInstructions").mockResolvedValue();
|
|
76
|
+
});
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
dbSpy.mockRestore();
|
|
79
|
+
queueInstructionsSpy.mockRestore();
|
|
80
|
+
});
|
|
81
|
+
it("should delete a document from dstPath", async () => {
|
|
82
|
+
const logicResultDoc = {
|
|
83
|
+
action: "delete",
|
|
84
|
+
priority: "normal",
|
|
85
|
+
dstPath: "/users/test-user-id/documents/test-doc-id",
|
|
86
|
+
};
|
|
87
|
+
await (0, index_utils_1.distributeDoc)(logicResultDoc);
|
|
88
|
+
expect(admin.firestore().doc).toHaveBeenCalledTimes(1);
|
|
89
|
+
expect(admin.firestore().doc).toHaveBeenCalledWith("/users/test-user-id/documents/test-doc-id");
|
|
90
|
+
expect(docDeleteMock).toHaveBeenCalledTimes(1);
|
|
91
|
+
expect(docDeleteMock).toHaveBeenCalled();
|
|
92
|
+
});
|
|
93
|
+
it("should delete documents in batch", async () => {
|
|
94
|
+
const batchDeleteSpy = jest.spyOn(batch, "deleteDoc").mockResolvedValue(undefined);
|
|
95
|
+
const logicResultDoc = {
|
|
96
|
+
action: "delete",
|
|
97
|
+
priority: "normal",
|
|
98
|
+
dstPath: "/users/test-user-id/documents/test-doc-id",
|
|
99
|
+
};
|
|
100
|
+
await (0, index_utils_1.distributeDoc)(logicResultDoc, batch);
|
|
101
|
+
expect(admin.firestore().doc).toHaveBeenCalledTimes(1);
|
|
102
|
+
expect(admin.firestore().doc).toHaveBeenCalledWith("/users/test-user-id/documents/test-doc-id");
|
|
103
|
+
expect(batchDeleteSpy).toHaveBeenCalledTimes(1);
|
|
104
|
+
batchDeleteSpy.mockRestore();
|
|
105
|
+
});
|
|
106
|
+
it("should merge a document to dstPath", async () => {
|
|
107
|
+
const logicResultDoc = {
|
|
108
|
+
action: "merge",
|
|
109
|
+
priority: "normal",
|
|
110
|
+
dstPath: "/users/test-user-id/documents/test-doc-id",
|
|
111
|
+
doc: { name: "test-doc-name-updated" },
|
|
112
|
+
};
|
|
113
|
+
const expectedData = Object.assign(Object.assign({}, logicResultDoc.doc), { "@id": "test-doc-id" });
|
|
114
|
+
await (0, index_utils_1.distributeDoc)(logicResultDoc);
|
|
115
|
+
expect(admin.firestore().doc).toHaveBeenCalledTimes(1);
|
|
116
|
+
expect(admin.firestore().doc).toHaveBeenCalledWith("/users/test-user-id/documents/test-doc-id");
|
|
117
|
+
expect(docSetMock).toHaveBeenCalledTimes(1);
|
|
118
|
+
expect(docSetMock).toHaveBeenCalledWith(expectedData, { merge: true });
|
|
119
|
+
});
|
|
120
|
+
it("should merge a document to dstPath and queue instructions", async () => {
|
|
121
|
+
const logicResultDoc = {
|
|
122
|
+
action: "merge",
|
|
123
|
+
priority: "normal",
|
|
124
|
+
doc: { name: "test-doc-name-updated" },
|
|
125
|
+
instructions: {
|
|
126
|
+
"count": "++",
|
|
127
|
+
"score": "+5",
|
|
128
|
+
"minusCount": "--",
|
|
129
|
+
"minusScore": "-3",
|
|
130
|
+
},
|
|
131
|
+
dstPath: "/users/test-user-id/documents/test-doc-id",
|
|
132
|
+
};
|
|
133
|
+
const expectedData = Object.assign(Object.assign({}, logicResultDoc.doc), { "@id": "test-doc-id" });
|
|
134
|
+
await (0, index_utils_1.distributeDoc)(logicResultDoc);
|
|
135
|
+
expect(admin.firestore().doc).toHaveBeenCalledTimes(1);
|
|
136
|
+
expect(admin.firestore().doc).toHaveBeenCalledWith("/users/test-user-id/documents/test-doc-id");
|
|
137
|
+
expect(queueInstructionsSpy).toHaveBeenCalledTimes(1);
|
|
138
|
+
expect(queueInstructionsSpy).toHaveBeenCalledWith("/users/test-user-id/documents/test-doc-id", logicResultDoc.instructions);
|
|
139
|
+
expect(docSetMock).toHaveBeenCalledTimes(1);
|
|
140
|
+
expect(docSetMock).toHaveBeenCalledWith(expectedData, { merge: true });
|
|
141
|
+
});
|
|
142
|
+
it("should merge documents in batch", async () => {
|
|
143
|
+
const batchSetSpy = jest.spyOn(batch, "set").mockResolvedValue(undefined);
|
|
144
|
+
const logicResultDoc = {
|
|
145
|
+
action: "merge",
|
|
146
|
+
priority: "normal",
|
|
147
|
+
dstPath: "/users/test-user-id/documents/test-doc-id",
|
|
148
|
+
};
|
|
149
|
+
await (0, index_utils_1.distributeDoc)(logicResultDoc, batch);
|
|
150
|
+
expect(admin.firestore().doc).toHaveBeenCalledTimes(1);
|
|
151
|
+
expect(admin.firestore().doc).toHaveBeenCalledWith("/users/test-user-id/documents/test-doc-id");
|
|
152
|
+
expect(batchSetSpy).toHaveBeenCalledTimes(1);
|
|
153
|
+
batchSetSpy.mockRestore();
|
|
154
|
+
});
|
|
155
|
+
it("should queue a document to submit form", async () => {
|
|
156
|
+
const queueSubmitFormSpy = jest.spyOn(forms, "queueSubmitForm").mockResolvedValue("test-message-id");
|
|
157
|
+
const logicResultDoc = {
|
|
158
|
+
action: "submit-form",
|
|
159
|
+
priority: "normal",
|
|
160
|
+
doc: { name: "test-doc-name-updated" },
|
|
161
|
+
dstPath: "/users/test-user-id/documents/test-doc-id",
|
|
162
|
+
};
|
|
163
|
+
const formData = Object.assign({ "@docPath": logicResultDoc.dstPath, "@actionType": "create" }, logicResultDoc.doc);
|
|
164
|
+
await (0, index_utils_1.distributeDoc)(logicResultDoc, batch);
|
|
165
|
+
expect(admin.firestore().doc).toHaveBeenCalledTimes(1);
|
|
166
|
+
expect(admin.firestore().doc).toHaveBeenCalledWith("/users/test-user-id/documents/test-doc-id");
|
|
167
|
+
expect(queueSubmitFormSpy).toHaveBeenCalledTimes(1);
|
|
168
|
+
expect(queueSubmitFormSpy).toHaveBeenCalledWith(formData);
|
|
169
|
+
queueSubmitFormSpy.mockRestore();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
58
172
|
describe("distribute", () => {
|
|
59
173
|
let dbSpy;
|
|
60
174
|
let colSpy;
|
|
175
|
+
let queueInstructionsSpy;
|
|
61
176
|
const batch = batch_1.BatchUtil.getInstance();
|
|
62
177
|
jest.spyOn(batch_1.BatchUtil, "getInstance").mockImplementation(() => batch);
|
|
63
178
|
beforeEach(() => {
|
|
@@ -65,17 +180,20 @@ describe("distribute", () => {
|
|
|
65
180
|
get: jest.fn().mockResolvedValue({ exists: true, data: () => ({}) }),
|
|
66
181
|
set: jest.fn().mockResolvedValue({}),
|
|
67
182
|
delete: jest.fn().mockResolvedValue({}),
|
|
183
|
+
id: "test-doc-id",
|
|
68
184
|
};
|
|
69
185
|
dbSpy = jest.spyOn(admin.firestore(), "doc").mockReturnValue(dbDoc);
|
|
70
186
|
colSpy = jest.spyOn(admin.firestore(), "collection").mockReturnValue({
|
|
71
187
|
doc: jest.fn(() => dbDoc),
|
|
72
188
|
});
|
|
189
|
+
queueInstructionsSpy = jest.spyOn(distribution, "queueInstructions").mockResolvedValue();
|
|
73
190
|
});
|
|
74
191
|
afterEach(() => {
|
|
75
192
|
dbSpy.mockRestore();
|
|
76
193
|
colSpy.mockRestore();
|
|
194
|
+
queueInstructionsSpy.mockRestore();
|
|
77
195
|
});
|
|
78
|
-
it("should merge a document to dstPath
|
|
196
|
+
it("should merge a document to dstPath and queue instructions", async () => {
|
|
79
197
|
const batchSetSpy = jest.spyOn(batch, "set").mockResolvedValue(undefined);
|
|
80
198
|
const userDocsByDstPath = new Map([[
|
|
81
199
|
"/users/test-user-id/documents/test-doc-id",
|
|
@@ -96,12 +214,16 @@ describe("distribute", () => {
|
|
|
96
214
|
await (0, index_utils_1.distribute)(userDocsByDstPath);
|
|
97
215
|
expect(admin.firestore().doc).toHaveBeenCalledTimes(1);
|
|
98
216
|
expect(admin.firestore().doc).toHaveBeenCalledWith("/users/test-user-id/documents/test-doc-id");
|
|
217
|
+
expect(queueInstructionsSpy).toHaveBeenCalledTimes(1);
|
|
218
|
+
expect(queueInstructionsSpy).toHaveBeenCalledWith("/users/test-user-id/documents/test-doc-id", {
|
|
219
|
+
"count": "++",
|
|
220
|
+
"score": "+5",
|
|
221
|
+
"minusCount": "--",
|
|
222
|
+
"minusScore": "-3",
|
|
223
|
+
});
|
|
99
224
|
expect(batchSetSpy.mock.calls[0][1]).toEqual({
|
|
225
|
+
"@id": "test-doc-id",
|
|
100
226
|
"name": "test-doc-name-updated",
|
|
101
|
-
"count": admin.firestore.FieldValue.increment(1),
|
|
102
|
-
"score": admin.firestore.FieldValue.increment(5),
|
|
103
|
-
"minusCount": admin.firestore.FieldValue.increment(-1),
|
|
104
|
-
"minusScore": admin.firestore.FieldValue.increment(-3),
|
|
105
227
|
});
|
|
106
228
|
expect(batchSetSpy).toHaveBeenCalledTimes(1);
|
|
107
229
|
batchSetSpy.mockRestore();
|
|
@@ -123,15 +245,15 @@ describe("distribute", () => {
|
|
|
123
245
|
});
|
|
124
246
|
});
|
|
125
247
|
describe("distributeLater", () => {
|
|
126
|
-
let
|
|
248
|
+
let queueForDistributionLaterSpy;
|
|
127
249
|
beforeEach(() => {
|
|
128
|
-
submitFormSpy = jest.spyOn(adminClient, "submitForm").mockImplementation();
|
|
129
250
|
(0, index_1.initializeEmberFlow)(projectConfig, admin, db_structure_1.dbStructure, db_structure_1.Entity, security_1.securityConfig, validators_1.validatorConfig, []);
|
|
251
|
+
queueForDistributionLaterSpy = jest.spyOn(distribution, "queueForDistributionLater").mockResolvedValue();
|
|
130
252
|
});
|
|
131
253
|
afterEach(() => {
|
|
132
|
-
|
|
254
|
+
queueForDistributionLaterSpy.mockRestore();
|
|
133
255
|
});
|
|
134
|
-
it("should
|
|
256
|
+
it("should queue docs for distribution later", async () => {
|
|
135
257
|
const doc1 = {
|
|
136
258
|
action: "merge",
|
|
137
259
|
priority: "normal",
|
|
@@ -140,36 +262,7 @@ describe("distributeLater", () => {
|
|
|
140
262
|
};
|
|
141
263
|
const doc2 = {
|
|
142
264
|
action: "merge",
|
|
143
|
-
priority: "
|
|
144
|
-
doc: { name: "test-doc-name-updated" },
|
|
145
|
-
dstPath: "/users/test-user-id/documents/doc2",
|
|
146
|
-
};
|
|
147
|
-
const usersDocsByDstPath = new Map([
|
|
148
|
-
["/users/test-user-id/documents/doc1", [doc1]],
|
|
149
|
-
["/users/test-user-id/documents/doc2", [doc2]],
|
|
150
|
-
]);
|
|
151
|
-
const formId = "formId";
|
|
152
|
-
await (0, index_utils_1.distributeLater)(usersDocsByDstPath, formId);
|
|
153
|
-
expect(submitFormSpy).toHaveBeenCalledTimes(1);
|
|
154
|
-
expect(submitFormSpy.mock.calls[0][0]).toEqual({
|
|
155
|
-
"@docPath": `@internal/forDistribution/distributions/${formId}`,
|
|
156
|
-
"@actionType": "create",
|
|
157
|
-
"logicResultDocs": [
|
|
158
|
-
Object.assign(Object.assign({}, doc1), { priority: "high" }),
|
|
159
|
-
Object.assign(Object.assign({}, doc2), { priority: "high" }),
|
|
160
|
-
],
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
it("should update docs priority from low to normal and submit form for later", async () => {
|
|
164
|
-
const doc1 = {
|
|
165
|
-
action: "merge",
|
|
166
|
-
priority: "low",
|
|
167
|
-
doc: { name: "test-doc-name-updated" },
|
|
168
|
-
dstPath: "/users/test-user-id/documents/doc1",
|
|
169
|
-
};
|
|
170
|
-
const doc2 = {
|
|
171
|
-
action: "merge",
|
|
172
|
-
priority: "low",
|
|
265
|
+
priority: "high",
|
|
173
266
|
doc: { name: "test-doc-name-updated" },
|
|
174
267
|
dstPath: "/users/test-user-id/documents/doc2",
|
|
175
268
|
};
|
|
@@ -177,17 +270,9 @@ describe("distributeLater", () => {
|
|
|
177
270
|
["/users/test-user-id/documents/doc1", [doc1]],
|
|
178
271
|
["/users/test-user-id/documents/doc2", [doc2]],
|
|
179
272
|
]);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
expect(
|
|
183
|
-
expect(submitFormSpy.mock.calls[0][0]).toEqual({
|
|
184
|
-
"@docPath": `@internal/forDistribution/distributions/${formId}`,
|
|
185
|
-
"@actionType": "create",
|
|
186
|
-
"logicResultDocs": [
|
|
187
|
-
Object.assign(Object.assign({}, doc1), { priority: "normal" }),
|
|
188
|
-
Object.assign(Object.assign({}, doc2), { priority: "normal" }),
|
|
189
|
-
],
|
|
190
|
-
});
|
|
273
|
+
await (0, index_utils_1.distributeLater)(usersDocsByDstPath);
|
|
274
|
+
expect(queueForDistributionLaterSpy).toHaveBeenCalledTimes(1);
|
|
275
|
+
expect(queueForDistributionLaterSpy).toHaveBeenCalledWith(doc1, doc2);
|
|
191
276
|
});
|
|
192
277
|
});
|
|
193
278
|
describe("validateForm", () => {
|
|
@@ -481,13 +566,13 @@ describe("groupDocsByUserAndDstPath", () => {
|
|
|
481
566
|
const userId = "user123";
|
|
482
567
|
const expectedResults = {
|
|
483
568
|
userDocsByDstPath: new Map([
|
|
484
|
-
["users/user123/document1", { action: "merge", priority: "normal", dstPath: "users/user123/document1", doc: { field1: "value1", field2: "value2" } }],
|
|
485
|
-
["users/user123/document2", { action: "merge", priority: "normal", dstPath: "users/user123/document2", doc: { field3: "value3", field6: "value6" } }],
|
|
569
|
+
["users/user123/document1", [{ action: "merge", priority: "normal", dstPath: "users/user123/document1", doc: { field1: "value1", field2: "value2" } }]],
|
|
570
|
+
["users/user123/document2", [{ action: "merge", priority: "normal", dstPath: "users/user123/document2", doc: { field3: "value3", field6: "value6" } }]],
|
|
486
571
|
]),
|
|
487
572
|
otherUsersDocsByDstPath: new Map([
|
|
488
|
-
["users/user456/document3", { action: "merge", priority: "normal", dstPath: "users/user456/document3", doc: { field4: "value4" } }],
|
|
489
|
-
["users/user789/document4", { action: "delete", priority: "normal", dstPath: "users/user789/document4" }],
|
|
490
|
-
["othercollection/document5", { action: "merge", priority: "normal", dstPath: "othercollection/document5", doc: { field5: "value5" } }],
|
|
573
|
+
["users/user456/document3", [{ action: "merge", priority: "normal", dstPath: "users/user456/document3", doc: { field4: "value4" } }]],
|
|
574
|
+
["users/user789/document4", [{ action: "delete", priority: "normal", dstPath: "users/user789/document4" }]],
|
|
575
|
+
["othercollection/document5", [{ action: "merge", priority: "normal", dstPath: "othercollection/document5", doc: { field5: "value5" } }]],
|
|
491
576
|
]),
|
|
492
577
|
};
|
|
493
578
|
const results = (0, index_utils_1.groupDocsByUserAndDstPath)(docsByDstPath, userId);
|
|
@@ -555,8 +640,10 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
555
640
|
timeFinished: firebase_admin_1.firestore.Timestamp.now(),
|
|
556
641
|
status: "finished",
|
|
557
642
|
documents: [
|
|
643
|
+
{ action: "create", priority: "normal", dstPath: "path8/doc8", doc: { field1: "value1" }, instructions: {} },
|
|
558
644
|
{ action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1" }, instructions: { field2: "++" } },
|
|
559
645
|
{ action: "delete", priority: "normal", dstPath: "path2/doc2" },
|
|
646
|
+
{ action: "merge", priority: "normal", dstPath: "path11/doc11", doc: { field3: "value3" } },
|
|
560
647
|
],
|
|
561
648
|
},
|
|
562
649
|
{
|
|
@@ -564,11 +651,13 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
564
651
|
timeFinished: firebase_admin_1.firestore.Timestamp.now(),
|
|
565
652
|
status: "finished",
|
|
566
653
|
documents: [
|
|
654
|
+
{ action: "merge", priority: "normal", dstPath: "path8/doc8", doc: { field3: "value3" }, instructions: { field4: "--" } },
|
|
567
655
|
{ action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1a" }, instructions: { field2: "--" } },
|
|
568
656
|
{ action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field3: "value3" }, instructions: { field4: "--" } },
|
|
569
657
|
{ action: "copy", priority: "normal", srcPath: "path3/doc3", dstPath: "path4/doc4" },
|
|
570
658
|
{ action: "merge", priority: "normal", dstPath: "path2/doc2", doc: { field4: "value4" } },
|
|
571
659
|
{ action: "merge", priority: "normal", dstPath: "path7/doc7", doc: { field6: "value7" } },
|
|
660
|
+
{ action: "create", priority: "normal", dstPath: "path10/doc10", doc: { field10: "value10" }, instructions: { field6: "++" } },
|
|
572
661
|
],
|
|
573
662
|
},
|
|
574
663
|
{
|
|
@@ -580,6 +669,8 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
580
669
|
{ action: "delete", priority: "normal", dstPath: "path7/doc7" },
|
|
581
670
|
{ action: "delete", priority: "normal", dstPath: "path7/doc7" },
|
|
582
671
|
{ action: "copy", priority: "normal", srcPath: "path3/doc3", dstPath: "path4/doc4" },
|
|
672
|
+
{ action: "create", priority: "normal", dstPath: "path9/doc9", instructions: { field4: "++" } },
|
|
673
|
+
{ action: "create", priority: "normal", dstPath: "path10/doc10", instructions: { field3: "--" } },
|
|
583
674
|
],
|
|
584
675
|
},
|
|
585
676
|
{
|
|
@@ -589,6 +680,8 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
589
680
|
documents: [
|
|
590
681
|
{ action: "delete", priority: "normal", dstPath: "path2/doc2" },
|
|
591
682
|
{ action: "copy", priority: "normal", srcPath: "path3/doc3", dstPath: "path7/doc7" },
|
|
683
|
+
{ action: "merge", priority: "normal", dstPath: "path9/doc9", doc: { field9: "value9" } },
|
|
684
|
+
{ action: "merge", priority: "normal", dstPath: "path11/doc11", doc: { field1: "value1" }, instructions: { field6: "++" } },
|
|
592
685
|
],
|
|
593
686
|
},
|
|
594
687
|
];
|
|
@@ -597,11 +690,15 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
597
690
|
const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResultDocs);
|
|
598
691
|
// Assert
|
|
599
692
|
const expectedResult = new Map([
|
|
600
|
-
["path1/doc1", { action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1a", field3: "value3" }, instructions: { field2: "--", field4: "--" } }],
|
|
601
|
-
["path2/doc2", { action: "delete", priority: "normal", dstPath: "path2/doc2" }],
|
|
602
|
-
["path4/doc4", { action: "merge", priority: "normal", dstPath: "path4/doc4", doc: {}, instructions: {} }],
|
|
603
|
-
["
|
|
604
|
-
["
|
|
693
|
+
["path1/doc1", [{ action: "merge", priority: "normal", dstPath: "path1/doc1", doc: { field1: "value1a", field3: "value3" }, instructions: { field2: "--", field4: "--" } }]],
|
|
694
|
+
["path2/doc2", [{ action: "delete", priority: "normal", dstPath: "path2/doc2" }]],
|
|
695
|
+
["path4/doc4", [{ action: "merge", priority: "normal", dstPath: "path4/doc4", doc: {}, instructions: {} }]],
|
|
696
|
+
["path7/doc7", [{ action: "delete", priority: "normal", dstPath: "path7/doc7" }]],
|
|
697
|
+
["path6/doc6", [{ action: "merge", priority: "normal", dstPath: "path6/doc6", doc: {} }]],
|
|
698
|
+
["path8/doc8", [{ action: "create", priority: "normal", dstPath: "path8/doc8", doc: { field1: "value1", field3: "value3" }, instructions: { field4: "--" } }]],
|
|
699
|
+
["path9/doc9", [{ action: "create", priority: "normal", dstPath: "path9/doc9", doc: { field9: "value9" }, instructions: { field4: "++" } }]],
|
|
700
|
+
["path10/doc10", [{ action: "create", priority: "normal", dstPath: "path10/doc10", doc: { field10: "value10" }, instructions: { field3: "--", field6: "++" } }]],
|
|
701
|
+
["path11/doc11", [{ action: "merge", priority: "normal", dstPath: "path11/doc11", doc: { field3: "value3", field1: "value1" }, instructions: { field6: "++" } }]],
|
|
605
702
|
]);
|
|
606
703
|
expect(result).toEqual(expectedResult);
|
|
607
704
|
// Verify that console.warn was called
|
|
@@ -609,11 +706,11 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
609
706
|
// Verify that console.warn was called with the correct message
|
|
610
707
|
expect(consoleWarnSpy.mock.calls[0][0]).toBe("Overwriting key \"field1\" in doc for dstPath \"path1/doc1\"");
|
|
611
708
|
expect(consoleWarnSpy.mock.calls[1][0]).toBe("Overwriting key \"field2\" in instructions for dstPath \"path1/doc1\"");
|
|
612
|
-
expect(consoleWarnSpy.mock.calls[2][0]).toBe("Action
|
|
613
|
-
expect(consoleWarnSpy.mock.calls[3][0]).toBe("Action
|
|
614
|
-
expect(consoleWarnSpy.mock.calls[4][0]).toBe("Action
|
|
615
|
-
expect(consoleWarnSpy.mock.calls[5][0]).toBe("Action
|
|
616
|
-
expect(consoleWarnSpy.mock.calls[6][0]).toBe("Action
|
|
709
|
+
expect(consoleWarnSpy.mock.calls[2][0]).toBe("Action merge ignored because a \"delete\" for dstPath \"path2/doc2\" already exists");
|
|
710
|
+
expect(consoleWarnSpy.mock.calls[3][0]).toBe("Action merge for dstPath \"path7/doc7\" is being overwritten by action \"delete\"");
|
|
711
|
+
expect(consoleWarnSpy.mock.calls[4][0]).toBe("Action delete for dstPath \"path7/doc7\" is being overwritten by action \"delete\"");
|
|
712
|
+
expect(consoleWarnSpy.mock.calls[5][0]).toBe("Action delete for dstPath \"path2/doc2\" is being overwritten by action \"delete\"");
|
|
713
|
+
expect(consoleWarnSpy.mock.calls[6][0]).toBe("Action merge ignored because a \"delete\" for dstPath \"path7/doc7\" already exists");
|
|
617
714
|
});
|
|
618
715
|
it("should expand recursive-copy logic results documents to merge logic results", async () => {
|
|
619
716
|
const logicResults = [
|
|
@@ -639,31 +736,31 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
639
736
|
const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResultDocs);
|
|
640
737
|
// Assert
|
|
641
738
|
const expectedResult = new Map([
|
|
642
|
-
["path1/doc1", {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
["users/456/friends/123", {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
["users/456/friends/123/games/1", {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
["users/456/friends/123/games/2", {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
739
|
+
["path1/doc1", [{
|
|
740
|
+
action: "merge",
|
|
741
|
+
priority: "normal",
|
|
742
|
+
dstPath: "path1/doc1",
|
|
743
|
+
doc: { field1: "value1a" },
|
|
744
|
+
instructions: { field2: "--" },
|
|
745
|
+
}]],
|
|
746
|
+
["users/456/friends/123", [{
|
|
747
|
+
action: "merge",
|
|
748
|
+
priority: "normal",
|
|
749
|
+
doc: friend,
|
|
750
|
+
dstPath: "users/456/friends/123",
|
|
751
|
+
}]],
|
|
752
|
+
["users/456/friends/123/games/1", [{
|
|
753
|
+
action: "merge",
|
|
754
|
+
priority: "normal",
|
|
755
|
+
doc: games[0],
|
|
756
|
+
dstPath: "users/456/friends/123/games/1",
|
|
757
|
+
}]],
|
|
758
|
+
["users/456/friends/123/games/2", [{
|
|
759
|
+
action: "merge",
|
|
760
|
+
priority: "normal",
|
|
761
|
+
doc: games[1],
|
|
762
|
+
dstPath: "users/456/friends/123/games/2",
|
|
763
|
+
}]],
|
|
667
764
|
]);
|
|
668
765
|
// Checks if "recursive-copy" is removed from the logic results
|
|
669
766
|
expect([...result.values()].every((logicResultDocs) => logicResultDocs.every((doc) => doc.action !== "recursive-copy")))
|
|
@@ -702,28 +799,28 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
702
799
|
const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResultDocs);
|
|
703
800
|
// Assert
|
|
704
801
|
const expectedResult = new Map([
|
|
705
|
-
["path1/doc1", {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
["users/123/friends/123", {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
["users/123/friends/123/games/1", {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
["users/123/friends/123/games/2", {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
802
|
+
["path1/doc1", [{
|
|
803
|
+
action: "merge",
|
|
804
|
+
priority: "normal",
|
|
805
|
+
dstPath: "path1/doc1",
|
|
806
|
+
doc: { field1: "value1a" },
|
|
807
|
+
instructions: { field2: "--" },
|
|
808
|
+
}]],
|
|
809
|
+
["users/123/friends/123", [{
|
|
810
|
+
action: "delete",
|
|
811
|
+
priority: "normal",
|
|
812
|
+
dstPath: "users/123/friends/123",
|
|
813
|
+
}]],
|
|
814
|
+
["users/123/friends/123/games/1", [{
|
|
815
|
+
action: "delete",
|
|
816
|
+
priority: "normal",
|
|
817
|
+
dstPath: "users/123/friends/123/games/1",
|
|
818
|
+
}]],
|
|
819
|
+
["users/123/friends/123/games/2", [{
|
|
820
|
+
action: "delete",
|
|
821
|
+
priority: "normal",
|
|
822
|
+
dstPath: "users/123/friends/123/games/2",
|
|
823
|
+
}]],
|
|
727
824
|
]);
|
|
728
825
|
// Checks if "recursive-delete" is removed from the logic results
|
|
729
826
|
expect([...result.values()].every((logicResultDocs) => logicResultDocs.every((doc) => doc.action !== "recursive-delete")))
|
|
@@ -731,7 +828,7 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
731
828
|
expect(result).toEqual(expectedResult);
|
|
732
829
|
// Verify that console.warn was called
|
|
733
830
|
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
|
|
734
|
-
expect(consoleWarnSpy.mock.calls[0][0]).toBe("Action
|
|
831
|
+
expect(consoleWarnSpy.mock.calls[0][0]).toBe("Action merge ignored because a \"delete\" for dstPath \"users/123/friends/123\" already exists");
|
|
735
832
|
});
|
|
736
833
|
it("should convert copy logic results documents to merge logic results", async () => {
|
|
737
834
|
const logicResults = [
|
|
@@ -758,25 +855,25 @@ describe("expandConsolidateAndGroupByDstPath", () => {
|
|
|
758
855
|
const result = await (0, index_utils_1.expandConsolidateAndGroupByDstPath)(logicResultDocs);
|
|
759
856
|
// Assert
|
|
760
857
|
const expectedResult = new Map([
|
|
761
|
-
["path1/doc1", {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
["users/456/friends/123/games/1", {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
["users/456/friends/123/games/2", {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
858
|
+
["path1/doc1", [{
|
|
859
|
+
action: "merge",
|
|
860
|
+
priority: "normal",
|
|
861
|
+
dstPath: "path1/doc1",
|
|
862
|
+
doc: { field1: "value1a" },
|
|
863
|
+
instructions: { field2: "--" },
|
|
864
|
+
}]],
|
|
865
|
+
["users/456/friends/123/games/1", [{
|
|
866
|
+
action: "merge",
|
|
867
|
+
priority: "normal",
|
|
868
|
+
doc: games[0],
|
|
869
|
+
dstPath: "users/456/friends/123/games/1",
|
|
870
|
+
}]],
|
|
871
|
+
["users/456/friends/123/games/2", [{
|
|
872
|
+
action: "merge",
|
|
873
|
+
priority: "normal",
|
|
874
|
+
doc: games[1],
|
|
875
|
+
dstPath: "users/456/friends/123/games/2",
|
|
876
|
+
}]],
|
|
780
877
|
]);
|
|
781
878
|
// Checks if "copy" is removed from the logic results
|
|
782
879
|
expect([...result.values()].every((logicResultDocs) => logicResultDocs.every((doc) => doc.action !== "copy")))
|
|
@@ -806,7 +903,6 @@ describe("runViewLogics", () => {
|
|
|
806
903
|
jest.spyOn(index_utils_1._mockable, "getViewLogicsConfig").mockReturnValue(customViewLogicsConfig);
|
|
807
904
|
});
|
|
808
905
|
it("should run view logics properly", async () => {
|
|
809
|
-
const dstPathLogicDocsMap = new Map();
|
|
810
906
|
const logicResult1 = {
|
|
811
907
|
action: "merge",
|
|
812
908
|
priority: "normal",
|
|
@@ -818,11 +914,11 @@ describe("runViewLogics", () => {
|
|
|
818
914
|
priority: "normal",
|
|
819
915
|
dstPath: "users/user124",
|
|
820
916
|
};
|
|
821
|
-
dstPathLogicDocsMap.set(logicResult1.dstPath, logicResult1);
|
|
822
|
-
dstPathLogicDocsMap.set(logicResult2.dstPath, logicResult2);
|
|
823
917
|
viewLogicFn1.mockResolvedValue({});
|
|
824
918
|
viewLogicFn2.mockResolvedValue({});
|
|
825
|
-
const
|
|
919
|
+
const results1 = await (0, index_utils_1.runViewLogics)(logicResult1);
|
|
920
|
+
const results2 = await (0, index_utils_1.runViewLogics)(logicResult2);
|
|
921
|
+
const results = [...results1, ...results2];
|
|
826
922
|
expect(viewLogicFn1).toHaveBeenCalledTimes(2);
|
|
827
923
|
expect(viewLogicFn1.mock.calls[0][0]).toBe(logicResult1);
|
|
828
924
|
expect(viewLogicFn1.mock.calls[1][0]).toBe(logicResult2);
|