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/notModule.js CHANGED
@@ -1,661 +1,706 @@
1
- const path = require('path');
2
- const expect = require('chai').expect,
3
- notModule = require('../src/manifest/module'),
4
- notManifest = require('../src/manifest/manifest'),
5
- mongoose = require('mongoose'),
6
- modulePath = __dirname + '/testies/module',
7
- {
8
- MongoMemoryServer
9
- } = require('mongodb-memory-server');
1
+ const path = require("path");
2
+ const expect = require("chai").expect,
3
+ notModule = require("../src/manifest/module"),
4
+ notManifest = require("../src/manifest/manifest"),
5
+ mongoose = require("mongoose"),
6
+ modulePath = __dirname + "/testies/module",
7
+ { MongoMemoryServer } = require("mongodb-memory-server");
10
8
 
11
9
  const moduleManifest = {
12
- 'file': {
13
- model: 'file',
14
- url: '/api/:modelName',
15
- actions: {
16
- list: {
17
- method: 'get'
18
- }
19
- }
20
- }
10
+ file: {
11
+ model: "file",
12
+ url: "/api/:modelName",
13
+ actions: {
14
+ list: {
15
+ method: "get",
16
+ },
17
+ },
18
+ },
21
19
  };
22
20
 
23
21
  var mongod = null;
24
22
 
