not-node 6.2.18 → 6.2.19

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.
Files changed (47) hide show
  1. package/.husky/pre-commit +4 -0
  2. package/package.json +7 -4
  3. package/src/auth/roles.js +9 -1
  4. package/src/auth/rules.js +5 -5
  5. package/src/cli/actions/env.mjs +1 -1
  6. package/src/cli/actions/nginx.mjs +1 -1
  7. package/src/cli/actions/pm2.mjs +1 -1
  8. package/src/common.js +1 -1
  9. package/src/domain.js +36 -24
  10. package/src/identity/providers/session.js +3 -0
  11. package/src/manifest/batchRunner.js +5 -1
  12. package/src/manifest/registrator/fields.js +4 -4
  13. package/src/manifest/route.js +1 -0
  14. package/src/model/exceptions.js +3 -3
  15. package/src/model/versioning.js +2 -2
  16. package/test/auth/routes.js +34 -10
  17. package/test/fakes.js +52 -0
  18. package/test/identity/providers/session.js +14 -5
  19. package/test/identity/providers/token.js +1 -1
  20. package/test/init/additional.js +31 -33
  21. package/test/init/app.js +66 -10
  22. package/test/init/bodyparser.js +4 -1
  23. package/test/init/compression.js +4 -1
  24. package/test/init/cors.js +5 -1
  25. package/test/init/csp.js +2 -2
  26. package/test/init/db.js +5 -1
  27. package/test/init/env.js +12 -2
  28. package/test/init/express.js +4 -1
  29. package/test/init/fileupload.js +4 -1
  30. package/test/init/http.js +21 -4
  31. package/test/init/middleware.js +13 -1
  32. package/test/init/routes.js +1 -0
  33. package/test/init/sessions/mongoose.js +5 -1
  34. package/test/init/sessions/redis.js +5 -1
  35. package/test/init/sessions.js +21 -15
  36. package/test/init/static.js +4 -1
  37. package/test/init/template.js +5 -1
  38. package/test/model/versioning.js +3 -3
  39. package/test/module/fields.js +45 -20
  40. package/test/module/index.js +26 -15
  41. package/test/notApp.js +221 -187
  42. package/test/notDomain.js +799 -707
  43. package/test/notManifestFilter.js +385 -322
  44. package/test/notModule.js +689 -644
  45. package/test/notRoute.js +112 -99
  46. package/test/testies/module/fields/collection.js +16 -14
  47. package/test/testies/module/fields/single.js +11 -11
