not-node 5.1.44 → 5.1.45

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.
@@ -0,0 +1,422 @@
1
+ require("not-log")(false);
2
+
3
+ const expect = require("chai").expect,
4
+ notManifestRouteResultFilter = require("../src/manifest/result.filter.js");
5
+
6
+ describe("notManifestRouteResultFilter", function () {
7
+ describe("filter", function () {
8
+ it("result is not an object", function () {
9
+ const reqRes = undefined;
10
+ notManifestRouteResultFilter.filter({}, reqRes);
11
+ expect(reqRes).to.be.undefined;
12
+ });
13
+
14
+ it("filtering rule is undefined", function () {
15
+ const reqRes = { some: "data" };
16
+ const notRouteData = {};
17
+ notManifestRouteResultFilter.filter(notRouteData, reqRes);
18
+ expect(reqRes).to.be.deep.equal({ some: "data" });
19
+ });
20
+
21
+ it("filtering target is undefined", function () {
22
+ const reqRes = { some: "data" };
23
+ const notRouteData = {
24
+ rule: { returnRoot: "result", return: ["some"] },
25
+ };
26
+ notManifestRouteResultFilter.filter(notRouteData, reqRes);
27
+ expect(reqRes).to.be.deep.equal({ some: "data" });
28
+ });
29
+
30
+ it("all params ok", function () {
31
+ const reqRes = { some: "data", error: false };
32
+ const notRouteData = {
33
+ rule: { return: ["some"] },
34
+ };
35
+ notManifestRouteResultFilter.filter(notRouteData, reqRes);
36
+ expect(reqRes).to.be.deep.equal({ some: "data" });
37
+ });
38
+ });
39
+
40
+ describe("filterByRule", function () {
41
+ it("target undefined", function () {
42
+ const reqRes = undefined;
43
+ const rule = ["result"];
44
+ notManifestRouteResultFilter.filterByRule(reqRes, rule);
45
+ expect(reqRes).to.be.undefined;
46
+ });
47
+
48
+ it("rule undefined", function () {
49
+ const reqRes = { some: "data" };
50
+ const rule = undefined;
51
+ notManifestRouteResultFilter.filterByRule(reqRes, rule);
52
+ expect(reqRes).to.be.deep.equal({ some: "data" });
53
+ });
54
+
55
+ it("rule is not object or array", function () {
56
+ const reqRes = { some: "data" };
57
+ const rule = 1;
58
+ notManifestRouteResultFilter.filterByRule(reqRes, rule);
59
+ expect(reqRes).to.be.deep.equal({ some: "data" });
60
+ });
61
+ });
62
+
63
+ describe("filterByMapRule", function () {
64
+ it("strict", function () {
65
+ const reqRes = {
66
+ prop1: "1",
67
+ prop2: {
68
+ sub: {
69
+ prop: {
70
+ id: 1,
71
+ name: "locale",
72
+ },
73
+ looser: "bummer",
74
+ },
75
+ stratification: true,
76
+ },
77
+ prop3: {
78
+ list: [
79
+ {
80
+ sub: {
81
+ id: 1,
82
+ name: "1",
83
+ },
84
+ },
85
+ ],
86
+ },
87
+ prop4: {
88
+ delta: [
89
+ { id: 1, name: "test" },
90
+ { id: 2, name: "test" },
91
+ { id: 3, name: "test" },
92
+ ],
93
+ },
94
+ };
95
+ const rule = {
96
+ prop1: true,
97
+ "prop2.sub.prop": ["name"],
98
+ "prop3.list": { sub: ["name"] },
99
+ "prop4.delta": ["name"],
100
+ };
101
+ const expected = {
102
+ prop1: "1",
103
+ prop2: {
104
+ sub: {
105
+ prop: {
106
+ name: "locale",
107
+ },
108
+ },
109
+ },
110
+ prop3: {
111
+ list: [
112
+ {
113
+ sub: {
114
+ name: "1",
115
+ },
116
+ },
117
+ ],
118
+ },
119
+ prop4: {
120
+ delta: [
121
+ { name: "test" },
122
+ { name: "test" },
123
+ { name: "test" },
124
+ ],
125
+ },
126
+ };
127
+ notManifestRouteResultFilter.filterByMapRule(reqRes, rule, true);
128
+ expect(reqRes).to.be.deep.equal(expected);
129
+ });
130
+
131
+ it("not strict", function () {
132
+ const reqRes = {
133
+ prop1: "1",
134
+ prop2: {
135
+ sub: {
136
+ prop: {
137
+ id: 1,
138
+ name: "locale",
139
+ },
140
+ looser: "bummer",
141
+ },
142
+ stratification: true,
143
+ },
144
+ prop3: {
145
+ list: [
146
+ {
147
+ sub: {
148
+ id: 1,
149
+ name: "1",
150
+ },
151
+ },
152
+ ],
153
+ },
154
+ prop4: {
155
+ delta: [
156
+ { id: 1, name: "test" },
157
+ { id: 2, name: "test" },
158
+ { id: 3, name: "test" },
159
+ ],
160
+ },
161
+ strict: false,
162
+ };
163
+ const rule = {
164
+ prop1: true,
165
+ "prop2.sub.prop": ["name"],
166
+ "prop3.list": { sub: ["name"] },
167
+ "prop4.delta": ["name"],
168
+ };
169
+ const expected = {
170
+ prop1: "1",
171
+ prop2: {
172
+ sub: {
173
+ prop: {
174
+ name: "locale",
175
+ },
176
+ looser: "bummer",
177
+ },
178
+ stratification: true,
179
+ },
180
+ prop3: {
181
+ list: [
182
+ {
183
+ sub: {
184
+ name: "1",
185
+ },
186
+ },
187
+ ],
188
+ },
189
+ prop4: {
190
+ delta: [
191
+ { name: "test" },
192
+ { name: "test" },
193
+ { name: "test" },
194
+ ],
195
+ },
196
+ strict: false,
197
+ };
198
+ notManifestRouteResultFilter.filterByMapRule(reqRes, rule);
199
+ expect(reqRes).to.be.deep.equal(expected);
200
+ });
201
+ });
202
+
203
+ describe("filterStrict", function () {
204
+ it("filtering out side props", function () {
205
+ const reqRes = {
206
+ prop1: "1",
207
+ prop2: {
208
+ sub: {
209
+ prop: {
210
+ id: 1,
211
+ name: "locale",
212
+ },
213
+ looser: "bummer",
214
+ },
215
+ stratification: true,
216
+ },
217
+ prop3: {
218
+ list: [
219
+ {
220
+ sub: {
221
+ id: 1,
222
+ name: "1",
223
+ },
224
+ },
225
+ ],
226
+ },
227
+ prop4: {
228
+ delta: [
229
+ { id: 1, name: "test" },
230
+ { id: 3, name: "test" },
231
+ { id: 3, name: "test" },
232
+ ],
233
+ },
234
+ };
235
+ const rule = [
236
+ "prop1",
237
+ "prop2.sub.prop",
238
+ "prop3.list.sub",
239
+ "prop4.delta",
240
+ ];
241
+ const expected = {
242
+ prop1: "1",
243
+ prop2: {
244
+ sub: {
245
+ prop: {
246
+ id: 1,
247
+ name: "locale",
248
+ },
249
+ },
250
+ },
251
+ prop3: {
252
+ list: [
253
+ {
254
+ sub: {
255
+ id: 1,
256
+ name: "1",
257
+ },
258
+ },
259
+ ],
260
+ },
261
+ prop4: {
262
+ delta: [
263
+ { id: 1, name: "test" },
264
+ { id: 3, name: "test" },
265
+ { id: 3, name: "test" },
266
+ ],
267
+ },
268
+ };
269
+ notManifestRouteResultFilter.filterStrict(reqRes, rule);
270
+ expect(reqRes).to.be.deep.equal(expected);
271
+ });
272
+ });
273
+
274
+ describe("filterByArrayRule", function () {
275
+ it("no return rule field", function () {
276
+ const reqRes = {
277
+ prop1: "1",
278
+ prop2: "2",
279
+ prop3: "3",
280
+ prop4: "4",
281
+ };
282
+ const rule = ["prop1", "prop3"];
283
+ const expected = {
284
+ prop1: "1",
285
+ prop3: "3",
286
+ };
287
+ notManifestRouteResultFilter.filterByArrayRule(reqRes, rule);
288
+ expect(reqRes).to.be.deep.equal(expected);
289
+ });
290
+ });
291
+
292
+ describe("getFilteringRule", function () {
293
+ it("no return rule field", function () {
294
+ const res = notManifestRouteResultFilter.getFilteringRule({});
295
+ expect(res).to.be.undefined;
296
+ });
297
+
298
+ it("return rule field in actionData", function () {
299
+ const res = notManifestRouteResultFilter.getFilteringRule({
300
+ actionData: {
301
+ return: ["only", "this"],
302
+ },
303
+ });
304
+ expect(res).to.be.deep.equal(["only", "this"]);
305
+ });
306
+
307
+ it("return rule field in rule", function () {
308
+ const res = notManifestRouteResultFilter.getFilteringRule({
309
+ rule: { return: ["only", "that"] },
310
+ });
311
+ expect(res).to.be.deep.equal(["only", "that"]);
312
+ });
313
+ });
314
+
315
+ describe("getFilteringTargetPath", function () {
316
+ it("no path field", function () {
317
+ const res = notManifestRouteResultFilter.getFilteringTargetPath({});
318
+ expect(res).to.be.equal(":");
319
+ });
320
+
321
+ it("path field in actionData", function () {
322
+ const res = notManifestRouteResultFilter.getFilteringTargetPath({
323
+ actionData: {
324
+ returnRoot: "only.this",
325
+ },
326
+ });
327
+ expect(res).to.be.deep.equal(":only.this");
328
+ });
329
+
330
+ it("path field in rule", function () {
331
+ const res = notManifestRouteResultFilter.getFilteringTargetPath({
332
+ rule: { returnRoot: "only.that" },
333
+ });
334
+ expect(res).to.be.deep.equal(":only.that");
335
+ });
336
+
337
+ it("notRouteData is undefined", function () {
338
+ const res = notManifestRouteResultFilter.getFilteringTargetPath();
339
+ expect(res).to.be.equal(":");
340
+ });
341
+ });
342
+
343
+ describe("getFilteringTarget", function () {
344
+ const requestResult = () => {
345
+ return {
346
+ message: "some",
347
+ status: "ok",
348
+ result: {
349
+ list: [1],
350
+ },
351
+ };
352
+ };
353
+
354
+ it("no target object by path, returned undefined", function () {
355
+ const res = notManifestRouteResultFilter.getFilteringTarget(
356
+ requestResult(),
357
+ {
358
+ actionData: { returnRoot: "result.user" },
359
+ }
360
+ );
361
+ expect(res).to.be.undefined;
362
+ });
363
+
364
+ it("returnRoot path is empty", function () {
365
+ const res = notManifestRouteResultFilter.getFilteringTarget(
366
+ requestResult(),
367
+ {}
368
+ );
369
+ expect(res).to.be.deep.equal(requestResult());
370
+ });
371
+
372
+ it("returnRoot path is valid, sub object returned", function () {
373
+ const res = notManifestRouteResultFilter.getFilteringTarget(
374
+ requestResult(),
375
+ {
376
+ actionData: { returnRoot: "result" },
377
+ }
378
+ );
379
+ expect(res).to.be.deep.equal(requestResult().result);
380
+ });
381
+
382
+ it("return target is not object, source object returned", function () {
383
+ const res = notManifestRouteResultFilter.getFilteringTarget(
384
+ "string",
385
+ {
386
+ actionData: { returnRoot: "result" },
387
+ }
388
+ );
389
+ expect(res).to.be.deep.equal("string");
390
+ });
391
+ });
392
+
393
+ describe("getFilteringStrictMode", function () {
394
+ it("no strict mode field", function () {
395
+ const res = notManifestRouteResultFilter.getFilteringStrictMode({});
396
+ expect(res).to.be.equal(
397
+ notManifestRouteResultFilter.DEFAULT_STRICT_MODE
398
+ );
399
+ });
400
+
401
+ it("strict mode field in actionData", function () {
402
+ const res = notManifestRouteResultFilter.getFilteringStrictMode({
403
+ actionData: {
404
+ returnStrict: true,
405
+ },
406
+ });
407
+ expect(res).to.be.equal(true);
408
+ });
409
+
410
+ it("strict mode field in rule", function () {
411
+ const res = notManifestRouteResultFilter.getFilteringStrictMode({
412
+ rule: { returnStrict: true },
413
+ });
414
+ expect(res).to.be.equal(true);
415
+ });
416
+
417
+ it("notRouteData is undefined", function () {
418
+ const res = notManifestRouteResultFilter.getFilteringStrictMode();
419
+ expect(res).to.be.equal(false);
420
+ });
421
+ });
422
+ });