25
- describe('notModule', function() {
26
- before(async () => {
27
- mongod = await MongoMemoryServer.create();
28
- let uri = mongod.getUri();
29
- await mongoose.connect(uri);
30
- });
31
-
32
- describe('constructor', function() {
33
- it('With init from path: ' + modulePath, function() {
34
- var mod = new notModule({
35
- modPath: modulePath,
36
- mongoose: mongoose,
37
- fields:{}
38
- });
39
- mod.fabricateModels();
40
- expect(mod.faulty).to.deep.equal(false);
41
- expect(mod.path).to.deep.equal(modulePath);
42
- expect(mod.models).to.have.any.keys(['UserLocal']);
43
- expect(mod.routes).to.have.keys(['file', 'icon']);
44
- let model = mod.getModel('UserLocal');
45
- expect(model).to.be.ok;
46
- });
47
-
48
- it('With init from module', function() {
49
- var mod = new notModule({
50
- modObject: require('./testies/module'),
51
- mongoose: mongoose
52
- });
53
- expect(mod.faulty).to.deep.equal(false);
54
- expect(mod.models).to.have.any.keys(['UserLocal']);
55
- expect(mod.routes).to.have.keys(['file', 'icon']);
56
- expect(mod.getModel('UserLocal')).to.be.ok;
23
+ describe("notModule", function () {
24
+ before(async () => {
25
+ mongod = await MongoMemoryServer.create();
26
+ let uri = mongod.getUri();
27
+ await mongoose.connect(uri);
57
28
  });
58
- });
59
29
 
60
-
61
- describe('init', ()=>{
62
- it('path is not set, module is not set', ()=>{
63
- const ctx = {
64
- path: false,
65
- module: null
66
- };
67
- const res = notModule.prototype.init.call(ctx);
68
- expect(res).to.be.equal(false);
69
- });
70
-
71
- it('path is not set, module is not set', ()=>{
72
- const ctx = {
73
- path: false,
74
- module: {},
75
- initFromModule(){},
76
- appIsSet(){return true;},
77
- notApp:{
78
- getModel(){},
79
- getModelFile(){},
80
- getModelSchema(){},
81
- getLogic(){},
82
- getLogicFile(){},
83
- getModule(){},
84
- }
85
- };
86
- notModule.prototype.init.call(ctx);
87
- expect(typeof ctx.module.getModel).to.be.equal('function');
88
- expect(typeof ctx.module.getModelFile).to.be.equal('function');
89
- expect(typeof ctx.module.getModelSchema).to.be.equal('function');
90
- });
91
- });
92
-
93
- describe('getManifest', function() {
94
- it('Get module manifest without params', function(done) {
95
- const ctx = {
96
- manifests: {
97
- some: 'fest'
98
- },
99
- manifest: {
100
- filterManifest(collection, auth, role, root) {
101
- expect(collection).to.deep.equal({
102
- some: 'fest'
30
+ describe("constructor", function () {
31
+ it("With init from path: " + modulePath, function () {
32
+ var mod = new notModule({
33
+ modPath: modulePath,
34
+ mongoose: mongoose,
35
+ fields: {},
103
36
  });
104
- expect(auth).to.be.false;
105
- expect(role).to.be.equal('guest');
106
- expect(root).to.be.false;
107
- done()
108
- }
109
- }
110
- }
111
- notModule.prototype.getManifest.call(ctx);
112
- });
113
-
114
- it('Get module manifest, with params', function(done) {
115
- const prms = {
116
- auth: true,
117
- role: 'manager',
118
- root: false
119
- };
120
- const ctx = {
121
- manifests: {
122
- some: 'fest'
123
- },
124
- manifest: {
125
- filterManifest(collection, auth, role, root) {
126
- expect(collection).to.deep.equal({
127
- some: 'fest'
37
+ //mod.fabricateModels();
38
+ expect(mod.faulty).to.deep.equal(false);
39
+ expect(mod.path).to.deep.equal(modulePath);
40
+ expect(mod.models).to.have.any.keys(["UserLocal"]);
41
+ expect(mod.routes).to.have.keys(["file", "icon"]);
42
+ let model = mod.getModel("UserLocal");
43
+ expect(model).to.be.ok;
44
+ });
45
+
46
+ it("With init from module", function () {
47
+ var mod = new notModule({
48
+ modObject: require("./testies/module"),
49
+ mongoose: mongoose,
128
50
  });
129
- expect(auth).to.be.true;
130
- expect(role).to.be.equal('manager');
131
- expect(root).to.be.false;
132
- done()
133
- }
134
- }
135
- }
136
- notModule.prototype.getManifest.call(ctx, prms);
137
- });
138
- });
139
-
140
- describe('getModuleName', function() {
141
- it('Get module name from module.exports.name', function() {
142
- const ctx = {
143
- module: {
144
- name: 'fake my name'
145
- }
146
- }
147
- expect(notModule.prototype.getName.call(ctx)).to.be.equal('fake my name');
148
- });
149
-
150
- it('no module.name, no path', function() {
151
- const ctx = {
152
- module: {}
153
- }
154
- expect(notModule.prototype.getName.call(ctx)).to.be.undefined;
155
- });
156
- });
157
-
158
-
159
- describe('expose', function() {
160
- it('!manifests', function() {
161
- const ctx = {
162
- manifests:{},
163
- initManifest(){
164
- this.manifest = {
165
- registerRoutes(){}
166
- };
167
- },
168
- fabricateModels(){}
169
- };
170
- notModule.prototype.expose.call(ctx, false, 'moduleName');
171
- });
172
-
173
- it('manifests', function() {
174
- const ctx = {
175
- manifests:{},
176
- initManifest(){
177
- this.manifest = {
178
- registerRoutes(){}
179
- };
180
- },
181
- fabricateModels(){}
182
- };
183
- notModule.prototype.expose.call(ctx, {}, 'moduleName');
184
- });
185
- });
186
-
187
-
188
- describe('initManifest', function() {
189
- it('plain', function() {
190
- const ctx = {
191
- notApp:{}
192
- };
193
- notModule.prototype.initManifest.call(ctx, true, 'moduleName');
194
- expect(ctx.manifest).to.be.instanceof(notManifest);
195
- });
196
- });
197
-
198
-
199
- describe('initFromPath', function() {
200
- it('modPath is points to a directory, require failed', function() {
201
- const mod = new notModule({
202
- modPath: path.join(__dirname, 'testies/badmodule'),
203
- mongoose: mongoose
204
- });
205
- expect(mod.faulty).to.be.true;
206
- });
207
-
208
- it('modPath is points to a file, require failed', function() {
209
- const mod = new notModule({
210
- modPath: path.join(__dirname, 'testies/module/index.js'),
211
- mongoose: mongoose
212
- });
213
- expect(mod.faulty).to.be.false;
214
- });
215
- });
216
-
217
- describe('initFromModule', function() {
218
- it('throws', function() {
219
- const mod = new notModule({
220
- modPath: path.join(__dirname, 'testies/badmodule'),
221
- mongoose: mongoose
222
- });
223
- mod.registerContent = () => {
224
- throw new Error('Some error!');
225
- }
226
- mod.initFromModule();
227
- expect(mod.faulty).to.be.true;
228
- });
229
- });
230
-
231
- describe('getApp', function() {
232
- it('get', function() {
233
- const ctx = {
234
- notApp: '123123'
235
- };
236
- expect(notModule.prototype.getApp.call(ctx)).to.be.equal('123123');
237
- });
238
- });
239
-
240
-
241
- describe('getName', function() {
242
- it('get', function() {
243
- const ctx = {
244
- module: {
245
- name: '123123'
246
- }
247
- };
248
- expect(notModule.prototype.getName.call(ctx)).to.be.equal('123123');
249
- });
250
- });
251
-
252
-
253
-
254
- describe('getEndPoints', function() {
255
- it('get', function() {
256
- const ctx = {
257
- routesWS: {
258
- name: '123123'
259
- }
260
- };
261
- expect(notModule.prototype.getEndPoints.call(ctx)).to.be.deep.equal({
262
- name: '123123'
263
- });
264
- });
265
- });
266
-
267
- describe('getRoute', function() {
268
- it('exists', function() {
269
- const ctx = {
270
- routes: {
271
- someRoute: '123123'
272
- }
273
- };
274
- expect(notModule.prototype.getRoute.call(ctx, 'someRoute')).to.be.equal('123123');
275
- });
276
- it('doesnt exists', function() {
277
- const ctx = {
278
- routes: {}
279
- };
280
- expect(notModule.prototype.getRoute.call(ctx, 'someRoute')).to.be.null;
281
- });
282
- });
283
-
284
-
285
- describe('getLogic', function() {
286
- it('exists', function() {
287
- const ctx = {
288
- getLogicFile(){
289
- return {
290
- LogicUnit:{t:'123123'}
291
- };
292
- }
293
- };
294
- expect(notModule.prototype.getLogic.call(ctx, 'LogicUnit')).to.be.deep.equal({t:'123123'});
295
- });
296
- it('doesnt exists', function() {
297
- const ctx = {
298
- getLogicFile(){
299
- return {};
300
- }
301
- };
302
- expect(notModule.prototype.getLogic.call(ctx, 'LogicUnit')).to.be.null;
303
- });
304
- });
305
-
306
-
307
- describe('getLogicFile', function() {
308
- it('exists', function() {
309
- const ctx = {
310
- logics: {
311
- LogicUnit:{t:'123123'}
312
- }
313
- };
314
- expect(notModule.prototype.getLogicFile.call(ctx, 'LogicUnit')).to.be.deep.equal({t:'123123'});
315
- });
316
-
317
- it('doesnt exists', function() {
318
- const ctx = {
319
- logics: {}
320
- };
321
- expect(notModule.prototype.getLogicFile.call(ctx, 'LogicUnit')).to.be.null;
322
- });
323
- });
324
-
325
-
326
- describe('getModelSchema', function() {
327
- it('exists', function() {
328
- const ctx = {
329
- getModelFile(){
330
- return { modelName: '123123', thisSchema: {} };
331
- }
332
- };
333
- expect(notModule.prototype.getModelSchema.call(ctx, 'modelName')).to.be.deep.equal({});
334
- });
335
-
336
- it('file doesnt exists', function() {
337
- const ctx = {
338
- getModelFile(){
339
- return false;
340
- }
341
- };
342
- expect(notModule.prototype.getModelSchema.call(ctx, 'modelName')).to.be.null;
343
- });
344
-
345
- it('exists', function() {
346
- const ctx = {
347
- getModelFile(){
348
- return {};
349
- }
350
- };
351
- expect(notModule.prototype.getModelSchema.call(ctx, 'modelName')).to.be.null;
352
- });
353
- });
354
-
355
- describe('getModel', function() {
356
- it('exists', function() {
357
- const ctx = {
358
- getModelFile(){
359
- return { modelName: '123123', thisSchema: {} };
360
- }
361
- };
362
- expect(notModule.prototype.getModel.call(ctx, 'modelName')).to.be.deep.equal('123123');
363
- });
364
-
365
- it('file doesnt exists', function() {
366
- const ctx = {
367
- getModelFile(){
368
- return false;
369
- }
370
- };
371
- expect(notModule.prototype.getModel.call(ctx, 'modelName')).to.be.null;
372
- });
373
-
374
- it('exists', function() {
375
- const ctx = {
376
- getModelFile(){
377
- return {};
378
- }
379
- };
380
- expect(notModule.prototype.getModel.call(ctx, 'modelName')).to.be.null;
381
- });
382
- });
383
-
384
- describe('getModelFile', function() {
385
- it('exists', function() {
386
- const ctx = {
387
- models: {
388
- modelName: {g: 12}
389
- }
390
- };
391
- expect(notModule.prototype.getModelFile.call(ctx, 'modelName')).to.be.deep.equal({g: 12});
392
- });
393
-
394
- it('file doesnt exists', function() {
395
- const ctx = {
396
- models: {}
397
- };
398
- expect(notModule.prototype.getModelFile.call(ctx, 'modelName')).to.be.null;
399
- });
400
-
401
- });
402
-
403
- describe('getModelsStatuses', function() {
404
- it('exists', function() {
405
- const ctx = {
406
- models: {
407
- user: '123123'
408
- },
409
- getModelSchema() {
410
- return '321321';
411
- }
412
- };
413
- expect(notModule.prototype.getModelsStatuses.call(ctx)).to.be.deep.equal({
414
- user: '321321'
415
- });
416
- });
417
- });
418
-
419
- describe('getRoutesStatuses', function() {
420
- it('exists', function() {
421
- const ctx = {
422
- manifests: {
423
- user: {
424
- actions: {
425
- legacy: {}
426
- }
427
- },
428
- client: {}
429
- }
430
- };
431
- expect(notModule.prototype.getRoutesStatuses.call(ctx)).to.be.deep.equal({
432
- user: {
433
- legacy: {}
434
- }
435
- });
436
- });
437
- });
438
-
439
- //getActionsList
440
- describe('getActionsList', function() {
441
- it('exists', function() {
442
- const ctx = {
443
- manifests: {
444
- user: {
445
- actions: {
446
- legacy: {}
447
- }
448
- },
449
- client: {}
450
- }
451
- };
452
- expect(notModule.prototype.getActionsList.call(ctx)).to.be.deep.equal([
453
- 'user//legacy'
454
- ]);
455
- });
456
- });
457
- //getStatus
458
-
459
- describe('getStatus', function() {
460
- it('exists', function() {
461
- const ctx = {
462
- getActionsList() {
463
- return ['route//action'];
464
- },
465
- models: {
466
- userModel: {}
467
- },
468
- routes: {
469
- userRoute: {}
470
- },
471
- forms: {
472
- 'route//action':{}
473
- },
474
- getModelsStatuses() {
475
- return {
476
- user: {
477
- name: 'UserModel'
478
- }
479
- };
480
- },
481
- getRoutesStatuses() {
482
- return {
483
- user: {
484
- name: 'UserRoute'
485
- }
486
- };
487
- },
488
- };
489
- expect(notModule.prototype.getStatus.call(ctx)).to.be.deep.equal({
490
- models: {
491
- count: 1,
492
- list: ['userModel'],
493
- content: {
494
- user: {
495
- name: 'UserModel'
496
- }
497
- }
498
- },
499
- routes: {
500
- count: 1,
501
- list: ['userRoute'],
502
- content: {
503
- user: {
504
- name: 'UserRoute'
505
- }
506
- }
507
- },
508
- actions: {
509
- count: 1,
510
- list: ['route//action']
511
- },
512
- forms: {
513
- count: 1,
514
- list: ['route//action']
515
- }
516
- });
517
- });
518
- });
519
- //exec
520
-
521
- describe('exec', function() {
522
- it('!this.module', async() => {
523
- const ctx = {
524
- module: false,
525
- path: 'modPath'
526
- };
527
- const res = await notModule.prototype.exec.call(ctx);
528
- expect(res).to.be.false;
529
- });
530
-
531
- it('this.module; !methodName', async() => {
532
- const ctx = {
533
- module: {},
534
- path: 'modPath'
535
- };
536
- const res = await notModule.prototype.exec.call(ctx, 'methodName');
537
- expect(res).to.be.false;
538
- });
539
-
540
- it('this.module; methodName; sync', async() => {
541
- const ctx = {
542
- module: {
543
- methodName(){}
544
- },
545
- path: 'modPath'
546
- };
547
- const res = await notModule.prototype.exec.call(ctx, 'methodName');
548
- expect(res).to.be.true;
549
- });
550
-
551
- it('this.module; methodName; async', async() => {
552
- const ctx = {
553
- module: {
554
- async methodName(){}
555
- },
556
- path: 'modPath'
557
- };
558
- const res = await notModule.prototype.exec.call(ctx, 'methodName');
559
- expect(res).to.be.true;
560
- });
561
-
562
- it('this.module; methodName; sync throwed', async() => {
563
- const ctx = {
564
- module: {
565
- methodName(){throw new Error('error');}
566
- },
567
- path: 'modPath'
568
- };
569
- const res = await notModule.prototype.exec.call(ctx, 'methodName');
570
- expect(res).to.be.false;
571
- });
572
-
51
+ expect(mod.faulty).to.deep.equal(false);
52
+ expect(mod.models).to.have.any.keys(["UserLocal"]);
53
+ expect(mod.routes).to.have.keys(["file", "icon"]);
54
+ expect(mod.getModel("UserLocal")).to.be.ok;
55
+ });
56
+ });
57
+
58
+ describe("init", () => {
59
+ it("path is not set, module is not set", () => {
60
+ const ctx = {
61
+ path: false,
62
+ module: null,
63
+ };
64
+ const res = notModule.prototype.init.call(ctx);
65
+ expect(res).to.be.equal(false);
66
+ });
67
+
68
+ it("path is not set, module is not set", () => {
69
+ const ctx = {
70
+ path: false,
71
+ module: {},
72
+ initFromModule() {},
73
+ appIsSet() {
74
+ return true;
75
+ },
76
+ notApp: {
77
+ getModel() {},
78
+ getModelFile() {},
79
+ getModelSchema() {},
80
+ getLogic() {},
81
+ getLogicFile() {},
82
+ getModule() {},
83
+ },
84
+ };
85
+ notModule.prototype.init.call(ctx);
86
+ expect(typeof ctx.module.getModel).to.be.equal("function");
87
+ expect(typeof ctx.module.getModelFile).to.be.equal("function");
88
+ expect(typeof ctx.module.getModelSchema).to.be.equal("function");
89
+ });
90
+ });
91
+
92
+ describe("getManifest", function () {
93
+ it("Get module manifest without params", function (done) {
94
+ const ctx = {
95
+ manifests: {
96
+ some: "fest",
97
+ },
98
+ manifest: {
99
+ filterManifest(collection, auth, role, root) {
100
+ expect(collection).to.deep.equal({
101
+ some: "fest",
102
+ });
103
+ expect(auth).to.be.false;
104
+ expect(role).to.be.equal("guest");
105
+ expect(root).to.be.false;
106
+ done();
107
+ },
108
+ },
109
+ };
110
+ notModule.prototype.getManifest.call(ctx);
111
+ });
112
+
113
+ it("Get module manifest, with params", function (done) {
114
+ const prms = {
115
+ auth: true,
116
+ role: "manager",
117
+ root: false,
118
+ };
119
+ const ctx = {
120
+ manifests: {
121
+ some: "fest",
122
+ },
123
+ manifest: {
124
+ filterManifest(collection, auth, role, root) {
125
+ expect(collection).to.deep.equal({
126
+ some: "fest",
127
+ });
128
+ expect(auth).to.be.true;
129
+ expect(role).to.be.equal("manager");
130
+ expect(root).to.be.false;
131
+ done();
132
+ },
133
+ },
134
+ };
135
+ notModule.prototype.getManifest.call(ctx, prms);
136
+ });
137
+ });
138
+
139
+ describe("getModuleName", function () {
140
+ it("Get module name from module.exports.name", function () {
141
+ const ctx = {
142
+ module: {
143
+ name: "fake my name",
144
+ },
145
+ };
146
+ expect(notModule.prototype.getName.call(ctx)).to.be.equal(
147
+ "fake my name"
148
+ );
149
+ });
150
+
151
+ it("no module.name, no path", function () {
152
+ const ctx = {
153
+ module: {},
154
+ };
155
+ expect(notModule.prototype.getName.call(ctx)).to.be.undefined;
156
+ });
157
+ });
158
+
159
+ describe("expose", function () {
160
+ it("!manifests", function () {
161
+ const ctx = {
162
+ manifests: {},
163
+ initManifest() {
164
+ this.manifest = {
165
+ registerRoutes() {},
166
+ };
167
+ },
168
+ fabricateModels() {},
169
+ };
170
+ notModule.prototype.expose.call(ctx, false, "moduleName");
171
+ });
172
+
173
+ it("manifests", function () {
174
+ const ctx = {
175
+ manifests: {},
176
+ initManifest() {
177
+ this.manifest = {
178
+ registerRoutes() {},
179
+ };
180
+ },
181
+ };
182
+ notModule.prototype.expose.call(ctx, {}, "moduleName");
183
+ });
184
+ });
185
+
186
+ describe("initManifest", function () {
187
+ it("plain", function () {
188
+ const ctx = {
189
+ notApp: {},
190
+ };
191
+ notModule.prototype.initManifest.call(ctx, true, "moduleName");
192
+ expect(ctx.manifest).to.be.instanceof(notManifest);
193
+ });
194
+ });
195
+
196
+ describe("initFromPath", function () {
197
+ it("modPath is points to a directory, require failed", function () {
198
+ const mod = new notModule({
199
+ modPath: path.join(__dirname, "testies/badmodule"),
200
+ mongoose: mongoose,
201
+ });
202
+ expect(mod.faulty).to.be.true;
203
+ });
573
204
 
574
- it('this.module; methodName; async throwed', async() => {
575
- const ctx = {
576
- module: {
577
- async methodName(){throw new Error('error');}
578
- },
579
- path: 'modPath'
580
- };
581
- const res = await notModule.prototype.exec.call(ctx, 'methodName');
582
- expect(res).to.be.false;
583
- });
584
- });
585
-
586
- describe('createEmptyIfNotExistsRouteWSType', function() {
587
- it('collection and end-point type not exists', function() {
588
- const ctx = {
589
- routesWS: {
590
- servers: {}
591
- }
592
- };
593
- notModule.prototype.createEmptyIfNotExistsRouteWSType.call(ctx, {
594
- collectionType: 'servers',
595
- collectionName: 'unit',
596
- endPointType: 'request'
597
- });
598
- expect(ctx.routesWS.servers.unit).to.be.ok;
599
- expect(ctx.routesWS.servers.unit.request).to.be.ok;
205
+ it("modPath is points to a file, require failed", function () {
206
+ const mod = new notModule({
207
+ modPath: path.join(__dirname, "testies/module/index.js"),
208
+ mongoose: mongoose,
209
+ });
210
+ expect(mod.faulty).to.be.false;
211
+ });
600
212
  });
601
213
 
602
- it('collection and end-point type exists', function() {
603
- const ctx = {
604
- routesWS: {
605
- servers: {
606
- unit: {
607
- request: {}
214
+ describe("initFromModule", function () {
215
+ it("throws", function () {
216
+ const mod = new notModule({
217
+ modPath: path.join(__dirname, "testies/badmodule"),
218
+ mongoose: mongoose,
219
+ });
220
+ mod.registerContent = () => {
221
+ throw new Error("Some error!");
222
+ };
223
+ mod.initFromModule();
224
+ expect(mod.faulty).to.be.true;
225
+ });
226
+ });
227
+
228
+ describe("getApp", function () {
229
+ it("get", function () {
230
+ const ctx = {
231
+ notApp: "123123",
232
+ };
233
+ expect(notModule.prototype.getApp.call(ctx)).to.be.equal("123123");
234
+ });
235
+ });
236
+
237
+ describe("getName", function () {
238
+ it("get", function () {
239
+ const ctx = {
240
+ module: {
241
+ name: "123123",
242
+ },
243
+ };
244
+ expect(notModule.prototype.getName.call(ctx)).to.be.equal("123123");
245
+ });
246
+ });
247
+
248
+ describe("getEndPoints", function () {
249
+ it("get", function () {
250
+ const ctx = {
251
+ routesWS: {
252
+ name: "123123",
253
+ },
254
+ };
255
+ expect(notModule.prototype.getEndPoints.call(ctx)).to.be.deep.equal(
256
+ {
257
+ name: "123123",
258
+ }
259
+ );
260
+ });
261
+ });
262
+
263
+ describe("getRoute", function () {
264
+ it("exists", function () {
265
+ const ctx = {
266
+ routes: {
267
+ someRoute: "123123",
268
+ },
269
+ };
270
+ expect(
271
+ notModule.prototype.getRoute.call(ctx, "someRoute")
272
+ ).to.be.equal("123123");
273
+ });
274
+ it("doesnt exists", function () {
275
+ const ctx = {
276
+ routes: {},
277
+ };
278
+ expect(notModule.prototype.getRoute.call(ctx, "someRoute")).to.be
279
+ .null;
280
+ });
281
+ });
282
+
283
+ describe("getLogic", function () {
284
+ it("exists", function () {
285
+ const ctx = {
286
+ getLogicFile() {
287
+ return {
288
+ LogicUnit: { t: "123123" },
289
+ };
290
+ },
291
+ };
292
+ expect(
293
+ notModule.prototype.getLogic.call(ctx, "LogicUnit")
294
+ ).to.be.deep.equal({ t: "123123" });
295
+ });
296
+ it("doesnt exists", function () {
297
+ const ctx = {
298
+ getLogicFile() {
299
+ return {};
300
+ },
301
+ };
302
+ expect(notModule.prototype.getLogic.call(ctx, "LogicUnit")).to.be
303
+ .null;
304
+ });
305
+ });
306
+
307
+ describe("getLogicFile", function () {
308
+ it("exists", function () {
309
+ const ctx = {
310
+ logics: {
311
+ LogicUnit: { t: "123123" },
312
+ },
313
+ };
314
+ expect(
315
+ notModule.prototype.getLogicFile.call(ctx, "LogicUnit")
316
+ ).to.be.deep.equal({ t: "123123" });
317
+ });
318
+
319
+ it("doesnt exists", function () {
320
+ const ctx = {
321
+ logics: {},
322
+ };
323
+ expect(notModule.prototype.getLogicFile.call(ctx, "LogicUnit")).to
324
+ .be.null;
325
+ });
326
+ });
327
+
328
+ describe("getModelSchema", function () {
329
+ it("exists", function () {
330
+ const ctx = {
331
+ getModelFile() {
332
+ return { modelName: "123123", thisSchema: {} };
333
+ },
334
+ };
335
+ expect(
336
+ notModule.prototype.getModelSchema.call(ctx, "modelName")
337
+ ).to.be.deep.equal({});
338
+ });
339
+
340
+ it("file doesnt exists", function () {
341
+ const ctx = {
342
+ getModelFile() {
343
+ return false;
344
+ },
345
+ };
346
+ expect(notModule.prototype.getModelSchema.call(ctx, "modelName")).to
347
+ .be.null;
348
+ });
349
+
350
+ it("exists", function () {
351
+ const ctx = {
352
+ getModelFile() {
353
+ return {};
354
+ },
355
+ };
356
+ expect(notModule.prototype.getModelSchema.call(ctx, "modelName")).to
357
+ .be.null;
358
+ });
359
+ });
360
+
361
+ describe("getModel", function () {
362
+ it("exists", function () {
363
+ const ctx = {
364
+ getModelFile() {
365
+ return { modelName: "123123", thisSchema: {} };
366
+ },
367
+ };
368
+ expect(
369
+ notModule.prototype.getModel.call(ctx, "modelName")
370
+ ).to.be.deep.equal("123123");
371
+ });
372
+
373
+ it("file doesnt exists", function () {
374
+ const ctx = {
375
+ getModelFile() {
376
+ return false;
377
+ },
378
+ };
379
+ expect(notModule.prototype.getModel.call(ctx, "modelName")).to.be
380
+ .null;
381
+ });
382
+
383
+ it("exists", function () {
384
+ const ctx = {
385
+ getModelFile() {
386
+ return {};
387
+ },
388
+ };
389
+ expect(notModule.prototype.getModel.call(ctx, "modelName")).to.be
390
+ .null;
391
+ });
392
+ });
393
+
394
+ describe("getModelFile", function () {
395
+ it("exists", function () {
396
+ const ctx = {
397
+ models: {
398
+ modelName: { g: 12 },
399
+ },
400
+ };
401
+ expect(
402
+ notModule.prototype.getModelFile.call(ctx, "modelName")
403
+ ).to.be.deep.equal({ g: 12 });
404
+ });
405
+
406
+ it("file doesnt exists", function () {
407
+ const ctx = {
408
+ models: {},
409
+ };
410
+ expect(notModule.prototype.getModelFile.call(ctx, "modelName")).to
411
+ .be.null;
412
+ });
413
+ });
414
+
415
+ describe("getModelsStatuses", function () {
416
+ it("exists", function () {
417
+ const ctx = {
418
+ models: {
419
+ user: "123123",
420
+ },
421
+ getModelSchema() {
422
+ return "321321";
423
+ },
424
+ };
425
+ expect(
426
+ notModule.prototype.getModelsStatuses.call(ctx)
427
+ ).to.be.deep.equal({
428
+ user: "321321",
429
+ });
430
+ });
431
+ });
432
+
433
+ describe("getRoutesStatuses", function () {
434
+ it("exists", function () {
435
+ const ctx = {
436
+ manifests: {
437
+ user: {
438
+ actions: {
439
+ legacy: {},
440
+ },
441
+ },
442
+ client: {},
443
+ },
444
+ };
445
+ expect(
446
+ notModule.prototype.getRoutesStatuses.call(ctx)
447
+ ).to.be.deep.equal({
448
+ user: {
449
+ legacy: {},
450
+ },
451
+ });
452
+ });
453
+ });
454
+
455
+ //getActionsList
456
+ describe("getActionsList", function () {
457
+ it("exists", function () {
458
+ const ctx = {
459
+ manifests: {
460
+ user: {
461
+ actions: {
462
+ legacy: {},
463
+ },
464
+ },
465
+ client: {},
466
+ },
467
+ };
468
+ expect(
469
+ notModule.prototype.getActionsList.call(ctx)
470
+ ).to.be.deep.equal(["user//legacy"]);
471
+ });
472
+ });
473
+ //getStatus
474
+
475
+ describe("getStatus", function () {
476
+ it("exists", function () {
477
+ const ctx = {
478
+ getActionsList() {
479
+ return ["route//action"];
480
+ },
481
+ models: {
482
+ userModel: {},
483
+ },
484
+ fields: {
485
+ timetracker: { ui: true },
486
+ },
487
+ routes: {
488
+ userRoute: {},
489
+ },
490
+ forms: {
491
+ "route//action": {},
492
+ },
493
+ getModelsStatuses() {
494
+ return {
495
+ user: {
496
+ name: "UserModel",
497
+ },
498
+ };
499
+ },
500
+ getRoutesStatuses() {
501
+ return {
502
+ user: {
503
+ name: "UserRoute",
504
+ },
505
+ };
506
+ },
507
+ };
508
+ expect(notModule.prototype.getStatus.call(ctx)).to.be.deep.equal({
509
+ models: {
510
+ count: 1,
511
+ list: ["userModel"],
512
+ content: {
513
+ user: {
514
+ name: "UserModel",
515
+ },
516
+ },
517
+ },
518
+ routes: {
519
+ count: 1,
520
+ list: ["userRoute"],
521
+ content: {
522
+ user: {
523
+ name: "UserRoute",
524
+ },
525
+ },
526
+ },
527
+ actions: {
528
+ count: 1,
529
+ list: ["route//action"],
530
+ },
531
+ forms: {
532
+ count: 1,
533
+ list: ["route//action"],
534
+ },
535
+ fields: {
536
+ count: 1,
537
+ list: ["timetracker"],
538
+ },
539
+ });
540
+ });
541
+ });
542
+ //exec
543
+
544
+ describe("exec", function () {
545
+ it("!this.module", async () => {
546
+ const ctx = {
547
+ module: false,
548
+ path: "modPath",
549
+ };
550
+ const res = await notModule.prototype.exec.call(ctx);
551
+ expect(res).to.be.false;
552
+ });
553
+
554
+ it("this.module; !methodName", (done) => {
555
+ const ctx = {
556
+ module: {},
557
+ path: "modPath",
558
+ };
559
+ notModule.prototype.exec
560
+ .call(ctx, "methodName")
561
+ .then(() => {
562
+ done();
563
+ })
564
+ .catch(done);
565
+ });
566
+
567
+ it("this.module; methodName; sync", async () => {
568
+ let res;
569
+ const ctx = {
570
+ module: {
571
+ methodName() {
572
+ res = true;
573
+ },
574
+ },
575
+ path: "modPath",
576
+ };
577
+ await notModule.prototype.exec.call(ctx, "methodName");
578
+ expect(res).to.be.true;
579
+ });
580
+
581
+ it("this.module; methodName; async", async () => {
582
+ let res;
583
+ const ctx = {
584
+ module: {
585
+ async methodName() {
586
+ res = true;
587
+ },
588
+ },
589
+ path: "modPath",
590
+ };
591
+ await notModule.prototype.exec.call(ctx, "methodName");
592
+ expect(res).to.be.true;
593
+ });
594
+
595
+ it("this.module; methodName; sync throwed", async () => {
596
+ const ctx = {
597
+ module: {
598
+ methodName() {
599
+ throw new Error("error");
600
+ },
601
+ },
602
+ path: "modPath",
603
+ };
604
+ try {
605
+ await notModule.prototype.exec.call(ctx, "methodName");
606
+ throw new Error("No error");
607
+ } catch (e) {
608
+ expect(e).to.be.instanceOf(Error);
609
+ expect(e.message).to.be.equal("error");
608
610
  }
609
- }
610
- }
611
- };
612
- notModule.prototype.createEmptyIfNotExistsRouteWSType.call(ctx, {
613
- collectionType: 'servers',
614
- collectionName: 'unit',
615
- endPointType: 'request'
616
- });
617
- expect(ctx.routesWS.servers.unit).to.be.ok;
618
- expect(ctx.routesWS.servers.unit.request).to.be.ok;
619
- });
620
-
621
- });
622
-
623
-
624
- describe('setRouteWS', function() {
625
- it('collection and end-point type not exists', function() {
626
- const ctx = {
627
- routesWS: {
628
- servers: {
629
- unit: {
630
- request: {}
611
+ });
612
+
613
+ it("this.module; methodName; async throwed", async () => {
614
+ const ctx = {
615
+ module: {
616
+ async methodName() {
617
+ throw new Error("error");
618
+ },
619
+ },
620
+ path: "modPath",
621
+ };
622
+ try {
623
+ await notModule.prototype.exec.call(ctx, "methodName");
624
+ throw new Error("No error");
625
+ } catch (e) {
626
+ expect(e).to.be.instanceOf(Error);
627
+ expect(e.message).to.be.equal("error");
631
628
  }
632
- }
633
- }
634
- };
635
- const param = {
636
- collectionType: 'servers',
637
- collectionName: 'unit',
638
- endPointType: 'request',
639
- wsRouteName: 'route',
640
- action: 'action',
641
- func: () => {}
642
- };
643
- notModule.prototype.setRouteWS.call(ctx, param);
644
- expect(ctx.routesWS.servers.unit).to.be.ok;
645
- expect(ctx.routesWS.servers.unit.request).to.be.ok;
646
- expect(typeof ctx.routesWS.servers.unit.request[`${param.wsRouteName}//${param.action}`]).to.be.equal('function');
629
+ });
630
+ });
631
+
632
+ describe("createEmptyIfNotExistsRouteWSType", function () {
633
+ it("collection and end-point type not exists", function () {
634
+ const ctx = {
635
+ routesWS: {
636
+ servers: {},
637
+ },
638
+ };
639
+ notModule.prototype.createEmptyIfNotExistsRouteWSType.call(ctx, {
640
+ collectionType: "servers",
641
+ collectionName: "unit",
642
+ endPointType: "request",
643
+ });
644
+ expect(ctx.routesWS.servers.unit).to.be.ok;
645
+ expect(ctx.routesWS.servers.unit.request).to.be.ok;
646
+ });
647
+
648
+ it("collection and end-point type exists", function () {
649
+ const ctx = {
650
+ routesWS: {
651
+ servers: {
652
+ unit: {
653
+ request: {},
654
+ },
655
+ },
656
+ },
657
+ };
658
+ notModule.prototype.createEmptyIfNotExistsRouteWSType.call(ctx, {
659
+ collectionType: "servers",
660
+ collectionName: "unit",
661
+ endPointType: "request",
662
+ });
663
+ expect(ctx.routesWS.servers.unit).to.be.ok;
664
+ expect(ctx.routesWS.servers.unit.request).to.be.ok;
665
+ });
666
+ });
667
+
668
+ describe("setRouteWS", function () {
669
+ it("collection and end-point type not exists", function () {
670
+ const ctx = {
671
+ routesWS: {
672
+ servers: {
673
+ unit: {
674
+ request: {},
675
+ },
676
+ },
677
+ },
678
+ };
679
+ const param = {
680
+ collectionType: "servers",
681
+ collectionName: "unit",
682
+ endPointType: "request",
683
+ wsRouteName: "route",
684
+ action: "action",
685
+ func: () => {},
686
+ };
687
+ notModule.prototype.setRouteWS.call(ctx, param);
688
+ expect(ctx.routesWS.servers.unit).to.be.ok;
689
+ expect(ctx.routesWS.servers.unit.request).to.be.ok;
690
+ expect(
691
+ typeof ctx.routesWS.servers.unit.request[
692
+ `${param.wsRouteName}//${param.action}`
693
+ ]
694
+ ).to.be.equal("function");
695
+ });
696
+ });
697
+
698
+ require("./module")({
699
+ expect,
700
+ });
701
+
702
+ after(async () => {
703
+ await mongoose.disconnect();
704
+ await mongod.stop();
647
705
  });
648
-
649
-
650
- });
651
-
652
-
653
- require('./module')({
654
- expect
655
- });
656
-
657
- after(async() => {
658
- await mongoose.disconnect()
659
- await mongod.stop();
660
- });
661
706
  });