package/test/notDomain.js CHANGED
@@ -1,777 +1,869 @@
1
- const expect = require('chai').expect,
2
- notModule = require('../src/manifest/module'),
3
- notDomain = require('../src/domain');
4
-
5
- const path = require('path');
6
- const pathToModules = path.join(__dirname, './testies/modules');
7
-
8
- describe('notDomain', function() {
9
-
10
- describe('forEachMod', function() {
11
- it('modules not empty', function() {
12
- const ctx = {
13
- modules:{
14
- user:{
15
- module: true
16
- },
17
- jom: false
18
- }
19
- };
20
- notDomain.prototype.forEachMod.call(ctx, (modName, mod, dom)=>{
21
- expect(modName).to.be.equal('user');
22
- expect(mod).to.be.deep.equal({
23
- module: true
24
- });
25
- });
26
- });
1
+ const expect = require("chai").expect,
2
+ notModule = require("../src/manifest/module"),
3
+ notDomain = require("../src/domain");
4
+
5
+ const path = require("path");
6
+ const pathToModules = path.join(__dirname, "./testies/modules");
7
+
8
+ describe("notDomain", function () {
9
+ describe("forEachMod", function () {
10
+ it("modules not empty", function () {
11
+ const ctx = {
12
+ modules: {
13
+ user: {
14
+ module: true,
15
+ },
16
+ jom: false,
17
+ },
18
+ };
19
+ notDomain.prototype.forEachMod.call(ctx, (modName, mod) => {
20
+ expect(modName).to.be.equal("user");
21
+ expect(mod).to.be.deep.equal({
22
+ module: true,
23
+ });
24
+ });
25
+ });
27
26
 
28
- it('modules empty', function() {
29
- const ctx = {};
30
- notDomain.prototype.forEachMod.call(ctx, ()=>{});
31
- });
32
- });
33
-
34
-
35
- describe('importModulesFrom', function() {
36
- it('modules not empty', function() {
37
- let modsList = [];
38
- const ctx = {
39
- importModuleFrom(path, file){
40
- modsList.push(file);
41
- }
42
- };
43
- notDomain.prototype.importModulesFrom.call(ctx, pathToModules);
44
- expect(modsList).to.be.deep.equal([
45
- 'not-test-module',
46
- 'post',
47
- 'user'
48
- ]);
49
- });
50
- });
51
-
52
- describe('importModuleFrom', function() {
53
- it('module not empty', function() {
54
- let imported = false;
55
- const pathToModule = path.join(pathToModules, 'user');
56
- const ctx = {
57
- options:{
58
- mongoose: require('mongoose')
59
- },
60
- importModule(mod, name){
61
- expect(mod).to.be.instanceof(notModule);
62
- expect(name).to.be.equal('testModule');
63
- imported = true;
64
- }
65
- };
66
- notDomain.prototype.importModuleFrom.call(ctx, pathToModule, 'testModule');
67
- expect(imported).to.be.true;
27
+ it("modules empty", function () {
28
+ const ctx = {};
29
+ notDomain.prototype.forEachMod.call(ctx, () => {});
30
+ });
68
31
  });
69
32
 
70
- it('module not empty, moduleName empty', function() {
71
- let imported = false;
72
- const pathToModule = path.join(pathToModules, 'user');
73
- const ctx = {
74
- options:{
75
- mongoose: require('mongoose')
76
- },
77
- importModule(mod, name){
78
- expect(mod).to.be.instanceof(notModule);
79
- expect(name).to.be.equal('not-user');
80
- imported = true;
81
- }
82
- };
83
- notDomain.prototype.importModuleFrom.call(ctx, pathToModule);
84
- expect(imported).to.be.true;
85
- });
86
- });
87
-
88
- describe('importModule', function() {
89
- it('module not empty', function() {
90
- const mod = {
91
- mod: true
92
- };
93
- const ctx = {
94
- modules:{}
95
- };
96
- notDomain.prototype.importModule.call(ctx, mod, 'testModule');
97
- expect(ctx.modules.testModule).to.be.ok;
98
- expect(ctx.modules.testModule).to.be.deep.equal(mod);
33
+ describe("importModulesFrom", function () {
34
+ it("modules not empty", function () {
35
+ let modsList = [];
36
+ const ctx = {
37
+ importModuleFrom(path, file) {
38
+ modsList.push(file);
39
+ },
40
+ };
41
+ notDomain.prototype.importModulesFrom.call(ctx, pathToModules);
42
+ expect(modsList).to.be.deep.equal([
43
+ "not-test-module",
44
+ "post",
45
+ "user",
46
+ ]);
47
+ });
99
48
  });
100
- });
101
49
 
50
+ describe("importModuleFrom", function () {
51
+ it("module not empty", function () {
52
+ let imported = false;
53
+ const pathToModule = path.join(pathToModules, "user");
54
+ const ctx = {
55
+ options: {
56
+ mongoose: require("mongoose"),
57
+ },
58
+ importModule(mod, name) {
59
+ expect(mod).to.be.instanceof(notModule);
60
+ expect(name).to.be.equal("not-user");
61
+ imported = true;
62
+ },
63
+ };
64
+ notDomain.prototype.importModuleFrom.call(
65
+ ctx,
66
+ pathToModule,
67
+ "testModule"
68
+ );
69
+ expect(imported).to.be.true;
70
+ });
102
71
 
103
- describe('getRoute', function() {
104
- it('route name missformed', function() {
105
- const route = 'myWay';
106
- const ctx = {
107
-
108
- };
109
- const res = notDomain.prototype.getRoute.call(ctx, route);
110
- expect(res).to.be.null;
72
+ it("module not empty, moduleName empty", function () {
73
+ let imported = false;
74
+ const pathToModule = path.join(pathToModules, "user");
75
+ const ctx = {
76
+ options: {
77
+ mongoose: require("mongoose"),
78
+ },
79
+ importModule(mod, name) {
80
+ expect(mod).to.be.instanceof(notModule);
81
+ expect(name).to.be.equal("not-user");
82
+ imported = true;
83
+ },
84
+ };
85
+ notDomain.prototype.importModuleFrom.call(ctx, pathToModule);
86
+ expect(imported).to.be.true;
87
+ });
111
88
  });
112
89
 
113
- it('route name ok, module, route and action exists', function() {
114
- const route = 'not-user//user//myWay';
115
- const id = Math.random();
116
- const ctx = {
117
- modules:{
118
- 'not-user': {
119
- getRoute(){
120
- return {
121
- myWay(){return id;}
122
- }
123
- }
124
- }
125
- }
126
- };
127
- const res = notDomain.prototype.getRoute.call(ctx, route);
128
- expect(typeof res).to.be.equal('function');
129
- expect(res()).to.be.equal(id);
90
+ describe("importModule", function () {
91
+ it("module not empty", function () {
92
+ const mod = {
93
+ mod: true,
94
+ };
95
+ const fModules = {};
96
+ const ctx = {
97
+ modules: fModules,
98
+ getModule(name) {
99
+ return fModules[name];
100
+ },
101
+ setModule(name, val) {
102
+ fModules[name] = val;
103
+ },
104
+ };
105
+ notDomain.prototype.importModule.call(ctx, mod, "testModule");
106
+ expect(ctx.modules.testModule).to.be.ok;
107
+ expect(ctx.modules.testModule).to.be.deep.equal(mod);
108
+ });
130
109
  });
131
110
 
111
+ describe("getRoute", function () {
112
+ it("route name missformed", function () {
113
+ const route = "myWay";
114
+ const ctx = {};
115
+ const res = notDomain.prototype.getRoute.call(ctx, route);
116
+ expect(res).to.be.null;
117
+ });
132
118
 
133
- it('route name ok, module not exists', function() {
134
- const route = 'not-user//user//myWay';
135
- const id = Math.random();
136
- const ctx = {
137
- modules:{
138
- 'not-user1': {
139
- getRoute(){
140
- return {
141
- myWay(){return id;}
142
- }
143
- }
144
- }
145
- }
146
- };
147
- const res = notDomain.prototype.getRoute.call(ctx, route);
148
- expect(res).to.be.null;
149
- });
150
-
151
- it('route name ok, module exists, route not exists', function() {
152
- const route = 'not-user//user//myWay';
153
- const id = Math.random();
154
- const ctx = {
155
- modules:{
156
- 'not-user': {
157
- getRoute(){
158
- return false;
159
- }
160
- }
161
- }
162
- };
163
- const res = notDomain.prototype.getRoute.call(ctx, route);
164
- expect(res).to.be.null;
165
- });
119
+ it("route name ok, module, route and action exists", function () {
120
+ const route = "not-user//user//myWay";
121
+ const id = Math.random();
122
+ const fModules = {
123
+ "not-user": {
124
+ getRoute() {
125
+ return {
126
+ myWay() {
127
+ return id;
128
+ },
129
+ };
130
+ },
131
+ },
132
+ };
133
+ const ctx = {
134
+ modules: fModules,
135
+ getModule(name) {
136
+ return fModules[name];
137
+ },
138
+ };
139
+ const res = notDomain.prototype.getRoute.call(ctx, route);
140
+ expect(typeof res).to.be.equal("function");
141
+ expect(res()).to.be.equal(id);
142
+ });
166
143
 
167
- it('route name ok, module exists, route exists, actio not exists', function() {
168
- const route = 'not-user//user//myWay';
169
- const ctx = {
170
- modules:{
171
- 'not-user': {
172
- getRoute(){
173
- return {};
174
- }
175
- }
176
- }
177
- };
178
- const res = notDomain.prototype.getRoute.call(ctx, route);
179
- expect(res).to.be.null;
180
- });
181
- });
182
-
183
- describe('getModel', function() {
184
- it('model name short', function() {
185
- const route = 'Jungle';
186
- const ctx = {
187
- getByPath(){return null;}
188
- };
189
- const res = notDomain.prototype.getModel.call(ctx, route);
190
- expect(res).to.be.null;
191
- });
144
+ it("route name ok, module not exists", function () {
145
+ const route = "not-user//user//myWay";
146
+ const id = Math.random();
147
+ const fModules = {
148
+ "not-user1": {
149
+ getRoute() {
150
+ return {
151
+ myWay() {
152
+ return id;
153
+ },
154
+ };
155
+ },
156
+ },
157
+ };
158
+ const ctx = {
159
+ modules: fModules,
160
+ getModule(name) {
161
+ return fModules[name];
162
+ },
163
+ };
164
+ const res = notDomain.prototype.getRoute.call(ctx, route);
165
+ expect(res).to.be.null;
166
+ });
192
167
 
193
- it('model name full', function() {
194
- const id = Math.random();
195
- const route = 'module//Jungle';
196
- const ctx = {
197
- getByPath(){return id;}
198
- };
199
- const res = notDomain.prototype.getModel.call(ctx, route);
200
- expect(res).to.be.equal(id);
201
- });
202
- });
203
-
204
- describe('getModelFile', function() {
205
- it('name short', function() {
206
- const id = Math.random();
207
- const route = 'Jungle';
208
- const ctx = {
209
- getByPath(){return id;}
210
- };
211
- const res = notDomain.prototype.getModelFile.call(ctx, route);
212
- expect(res).to.be.equal(id);
213
- });
168
+ it("route name ok, module exists, route not exists", function () {
169
+ const route = "not-user//user//myWay";
170
+ const id = Math.random();
171
+ const fModules = {
172
+ "not-user": {
173
+ getRoute() {
174
+ return false;
175
+ },
176
+ },
177
+ };
178
+ const ctx = {
179
+ modules: fModules,
180
+ getModule(name) {
181
+ return fModules[name];
182
+ },
183
+ };
184
+ const res = notDomain.prototype.getRoute.call(ctx, route);
185
+ expect(res).to.be.null;
186
+ });
214
187
 
215
- it('name full', function() {
216
- const id = Math.random();
217
- const route = 'module//Jungle';
218
- const ctx = {
219
- getByPath(){return id;}
220
- };
221
- const res = notDomain.prototype.getModelFile.call(ctx, route);
222
- expect(res).to.be.equal(id);
223
- });
224
- });
225
-
226
-
227
- describe('getModelSchema', function() {
228
- it('name short', function() {
229
- const id = Math.random();
230
- const route = 'Jungle';
231
- const ctx = {
232
- getByPath(){return id;}
233
- };
234
- const res = notDomain.prototype.getModelSchema.call(ctx, route);
235
- expect(res).to.be.equal(id);
188
+ it("route name ok, module exists, route exists, actio not exists", function () {
189
+ const route = "not-user//user//myWay";
190
+ const fModules = {
191
+ "not-user": {
192
+ getRoute() {
193
+ return {};
194
+ },
195
+ },
196
+ };
197
+ const ctx = {
198
+ modules: fModules,
199
+ getModule(name) {
200
+ return fModules[name];
201
+ },
202
+ };
203
+ const res = notDomain.prototype.getRoute.call(ctx, route);
204
+ expect(res).to.be.null;
205
+ });
236
206
  });
237
207
 
238
- it('name full', function() {
239
- const id = Math.random();
240
- const route = 'module//Jungle';
241
- const ctx = {
242
- getByPath(){return id;}
243
- };
244
- const res = notDomain.prototype.getModelSchema.call(ctx, route);
245
- expect(res).to.be.equal(id);
246
- });
247
- });
248
-
249
-
250
- describe('getLogic', function() {
251
- it('name short', function() {
252
- const id = Math.random();
253
- const route = 'Jungle';
254
- const ctx = {
255
- getByPath(){return id;}
256
- };
257
- const res = notDomain.prototype.getLogic.call(ctx, route);
258
- expect(res).to.be.equal(id);
259
- });
208
+ describe("getModel", function () {
209
+ it("model name short", function () {
210
+ const route = "Jungle";
211
+ const ctx = {
212
+ getByPath() {
213
+ return null;
214
+ },
215
+ };
216
+ const res = notDomain.prototype.getModel.call(ctx, route);
217
+ expect(res).to.be.null;
218
+ });
260
219
 
261
- it('name full', function() {
262
- const id = Math.random();
263
- const route = 'module//Jungle';
264
- const ctx = {
265
- getByPath(){return id;}
266
- };
267
- const res = notDomain.prototype.getLogic.call(ctx, route);
268
- expect(res).to.be.equal(id);
269
- });
270
- });
271
-
272
- describe('getLogicFile', function() {
273
- it('name short', function() {
274
- const id = Math.random();
275
- const route = 'Jungle';
276
- const ctx = {
277
- getByPath(){return id;}
278
- };
279
- const res = notDomain.prototype.getLogicFile.call(ctx, route);
280
- expect(res).to.be.equal(id);
220
+ it("model name full", function () {
221
+ const id = Math.random();
222
+ const route = "module//Jungle";
223
+ const ctx = {
224
+ getByPath() {
225
+ return id;
226
+ },
227
+ };
228
+ const res = notDomain.prototype.getModel.call(ctx, route);
229
+ expect(res).to.be.equal(id);
230
+ });
281
231
  });
282
232
 
283
- it('name full', function() {
284
- const id = Math.random();
285
- const route = 'module//Jungle';
286
- const ctx = {
287
- getByPath(){return id;}
288
- };
289
- const res = notDomain.prototype.getLogicFile.call(ctx, route);
290
- expect(res).to.be.equal(id);
291
- });
292
- });
293
-
294
-
295
- describe('getByFullPath', function() {
296
- it('path exists', function() {
297
- const id = Math.random();
298
- const path = 'user//resource';
299
- const type = 'File';
300
- const ctx = {
301
- modules:{
302
- user:{
303
- getFile(name){
304
- expect(name).to.be.equal('resource');
305
- return id;
306
- }
307
- }
308
- }
309
- };
310
- const res = notDomain.prototype.getByFullPath.call(ctx, path, type);
311
- expect(res).to.be.equal(id);
312
- });
233
+ describe("getModelFile", function () {
234
+ it("name short", function () {
235
+ const id = Math.random();
236
+ const route = "Jungle";
237
+ const ctx = {
238
+ getByPath() {
239
+ return id;
240
+ },
241
+ };
242
+ const res = notDomain.prototype.getModelFile.call(ctx, route);
243
+ expect(res).to.be.equal(id);
244
+ });
313
245
 
314
- it('path not exists', function() {
315
- const path = 'usesr//resource';
316
- const type = 'File';
317
- const ctx = {
318
- modules:{
319
- user:{
320
- getFile(name){
321
- expect(name).to.be.equal('resource');
322
- return id;
323
- }
324
- }
325
- }
326
- };
327
- const res = notDomain.prototype.getByFullPath.call(ctx, path, type);
328
- expect(res).to.be.null;
246
+ it("name full", function () {
247
+ const id = Math.random();
248
+ const route = "module//Jungle";
249
+ const ctx = {
250
+ getByPath() {
251
+ return id;
252
+ },
253
+ };
254
+ const res = notDomain.prototype.getModelFile.call(ctx, route);
255
+ expect(res).to.be.equal(id);
256
+ });
329
257
  });
330
258
 
331
- });
259
+ describe("getModelSchema", function () {
260
+ it("name short", function () {
261
+ const id = Math.random();
262
+ const route = "Jungle";
263
+ const ctx = {
264
+ getByPath() {
265
+ return id;
266
+ },
267
+ };
268
+ const res = notDomain.prototype.getModelSchema.call(ctx, route);
269
+ expect(res).to.be.equal(id);
270
+ });
332
271
 
272
+ it("name full", function () {
273
+ const id = Math.random();
274
+ const route = "module//Jungle";
275
+ const ctx = {
276
+ getByPath() {
277
+ return id;
278
+ },
279
+ };
280
+ const res = notDomain.prototype.getModelSchema.call(ctx, route);
281
+ expect(res).to.be.equal(id);
282
+ });
283
+ });
333
284
 
285
+ describe("getLogic", function () {
286
+ it("name short", function () {
287
+ const id = Math.random();
288
+ const route = "Jungle";
289
+ const ctx = {
290
+ getByPath() {
291
+ return id;
292
+ },
293
+ };
294
+ const res = notDomain.prototype.getLogic.call(ctx, route);
295
+ expect(res).to.be.equal(id);
296
+ });
334
297
 
335
- describe('getByShortPath', function() {
336
- it('path exists', function() {
337
- const id = Math.random();
338
- const path = 'resource';
339
- const type = 'File';
340
- const ctx = {
341
- modules:{
342
- lite:{
343
- getFile(){return false;}
344
- },
345
- user:{
346
- getFile(name){
347
- expect(name).to.be.equal('resource');
348
- return id;
349
- }
350
- }
351
- }
352
- };
353
- const res = notDomain.prototype.getByShortPath.call(ctx, path, type);
354
- expect(res).to.be.equal(id);
298
+ it("name full", function () {
299
+ const id = Math.random();
300
+ const route = "module//Jungle";
301
+ const ctx = {
302
+ getByPath() {
303
+ return id;
304
+ },
305
+ };
306
+ const res = notDomain.prototype.getLogic.call(ctx, route);
307
+ expect(res).to.be.equal(id);
308
+ });
355
309
  });
356
310
 
357
- it('path not exists', function() {
358
- const path = 'usesr';
359
- const type = 'File';
360
- const ctx = {
361
- modules:{
362
- user:{
363
- getFile(){
364
- return null;
365
- }
366
- }
367
- }
368
- };
369
- const res = notDomain.prototype.getByShortPath.call(ctx, path, type);
370
- expect(res).to.be.null;
371
- });
372
- });
373
-
374
- describe('getModule', function() {
375
- it('exists', function() {
376
- const route = 'user';
377
- const ctx = {
378
- modules:{
379
- user:{
380
- mod: 'user'
381
- }
382
- }
383
- };
384
- const res = notDomain.prototype.getModule.call(ctx, route);
385
- expect(res).to.be.deep.equal({
386
- mod: 'user'
387
- });
388
- });
311
+ describe("getLogicFile", function () {
312
+ it("name short", function () {
313
+ const id = Math.random();
314
+ const route = "Jungle";
315
+ const ctx = {
316
+ getByPath() {
317
+ return id;
318
+ },
319
+ };
320
+ const res = notDomain.prototype.getLogicFile.call(ctx, route);
321
+ expect(res).to.be.equal(id);
322
+ });
389
323
 
390
- it('exists, but with custom name', function() {
391
- const route = 'Jungle';
392
- const targetMod = {
393
- getName(){ return 'Jungle'; }
394
- };
395
- const ctx = {
396
- modules:{
397
- loop:{
398
- getName(){return 'loop'; }
399
- },
400
- trees: targetMod
401
- }
402
- };
403
- const res = notDomain.prototype.getModule.call(ctx, route);
404
- expect(res).to.be.deep.equal(targetMod);
324
+ it("name full", function () {
325
+ const id = Math.random();
326
+ const route = "module//Jungle";
327
+ const ctx = {
328
+ getByPath() {
329
+ return id;
330
+ },
331
+ };
332
+ const res = notDomain.prototype.getLogicFile.call(ctx, route);
333
+ expect(res).to.be.equal(id);
334
+ });
405
335
  });
406
336
 
337
+ describe("getByFullPath", function () {
338
+ it("path exists", function () {
339
+ const id = Math.random();
340
+ const path = "user//resource";
341
+ const type = "File";
342
+ const fModules = {
343
+ user: {
344
+ getFile(name) {
345
+ expect(name).to.be.equal("resource");
346
+ return id;
347
+ },
348
+ },
349
+ };
350
+ const ctx = {
351
+ modules: fModules,
352
+ getModule(name) {
353
+ return fModules[name];
354
+ },
355
+ };
356
+ const res = notDomain.prototype.getByFullPath.call(ctx, path, type);
357
+ expect(res).to.be.equal(id);
358
+ });
407
359
 
408
- it('not exists', function() {
409
- const route = 'Jungle';
410
- const targetMod = {
411
- getName(){ return 'Jungle1'; }
412
- };
413
- const ctx = {
414
- modules:{
415
- loop:{
416
- getName(){return 'loop'; }
417
- },
418
- trees: targetMod
419
- }
420
- };
421
- const res = notDomain.prototype.getModule.call(ctx, route);
422
- expect(res).to.be.null;
423
- });
424
- });
425
-
426
- //execInModules
427
- describe('execInModules', function() {
428
- it('exec - ok', async ()=> {
429
- let executed = 0;
430
- const method = 'jump';
431
- const ctx = {
432
- modules:{
433
- user:{
434
- exec(){
435
- executed++;
436
- }
437
- },
438
- dof:{
439
- async exec(){
440
- executed++;
441
- }
442
- }
443
- },
444
- report(e){
445
- expect(e).to.be.instanceof(Error);
446
- }
447
- };
448
- await notDomain.prototype.execInModules.call(ctx, method);
449
- expect(executed).to.be.equal(2);
360
+ it("path not exists", function () {
361
+ const path = "usesr//resource";
362
+ const type = "File";
363
+ const fModules = {
364
+ user: {
365
+ getFile(name) {
366
+ expect(name).to.be.equal("resource");
367
+ return id;
368
+ },
369
+ },
370
+ };
371
+ const ctx = {
372
+ modules: fModules,
373
+ getModule(name) {
374
+ return fModules[name];
375
+ },
376
+ };
377
+ const res = notDomain.prototype.getByFullPath.call(ctx, path, type);
378
+ expect(res).to.be.null;
379
+ });
450
380
  });
451
381
 
382
+ describe("getByShortPath", function () {
383
+ it("path exists", function () {
384
+ const id = Math.random();
385
+ const path = "resource";
386
+ const type = "File";
387
+ const fModules = {
388
+ lite: {
389
+ getFile() {
390
+ return false;
391
+ },
392
+ },
393
+ user: {
394
+ getFile(name) {
395
+ expect(name).to.be.equal("resource");
396
+ return id;
397
+ },
398
+ },
399
+ };
400
+ const ctx = {
401
+ modules: fModules,
402
+ getModule(name) {
403
+ return fModules[name];
404
+ },
405
+ };
406
+ const res = notDomain.prototype.getByShortPath.call(
407
+ ctx,
408
+ path,
409
+ type
410
+ );
411
+ expect(res).to.be.equal(id);
412
+ });
452
413
 
453
- it('exec - one failed, other runned', async ()=> {
454
- let executed = 0, failed = false;
455
- const method = 'jump';
456
- const ctx = {
457
- modules:{
458
- user:{
459
- exec(){
460
- executed++;
461
- }
462
- },
463
- dof:{
464
- async exec(){
465
- throw 'execution failed'
466
- }
467
- },
468
- loaf:{
469
- async exec(){
470
- expect(failed).to.be.true;
471
- executed++;
472
- }
473
- },
474
- },
475
- report(e){
476
- failed = true;
477
- expect(e).to.be.equal('execution failed');
478
- }
479
- };
480
- await notDomain.prototype.execInModules.call(ctx, method);
481
- expect(executed).to.be.equal(2);
482
- expect(failed).to.be.true;
483
- });
484
- });
485
-
486
-
487
- describe('fabricate', function() {
488
- it('modules', function() {
489
- let cnt = 0;
490
- const ctx = {
491
- modules:{
492
- user:{
493
- fabricateModels(){cnt++;}
494
- },
495
- load:{
496
- fabricateModels(){cnt++;}
497
- },
498
- loaf:{},
499
- mepty:{
500
- fabricateModels(){cnt++;}
501
- },
502
- }
503
- };
504
- notDomain.prototype.fabricate.call(ctx);
505
- expect(cnt).to.be.equal(3);
414
+ it("path not exists", function () {
415
+ const path = "usesr";
416
+ const type = "File";
417
+ const fModules = {
418
+ user: {
419
+ getFile() {
420
+ return null;
421
+ },
422
+ },
423
+ };
424
+ const ctx = {
425
+ modules: fModules,
426
+ getModule(name) {
427
+ return fModules[name];
428
+ },
429
+ };
430
+ const res = notDomain.prototype.getByShortPath.call(
431
+ ctx,
432
+ path,
433
+ type
434
+ );
435
+ expect(res).to.be.null;
436
+ });
506
437
  });
507
- });
508
438
 
439
+ describe("getModule", function () {
440
+ it("exists", function () {
441
+ const route = "user";
442
+ const fModules = {
443
+ user: {
444
+ mod: "user",
445
+ },
446
+ };
447
+ const ctx = {
448
+ modules: fModules,
449
+ getModule(name) {
450
+ return fModules[name];
451
+ },
452
+ };
453
+ const res = notDomain.prototype.getModule.call(ctx, route);
454
+ expect(res).to.be.deep.equal({
455
+ mod: "user",
456
+ });
457
+ });
509
458
 
459
+ it("exists, but with custom name", function () {
460
+ const route = "Jungle";
461
+ const targetMod = {
462
+ getName() {
463
+ return "Jungle";
464
+ },
465
+ };
466
+ const fModules = {
467
+ loop: {
468
+ getName() {
469
+ return "loop";
470
+ },
471
+ },
472
+ trees: targetMod,
473
+ };
474
+ const ctx = {
475
+ modules: fModules,
476
+ getModule(name) {
477
+ return fModules[name];
478
+ },
479
+ };
480
+ const res = notDomain.prototype.getModule.call(ctx, route);
481
+ expect(res).to.be.deep.equal(targetMod);
482
+ });
510
483
 
484
+ it("not exists", function () {
485
+ const route = "Jungle";
486
+ const targetMod = {
487
+ getName() {
488
+ return "Jungle1";
489
+ },
490
+ };
491
+ const fModules = {
492
+ loop: {
493
+ getName() {
494
+ return "loop";
495
+ },
496
+ },
497
+ trees: targetMod,
498
+ };
499
+ const ctx = {
500
+ modules: fModules,
501
+ getModule(name) {
502
+ return fModules[name];
503
+ },
504
+ };
505
+ const res = notDomain.prototype.getModule.call(ctx, route);
506
+ expect(res).to.be.null;
507
+ });
508
+ });
511
509
 
510
+ //execInModules
511
+ describe("execInModules", function () {
512
+ it("exec - ok", async () => {
513
+ let executed = 0;
514
+ const method = "jump";
515
+ const fModules = {
516
+ user: {
517
+ exec() {
518
+ executed++;
519
+ },
520
+ },
521
+ dof: {
522
+ async exec() {
523
+ executed++;
524
+ },
525
+ },
526
+ };
527
+ const ctx = {
528
+ modules: fModules,
529
+ report(e) {
530
+ expect(e).to.be.instanceof(Error);
531
+ },
532
+ getModule(name) {
533
+ return fModules[name];
534
+ },
535
+ };
536
+ await notDomain.prototype.execInModules.call(ctx, method);
537
+ expect(executed).to.be.equal(2);
538
+ });
512
539
 
513
- describe('logger', function() {
514
- it('getter/setter', function() {
515
- const dom = new notDomain({});
516
- expect(dom.logger).to.be.deep.equal(console);
517
- dom.logger = 'happy';
518
- expect(dom.logger).to.be.deep.equal('happy');
540
+ it("exec - one failed, other runned", async () => {
541
+ let executed = 0,
542
+ failed = false;
543
+ const method = "jump";
544
+ const fModules = {
545
+ user: {
546
+ exec() {
547
+ executed++;
548
+ },
549
+ },
550
+ dof: {
551
+ async exec() {
552
+ throw "execution failed";
553
+ },
554
+ },
555
+ loaf: {
556
+ async exec() {
557
+ expect(failed).to.be.true;
558
+ executed++;
559
+ },
560
+ },
561
+ };
562
+ const ctx = {
563
+ modules: fModules,
564
+ getModule(name) {
565
+ return fModules[name];
566
+ },
567
+ report(e) {
568
+ failed = true;
569
+ expect(e).to.be.equal("execution failed");
570
+ },
571
+ };
572
+ await notDomain.prototype.execInModules.call(ctx, method);
573
+ expect(executed).to.be.equal(2);
574
+ expect(failed).to.be.true;
575
+ });
519
576
  });
520
577
 
521
- it('log', function(done) {
522
- const dom = new notDomain({});
523
- const params = ['leet',2, {cold: true}];
524
- expect(dom.logger).to.be.deep.equal(console);
525
- dom.logger = {
526
- log(){
527
- expect(Array.from(arguments)).to.be.deep.equal(params);
528
- done()
529
- }
530
- };
531
- dom.log(...params);
578
+ describe("fabricate", function () {
579
+ it("modules", function () {
580
+ let cnt = 0;
581
+ const fModules = {
582
+ user: {
583
+ fabricateModels() {
584
+ cnt++;
585
+ },
586
+ },
587
+ load: {
588
+ fabricateModels() {
589
+ cnt++;
590
+ },
591
+ },
592
+ loaf: {},
593
+ mepty: {
594
+ fabricateModels() {
595
+ cnt++;
596
+ },
597
+ },
598
+ };
599
+ const ctx = {
600
+ modules: fModules,
601
+ getModule(name) {
602
+ return fModules[name];
603
+ },
604
+ };
605
+ notDomain.prototype.fabricate.call(ctx);
606
+ expect(cnt).to.be.equal(3);
607
+ });
532
608
  });
533
- });
534
609
 
610
+ describe("logger", function () {
611
+ it("getter/setter", function () {
612
+ const dom = new notDomain({});
613
+ expect(dom.logger).to.be.deep.equal(console);
614
+ dom.logger = "happy";
615
+ expect(dom.logger).to.be.deep.equal("happy");
616
+ });
535
617
 
536
- describe('reporter', function() {
537
- it('getter/setter', function() {
538
- const dom = new notDomain({});
539
- expect(dom.reporter).to.have.keys(['report']);
540
- dom.reporter = 'happy';
541
- expect(dom.reporter).to.be.deep.equal('happy');
618
+ it("log", function (done) {
619
+ const dom = new notDomain({});
620
+ const params = ["leet", 2, { cold: true }];
621
+ expect(dom.logger).to.be.deep.equal(console);
622
+ dom.logger = {
623
+ log() {
624
+ expect(Array.from(arguments)).to.be.deep.equal(params);
625
+ done();
626
+ },
627
+ };
628
+ dom.log(...params);
629
+ });
542
630
  });
543
631
 
544
- it('report', function() {
545
- const dom = new notDomain({});
546
- const params = ['leet',2, {cold: true}];
547
- dom.report('some data');
548
- dom.reporter = {
549
- async report(...somedata){
550
- expect(somedata).to.be.deep.equal(params);
551
- throw 'ok';
552
- }
553
- };
554
- try{
555
- dom.reporter.report(params);
556
- }catch(e){
557
- expect(e).to.be.equal('ok');
558
- }
632
+ describe("reporter", function () {
633
+ it("getter/setter", function () {
634
+ const dom = new notDomain({});
635
+ expect(dom.reporter).to.have.keys(["report"]);
636
+ dom.reporter = "happy";
637
+ expect(dom.reporter).to.be.deep.equal("happy");
638
+ });
639
+
640
+ it("report", function () {
641
+ const dom = new notDomain({});
642
+ const params = ["leet", 2, { cold: true }];
643
+ dom.report("some data");
644
+ dom.reporter = {
645
+ async report(...somedata) {
646
+ expect(somedata).to.be.deep.equal(params);
647
+ throw "ok";
648
+ },
649
+ };
650
+ try {
651
+ dom.reporter.report(params);
652
+ } catch (e) {
653
+ expect(e).to.be.equal("ok");
654
+ }
655
+ });
559
656
  });
560
- });
561
657
 
658
+ describe("informer", function () {
659
+ it("getter/setter", function () {
660
+ const dom = new notDomain({});
661
+ expect(dom.informer).to.have.keys(["now"]);
662
+ dom.informer = "happy";
663
+ expect(dom.informer).to.be.deep.equal("happy");
664
+ });
562
665
 
563
- describe('informer', function() {
564
- it('getter/setter', function() {
565
- const dom = new notDomain({});
566
- expect(dom.informer).to.have.keys(['now']);
567
- dom.informer = 'happy';
568
- expect(dom.informer).to.be.deep.equal('happy');
666
+ it("inform", function () {
667
+ const dom = new notDomain({});
668
+ const params = ["leet", 2, { cold: true }];
669
+ dom.inform("some data");
670
+ dom.inform = {
671
+ async now(...somedata) {
672
+ expect(somedata).to.be.deep.equal(params);
673
+ throw "ok";
674
+ },
675
+ };
676
+ try {
677
+ dom.inform.now(params);
678
+ } catch (e) {
679
+ expect(e).to.be.equal("ok");
680
+ }
681
+ });
569
682
  });
570
683
 
571
- it('inform', function() {
572
- const dom = new notDomain({});
573
- const params = ['leet',2, {cold: true}];
574
- dom.inform('some data');
575
- dom.inform = {
576
- async now(...somedata){
577
- expect(somedata).to.be.deep.equal(params);
578
- throw 'ok';
579
- }
580
- };
581
- try{
582
- dom.inform.now(params);
583
- }catch(e){
584
- expect(e).to.be.equal('ok');
585
- }
586
- });
587
- });
588
-
589
- describe('addWSServer', function() {
590
- it('set', function() {
591
- const ctx = {
592
- _wss:{}
593
- };
594
- notDomain.prototype.addWSServer.call(ctx, 'key', 'happy');
595
- expect(ctx._wss.key).to.be.deep.equal('happy');
684
+ describe("addWSServer", function () {
685
+ it("set", function () {
686
+ const dom = new notDomain({});
687
+ dom.addWSServer("key", "happy");
688
+ expect(dom.WSServer("key")).to.be.deep.equal("happy");
689
+ });
596
690
  });
597
- });
598
-
599
-
600
- describe('WSServer', function() {
601
- it('default(main) exists', function() {
602
- const ctx = {
603
- _wss:{
604
- main: 'happy'
605
- }
606
- };
607
- const res = notDomain.prototype.WSServer.call(ctx);
608
- expect(res).to.be.equal('happy');
691
+
692
+ describe("WSServer", function () {
693
+ it("default(main) exists", function () {
694
+ const dom = new notDomain({});
695
+ dom.addWSServer("main", "happy");
696
+ const res = dom.WSServer();
697
+ expect(res).to.be.equal("happy");
698
+ });
699
+
700
+ it("default(main) not exists", function () {
701
+ const dom = new notDomain({});
702
+ const res = dom.WSServer();
703
+ expect(res).to.be.undefined;
704
+ });
609
705
  });
610
706
 
611
- it('default(main) not exists', function() {
612
- const ctx = {
613
- _wss:{
614
- }
615
- };
616
- const res = notDomain.prototype.WSServer.call(ctx);
617
- expect(res).to.be.undefined;
707
+ describe("addWSClient", function () {
708
+ it("set", function () {
709
+ const dom = new notDomain({});
710
+ dom.addWSClient("key", "happy");
711
+ expect(dom.WSClient("key")).to.be.deep.equal("happy");
712
+ });
618
713
  });
619
- });
620
714
 
715
+ describe("WSClient", function () {
716
+ it("main exists", function () {
717
+ const dom = new notDomain({});
718
+ dom.addWSClient("main", "happy");
719
+ const res = dom.WSClient("main");
720
+ expect(res).to.be.equal("happy");
721
+ });
621
722
 
622
- describe('addWSClient', function() {
623
- it('set', function() {
624
- const ctx = {
625
- _wsc:{}
626
- };
627
- notDomain.prototype.addWSClient.call(ctx, 'key', 'happy');
628
- expect(ctx._wsc.key).to.be.deep.equal('happy');
629
- });
630
- });
631
-
632
- describe('WSClient', function() {
633
- it('main exists', function() {
634
- const ctx = {
635
- _wsc:{
636
- main: 'happy'
637
- }
638
- };
639
- const res = notDomain.prototype.WSClient.call(ctx, 'main');
640
- expect(res).to.be.equal('happy');
723
+ it("default(main) not exists", function () {
724
+ const dom = new notDomain({});
725
+ const res = dom.WSClient();
726
+ expect(res).to.be.undefined;
727
+ });
641
728
  });
642
729
 
643
- it('default(main) not exists', function() {
644
- const ctx = {
645
- _wsc:{
646
- }
647
- };
648
- const res = notDomain.prototype.WSClient.call(ctx);
649
- expect(res).to.be.undefined;
650
- });
651
- });
652
-
653
-
654
- describe('shutdown', function() {
655
- it(`default timeout, ${notDomain.OPT_DEFAULT_SHUTDOWN_TIMEOUT}ms`, function(done) {
656
- const realProcess = process;
657
- const exitMock = ()=>{
658
- global.process = realProcess;
659
- done();
660
- }
661
- global.process = { ...realProcess, exit: exitMock };
662
- const ctx = {
663
- log(str){
664
- expect(str).to.be.equal(`Перезагрузка сервиса через ${notDomain.OPT_DEFAULT_SHUTDOWN_TIMEOUT}мс...`)
665
- },
666
- emit(evName){
667
- expect(evName).to.be.equal('app:shutdown');
668
- }
669
- };
670
- notDomain.prototype.shutdown.call(ctx);
671
- });
730
+ describe("shutdown", function () {
731
+ it(`default timeout, ${notDomain.OPT_DEFAULT_SHUTDOWN_TIMEOUT}ms`, function (done) {
732
+ const realProcess = process;
733
+ const exitMock = () => {
734
+ global.process = realProcess;
735
+ done();
736
+ };
737
+ global.process = { ...realProcess, exit: exitMock };
738
+ const ctx = {
739
+ log(str) {
740
+ expect(str).to.be.equal(
741
+ `Перезагрузка сервиса через ${notDomain.OPT_DEFAULT_SHUTDOWN_TIMEOUT}мс...`
742
+ );
743
+ },
744
+ emit(evName) {
745
+ expect(evName).to.be.equal("app:shutdown");
746
+ },
747
+ };
748
+ notDomain.prototype.shutdown.call(ctx);
749
+ });
672
750
 
673
- it('custom timeout', function(done) {
674
- const TIMEOUT = 1000;
675
- const realProcess = process;
676
- const exitMock = ()=>{
677
- global.process = realProcess;
678
- done();
679
- }
680
- global.process = { ...realProcess, exit: exitMock };
681
- const ctx = {
682
- log(str){
683
- expect(str).to.be.equal(`Перезагрузка сервиса через ${TIMEOUT}мс...`)
684
- },
685
- emit(evName){
686
- expect(evName).to.be.equal('app:shutdown');
687
- }
688
- };
689
- notDomain.prototype.shutdown.call(ctx, TIMEOUT);
751
+ it("custom timeout", function (done) {
752
+ const TIMEOUT = 1000;
753
+ const realProcess = process;
754
+ const exitMock = () => {
755
+ global.process = realProcess;
756
+ done();
757
+ };
758
+ global.process = { ...realProcess, exit: exitMock };
759
+ const ctx = {
760
+ log(str) {
761
+ expect(str).to.be.equal(
762
+ `Перезагрузка сервиса через ${TIMEOUT}мс...`
763
+ );
764
+ },
765
+ emit(evName) {
766
+ expect(evName).to.be.equal("app:shutdown");
767
+ },
768
+ };
769
+ notDomain.prototype.shutdown.call(ctx, TIMEOUT);
770
+ });
690
771
  });
691
- });
692
772
 
693
-
694
- describe('getStatus', function() {
695
- it('ok', function() {
696
- const ctx = {
697
- modules:{
698
- 'not-user':{
699
- getStatus(){
700
- return {
701
- models: {
702
- count: 2,
703
- list: ['User', 'Role'],
704
- content: {}
773
+ describe("getStatus", function () {
774
+ it("ok", function () {
775
+ const ctx = {
776
+ modules: {
777
+ "not-user": {
778
+ getStatus() {
779
+ return {
780
+ models: {
781
+ count: 2,
782
+ list: ["User", "Role"],
783
+ content: {},
784
+ },
785
+ routes: {
786
+ count: 2,
787
+ list: ["user", "role"],
788
+ content: {},
789
+ },
790
+ actions: {
791
+ count: 2,
792
+ list: ["user//list", "role//list"],
793
+ },
794
+ forms: {
795
+ count: 3,
796
+ list: [
797
+ "user//listAll",
798
+ "user//list",
799
+ "role//list",
800
+ ],
801
+ },
802
+ };
803
+ },
804
+ },
805
+ },
806
+ getModule(name) {
807
+ return fModules[name];
808
+ },
809
+ };
810
+ const res = notDomain.prototype.getStatus.call(ctx);
811
+ expect(res).to.be.deep.equal({
812
+ modules: {
813
+ count: 1,
814
+ list: ["not-user"],
815
+ content: {
816
+ "not-user": {
817
+ models: {
818
+ count: 2,
819
+ list: ["User", "Role"],
820
+ content: {},
821
+ },
822
+ routes: {
823
+ count: 2,
824
+ list: ["user", "role"],
825
+ content: {},
826
+ },
827
+ actions: {
828
+ count: 2,
829
+ list: ["user//list", "role//list"],
830
+ },
831
+ forms: {
832
+ count: 3,
833
+ list: [
834
+ "user//listAll",
835
+ "user//list",
836
+ "role//list",
837
+ ],
838
+ },
839
+ },
840
+ },
841
+ },
842
+ forms: {
843
+ count: 3,
844
+ list: [
845
+ "not-user//user//listAll",
846
+ "not-user//user//list",
847
+ "not-user//role//list",
848
+ ],
705
849
  },
706
850
  routes: {
707
- count: 2,
708
- list: ['user', 'role'],
709
- content: {}
851
+ count: 2,
852
+ list: ["not-user//user", "not-user//role"],
853
+ },
854
+ models: {
855
+ count: 2,
856
+ list: ["not-user//User", "not-user//Role"],
710
857
  },
711
858
  actions: {
712
- count: 2,
713
- list: ['user//list', 'role//list']
859
+ count: 2,
860
+ list: ["not-user//user//list", "not-user//role//list"],
714
861
  },
715
- forms: {
716
- count: 3,
717
- list: ['user//listAll', 'user//list', 'role//list']
718
- }
719
- };
720
- }
721
- }
722
- }
723
- };
724
- const res = notDomain.prototype.getStatus.call(ctx);
725
- expect(res).to.be.deep.equal({
726
- modules: {
727
- count: 1,
728
- list: ['not-user'],
729
- content: {
730
- 'not-user':{
731
- models: {
732
- count: 2,
733
- list: ['User', 'Role'],
734
- content: {}
735
- },
736
- routes: {
737
- count: 2,
738
- list: ['user', 'role'],
739
- content: {}
740
- },
741
- actions: {
742
- count: 2,
743
- list: ['user//list', 'role//list']
744
- },
745
- forms: {
746
- count: 3,
747
- list: ['user//listAll', 'user//list', 'role//list']
748
- }
749
- }
750
- }
751
- },
752
- forms: {
753
- count: 3,
754
- list: ['not-user//user//listAll', 'not-user//user//list', 'not-user//role//list']
755
- },
756
- routes: {
757
- count: 2,
758
- list: ["not-user//user","not-user//role"]
759
- },
760
- models: {
761
- count: 2,
762
- list: ['not-user//User', 'not-user//Role']
763
- },
764
- actions: {
765
- count: 2,
766
- list: ['not-user//user//list', 'not-user//role//list']
767
- },
768
- roles: {
769
- count: 0,
770
- list: []
771
- },
772
- });
862
+ roles: {
863
+ count: 0,
864
+ list: [],
865
+ },
866
+ });
867
+ });
773
868
  });
774
-
775
- });
776
-
777
869
  });