not-node 5.1.36 → 5.1.39

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.
@@ -1,388 +1,399 @@
1
- const expect = require('chai').expect,
2
- increment = require('../../src/model/increment'),
3
- validators = require('./../validators'),
4
- remember = require('./../remember'),
5
- proto = require('../../src/model/proto'),
6
- defaultModel = require('../../src/model/default');
7
-
8
- module.exports = ({mongod, mongoose})=>{
9
-
10
- describe('Model/Proto', function() {
11
-
12
- before(async () => {
13
- increment.init(mongoose);
14
- });
15
-
16
- describe('isIgnored', ()=>{
17
- it('set to TRUE', () => {
18
- let targetModule = {
19
- IGNORE: true
20
- },
21
- result = proto.isIgnored(targetModule);
22
- expect(result).to.be.true;
23
- });
24
-
25
- it('set to TRUE', () => {
26
- let targetModule = {
27
- IGNORE: false
28
- },
29
- result = proto.isIgnored(targetModule);
30
- expect(result).to.be.false;
31
- });
32
- });
33
-
34
- describe('initOptions', ()=>{
35
- it('targetModule.schemaOptions is set, but options is NULL', () => {
36
- let targetModule = {
37
- schemaOptions: {
38
- foor: 'bar'
39
- }
40
- },
41
- result = proto.initOptions(null, targetModule);
42
- expect(result.schemaOptions).to.exist;
43
- expect(result.schemaOptions.foor).to.be.equal('bar');
44
- });
1
+ const expect = require("chai").expect,
2
+ increment = require("../../src/model/increment"),
3
+ validators = require("./../validators"),
4
+ remember = require("./../remember"),
5
+ proto = require("../../src/model/proto"),
6
+ defaultModel = require("../../src/model/default");
7
+
8
+ module.exports = ({ mongod, mongoose }) => {
9
+ describe("Model/Proto", function () {
10
+ before(async () => {
11
+ increment.init(mongoose);
12
+ });
45
13
 
46
- it('targetModule.schemaOptions is set, but options is NULL', () => {
47
- let targetModule = {
48
- schemaOptions: {
49
- foor: 'bar'
50
- }
51
- },
52
- options = {
53
- schemaOptions: {
54
- legacy: 'instruction'
55
- }
56
- },
57
- result = proto.initOptions(options, targetModule);
58
- expect(result.schemaOptions).to.exist;
59
- expect(result.schemaOptions.foor).to.be.equal('bar');
60
- });
61
- });
14
+ describe("isIgnored", () => {
15
+ it("set to TRUE", () => {
16
+ let targetModule = {
17
+ IGNORE: true,
18
+ },
19
+ result = proto.isIgnored(targetModule);
20
+ expect(result).to.be.true;
21
+ });
22
+
23
+ it("set to TRUE", () => {
24
+ let targetModule = {
25
+ IGNORE: false,
26
+ },
27
+ result = proto.isIgnored(targetModule);
28
+ expect(result).to.be.false;
29
+ });
30
+ });
62
31
 
32
+ describe("initOptions", () => {
33
+ it("targetModule.schemaOptions is set, but options is NULL", () => {
34
+ let targetModule = {
35
+ schemaOptions: {
36
+ foor: "bar",
37
+ },
38
+ },
39
+ result = proto.initOptions(null, targetModule);
40
+ expect(result.schemaOptions).to.exist;
41
+ expect(result.schemaOptions.foor).to.be.equal("bar");
42
+ });
43
+
44
+ it("targetModule.schemaOptions is set, but options is NULL", () => {
45
+ let targetModule = {
46
+ schemaOptions: {
47
+ foor: "bar",
48
+ },
49
+ },
50
+ options = {
51
+ schemaOptions: {
52
+ legacy: "instruction",
53
+ },
54
+ },
55
+ result = proto.initOptions(options, targetModule);
56
+ expect(result.schemaOptions).to.exist;
57
+ expect(result.schemaOptions.foor).to.be.equal("bar");
58
+ });
59
+ });
63
60
 
64
- describe('extendBySource', ()=>{
65
- it('targetModule full', () => {
66
- let schema = {
67
- methods: {
68
- secure() {}
69
- },
70
- statics: {
71
- insecure() {}
72
- },
73
- virtual(l) {
74
- expect(l).to.be.equal('neo');
75
- return {
76
- get() {
77
- return {
78
- set() {}
79
- };
80
- }
81
- };
82
- },
83
- pre(key, l) {
84
- expect(key).to.be.equal('update');
85
- expect(l(2)).to.be.equal(4);
86
- },
87
- post(key, l) {
88
- expect(key).to.be.equal('update');
89
- expect(l(2)).to.be.equal(1);
90
- },
91
- };
92
- let targetModule = {
93
- thisMethods: {
94
- foo() {}
95
- },
96
- thisStatics: {
97
- bar() {}
98
- },
99
- thisVirtuals: {
100
- neo: {
101
- get() {},
102
- set() {}
103
- }
104
- },
105
- thisPre: {
106
- update(n) {
107
- return n * 2;
108
- },
109
- },
110
- thisPost: {
111
- update(n) {
112
- return n / 2;
113
- },
114
- },
115
- };
116
- proto.extendBySource(schema, targetModule);
117
- expect(schema.methods).to.have.keys(['secure', 'foo']);
118
- expect(schema.statics).to.have.keys(['insecure', 'bar']);
119
- });
61
+ describe("extendBySource", () => {
62
+ it("targetModule full", () => {
63
+ let schema = {
64
+ methods: {
65
+ secure() {},
66
+ },
67
+ statics: {
68
+ insecure() {},
69
+ },
70
+ virtual(l) {
71
+ expect(l).to.be.equal("neo");
72
+ return {
73
+ get() {
74
+ return {
75
+ set() {},
76
+ };
77
+ },
78
+ };
79
+ },
80
+ pre(key, l) {
81
+ expect(key).to.be.equal("update");
82
+ expect(l(2)).to.be.equal(4);
83
+ },
84
+ post(key, l) {
85
+ expect(key).to.be.equal("update");
86
+ expect(l(2)).to.be.equal(1);
87
+ },
88
+ };
89
+ let targetModule = {
90
+ thisMethods: {
91
+ foo() {},
92
+ },
93
+ thisStatics: {
94
+ bar() {},
95
+ },
96
+ thisVirtuals: {
97
+ neo: {
98
+ get() {},
99
+ set() {},
100
+ },
101
+ },
102
+ thisPre: {
103
+ update(n) {
104
+ return n * 2;
105
+ },
106
+ },
107
+ thisPost: {
108
+ update(n) {
109
+ return n / 2;
110
+ },
111
+ },
112
+ };
113
+ proto.extendBySource(schema, targetModule);
114
+ expect(schema.methods).to.have.keys(["secure", "foo"]);
115
+ expect(schema.statics).to.have.keys(["insecure", "bar"]);
116
+ });
117
+
118
+ it("targetModule not full, different structure of virtuals", () => {
119
+ let schema = {
120
+ methods: {
121
+ secure() {},
122
+ },
123
+ statics: {
124
+ insecure() {},
125
+ },
126
+ virtual(l) {
127
+ expect(l).to.be.equal("neo");
128
+ },
129
+ pre(key, l) {
130
+ expect(key).to.be.equal("update");
131
+ expect(l(2)).to.be.equal(4);
132
+ },
133
+ post(key, l) {
134
+ expect(key).to.be.equal("update");
135
+ expect(l(2)).to.be.equal(1);
136
+ },
137
+ };
138
+ let targetModule = {
139
+ thisVirtuals: {
140
+ neo() {},
141
+ },
142
+ thisPre: {
143
+ update(n) {
144
+ return n * 2;
145
+ },
146
+ },
147
+ thisPost: {
148
+ update(n) {
149
+ return n / 2;
150
+ },
151
+ },
152
+ };
153
+ proto.extendBySource(schema, targetModule);
154
+ expect(schema.methods).to.have.keys(["secure"]);
155
+ expect(schema.statics).to.have.keys(["insecure"]);
156
+ });
157
+ });
120
158
 
121
- it('targetModule not full, different structure of virtuals', () => {
122
- let schema = {
123
- methods: {
124
- secure() {}
125
- },
126
- statics: {
127
- insecure() {}
128
- },
129
- virtual(l) {
130
- expect(l).to.be.equal('neo');
131
- },
132
- pre(key, l) {
133
- expect(key).to.be.equal('update');
134
- expect(l(2)).to.be.equal(4);
135
- },
136
- post(key, l) {
137
- expect(key).to.be.equal('update');
138
- expect(l(2)).to.be.equal(1);
139
- },
140
- };
141
- let targetModule = {
142
- thisVirtuals: {
143
- neo() {}
144
- },
145
- thisPre: {
146
- update(n) {
147
- return n * 2;
148
- },
149
- },
150
- thisPost: {
151
- update(n) {
152
- return n / 2;
153
- },
154
- },
155
- };
156
- proto.extendBySource(schema, targetModule);
157
- expect(schema.methods).to.have.keys(['secure']);
158
- expect(schema.statics).to.have.keys(['insecure']);
159
- });
160
- });
159
+ describe("enrichByFields", () => {
160
+ it("enrich not exist", () => {
161
+ let targetModule = {};
162
+ proto.enrichByFields(targetModule);
163
+ expect(targetModule).to.be.deep.equal({});
164
+ });
165
+
166
+ it("enrich not filled", () => {
167
+ let targetModule = {
168
+ enrich: {},
169
+ };
170
+ proto.enrichByFields(targetModule);
171
+ expect(targetModule).to.be.deep.equal({
172
+ enrich: {},
173
+ });
174
+ });
175
+ });
161
176
 
177
+ describe("collectFieldsForIndexes", () => {
178
+ it("targetModule have unique fields for indexes", () => {
179
+ const mod = {
180
+ thisSchema: {
181
+ name: {
182
+ unique: true,
183
+ },
184
+ ID: {
185
+ unique: true,
186
+ },
187
+ phone: {},
188
+ },
189
+ };
190
+ const result = proto.collectFieldsForIndexes(mod);
191
+ expect(result.sort()).to.be.deep.equal(["name", "ID"].sort());
192
+ });
193
+ });
194
+ //createIndexesForFields
195
+ describe("createIndexesForFields", () => {
196
+ it("schema is not empty; fieldsForIndex not empty", () => {
197
+ const schema = {
198
+ index(rule, opts) {
199
+ expect(opts).to.be.deep.equal({
200
+ unique: true,
201
+ });
202
+ expect(rule).to.include({
203
+ __closed: 1,
204
+ __latest: 1,
205
+ _id: 1,
206
+ });
207
+ },
208
+ },
209
+ fieldsForIndexes = ["name", "ID"];
210
+ proto.createIndexesForFields(schema, fieldsForIndexes);
211
+ });
212
+ });
162
213
 
163
- describe('enrichByFields',()=>{
164
- it('enrich not exist', () => {
165
- let targetModule = {};
166
- proto.enrichByFields(targetModule);
167
- expect(targetModule).to.be.deep.equal({});
168
- });
214
+ describe("createIndexesForText", () => {
215
+ it("textIndex exists", () => {
216
+ const targetModule = {
217
+ enrich: {
218
+ textIndex: {
219
+ name: 1,
220
+ surname: 1,
221
+ },
222
+ },
223
+ },
224
+ schema = {
225
+ index(rule, opts) {
226
+ expect(rule).to.be.deep.equal(
227
+ targetModule.enrich.textIndex
228
+ );
229
+ expect(opts).to.be.deep.equal({
230
+ name: "name__surname",
231
+ });
232
+ },
233
+ };
234
+ proto.createIndexesForText(schema, targetModule);
235
+ });
236
+ });
169
237
 
170
- it('enrich not filled', () => {
171
- let targetModule = {
172
- enrich: {}
173
- };
174
- proto.enrichByFields(targetModule);
175
- expect(targetModule).to.be.deep.equal({
176
- enrich: {}
177
- });
178
- });
179
- });
238
+ describe("markFor", () => {
239
+ it("!enrich", () => {
240
+ proto.markFor({}, {});
241
+ });
242
+
243
+ it("enrich, !enrich.increment, !enrich.versioning", () => {
244
+ proto.markFor(
245
+ {},
246
+ {
247
+ enrich: {},
248
+ }
249
+ );
250
+ });
251
+
252
+ it("enrich, enrich.increment && enrich.incrementOptions, !enrich.versioning", () => {
253
+ proto.markFor(
254
+ {
255
+ statics: {},
256
+ },
257
+ {
258
+ thisModelName: "ModelName",
259
+ enrich: {
260
+ increment: {},
261
+ incrementOptions: {},
262
+ },
263
+ }
264
+ );
265
+ });
266
+ });
180
267
 
268
+ describe("initMongooseModel", () => {
269
+ it("model already created and presented in mongoose", () => {
270
+ let results = {};
271
+ const schema = {
272
+ name: {
273
+ type: "string",
274
+ },
275
+ },
276
+ mongoose = {
277
+ modelNames() {
278
+ results.modelNames = true;
279
+ return ["SameModelName"];
280
+ },
281
+ connection: {
282
+ model() {
283
+ return {
284
+ createIndexes() {
285
+ results.createIndexes = true;
286
+ },
287
+ };
288
+ },
289
+ },
290
+ },
291
+ targetModule = {
292
+ thisModelName: "SameModelName",
293
+ };
294
+ proto.initMongooseModel(targetModule, schema, mongoose);
295
+ expect(results).to.have.keys(["modelNames", "createIndexes"]);
296
+ });
297
+ });
181
298
 
299
+ it("fabricate with options", function () {
300
+ let moduleProto1 = {
301
+ thisSchema: {
302
+ name: {
303
+ type: String,
304
+ required: true,
305
+ validate: validators.title,
306
+ },
307
+ default: {
308
+ type: Boolean,
309
+ required: true,
310
+ },
311
+ },
312
+ thisModelName: "User1",
313
+ thisMethods: {
314
+ getName: function () {
315
+ return this.name + " 1";
316
+ },
317
+ },
318
+ thisStatics: {
319
+ returnFalse: () => false,
320
+ },
321
+ enrich: {
322
+ versioning: true,
323
+ increment: true,
324
+ validators: true,
325
+ },
326
+ };
327
+ proto.fabricate(moduleProto1, {}, mongoose);
328
+ expect(moduleProto1.User1).to.exist;
329
+ expect(moduleProto1.User1.returnFalse()).to.be.false;
330
+ let item = new moduleProto1.User1({
331
+ name: "val",
332
+ });
333
+ expect(item.getName()).to.be.equal("val 1");
334
+ expect(moduleProto1.mongooseSchema.statics).to.have.keys([
335
+ "saveVersion",
336
+ "__versioning",
337
+ "__incModel",
338
+ "__incField",
339
+ "returnFalse",
340
+ "sanitizeInput",
341
+ "getOne",
342
+ "getOneByID",
343
+ "getOneRaw",
344
+ "makeQuery",
345
+ "list",
346
+ "countWithFilter",
347
+ "listAndPopulate",
348
+ "add",
349
+ "update",
350
+ "listAll",
351
+ "listAllAndPopulate",
352
+ "listAndCount",
353
+ "listByField",
354
+ ]);
355
+ expect(moduleProto1.mongooseSchema.methods).to.have.keys([
356
+ "getName",
357
+ "getID",
358
+ "close",
359
+ "saveNewVersion",
360
+ ]);
361
+ });
182
362
 
183
- describe('collectFieldsForIndexes', () => {
184
- it('targetModule have unique fields for indexes', () => {
185
- const mod = {
186
- thisSchema: {
187
- name: {
188
- unique: true
363
+ let moduleProto = {
364
+ thisSchema: {
365
+ username: {
366
+ type: String,
367
+ required: true,
368
+ validate: validators.title,
369
+ },
370
+ default: {
371
+ type: Boolean,
372
+ required: true,
373
+ },
189
374
  },
190
- ID: {
191
- unique: true
375
+ thisModelName: "User",
376
+ thisMethods: {},
377
+ thisStatics: {},
378
+ enrich: {
379
+ versioning: true,
380
+ increment: true,
381
+ validators: true,
192
382
  },
193
- phone: {}
194
- }
195
383
  };
196
- const result = proto.collectFieldsForIndexes(mod);
197
- expect(result.sort()).to.be.deep.equal(['name', 'ID'].sort());
198
- });
199
- });
200
- //createIndexesForFields
201
- describe('createIndexesForFields', () => {
202
- it('schema is not empty; fieldsForIndex not empty', () => {
203
- const schema = {
204
- index(rule, opts) {
205
- expect(opts).to.be.deep.equal({
206
- unique: true
207
- });
208
- expect(rule).to.include({
209
- __closed: 1,
210
- __latest: 1,
211
- _id: 1
212
- });
213
- }
214
- },
215
- fieldsForIndexes = ['name', 'ID'];
216
- proto.createIndexesForFields(schema, fieldsForIndexes);
217
- });
218
- });
219
384
 
220
-
221
- describe('createIndexesForText', () => {
222
- it('textIndex exists', () => {
223
- const
224
- targetModule = {
225
- enrich: {
226
- textIndex: {
227
- name: 1,
228
- surname: 1
229
- }
230
- }
231
- },
232
- schema = {
233
- index(rule, opts) {
234
- expect(rule).to.be.deep.equal(targetModule.enrich.textIndex);
235
- expect(opts).to.be.deep.equal({
236
- name: 'name__surname'
237
- });
238
- }
239
- };
240
- proto.createIndexesForText(schema, targetModule);
241
- });
242
- });
243
-
244
-
245
- describe('markFor', () => {
246
- it('!enrich', () => {
247
- proto.markFor({}, {});
248
- });
249
-
250
- it('enrich, !enrich.increment, !enrich.versioning', () => {
251
- proto.markFor({}, {
252
- enrich: {}
385
+ it("fabricate without options", function () {
386
+ proto.fabricate(moduleProto, null, mongoose);
387
+ expect(moduleProto.User).to.exist;
253
388
  });
254
- });
255
389
 
256
- it('enrich, enrich.increment && enrich.incrementOptions, !enrich.versioning', () => {
257
- proto.markFor({
258
- statics:{}
259
- }, {
260
- thisModelName: 'ModelName',
261
- enrich: {
262
- increment: {},
263
- incrementOptions: {}
264
- }
390
+ require("./default.js")({
391
+ expect,
392
+ mongoose,
393
+ mongod,
394
+ defaultModel,
395
+ moduleProto,
396
+ remember,
265
397
  });
266
- });
267
- });
268
-
269
-
270
- describe('initMongooseModel', () => {
271
-
272
- it('model already created and presented in mongoose', () => {
273
- let results = {};
274
- const
275
- schema = {
276
- name: {
277
- type: 'string'
278
- }
279
- },
280
- mongoose = {
281
- modelNames() {
282
- results.modelNames = true;
283
- return ['SameModelName'];
284
- },
285
- connection: {
286
- model() {
287
- return {
288
- createIndexes() {
289
- results.createIndexes = true;
290
- }
291
- }
292
- }
293
- }
294
- },
295
- targetModule = {
296
- thisModelName: 'SameModelName'
297
- };
298
- proto.initMongooseModel(targetModule, schema, mongoose);
299
- expect(results).to.have.keys(['modelNames', 'createIndexes']);
300
- });
301
-
302
398
  });
303
-
304
-
305
-
306
- it('fabricate with options', function() {
307
- let moduleProto1 = {
308
- thisSchema: {
309
- name: {
310
- type: String,
311
- required: true,
312
- validate: validators.title
313
- },
314
- default: {
315
- type: Boolean,
316
- required: true,
317
- }
318
- },
319
- thisModelName: 'User1',
320
- thisMethods: {
321
- getName: function() {
322
- return this.name + ' 1';
323
- }
324
- },
325
- thisStatics: {
326
- returnFalse: () => false
327
- },
328
- enrich: {
329
- versioning: true,
330
- increment: true,
331
- validators: true,
332
- }
333
- };
334
- proto.fabricate(moduleProto1, {}, mongoose);
335
- expect(moduleProto1.User1).to.exist;
336
- expect(moduleProto1.User1.returnFalse()).to.be.false;
337
- let item = new moduleProto1.User1({
338
- name: 'val'
339
- });
340
- expect(item.getName()).to.be.equal('val 1');
341
- expect(moduleProto1.mongooseSchema.statics).to.have.keys(['saveVersion', '__versioning', '__incModel', '__incField', 'returnFalse', 'sanitizeInput', 'getOne', 'getOneByID', 'getOneRaw', 'makeQuery', 'list', 'countWithFilter', 'listAndPopulate', 'add', 'update', 'listAll', 'listAllAndPopulate', 'listAndCount', 'listByField']);
342
- expect(moduleProto1.mongooseSchema.methods).to.have.keys(['getName', 'getID', 'close']);
343
- });
344
-
345
- let moduleProto = {
346
- thisSchema: {
347
- username: {
348
- type: String,
349
- required: true,
350
- validate: validators.title
351
- },
352
- default: {
353
- type: Boolean,
354
- required: true,
355
- }
356
- },
357
- thisModelName: 'User',
358
- thisMethods: {
359
-
360
- },
361
- thisStatics: {
362
-
363
- },
364
- enrich: {
365
- versioning: true,
366
- increment: true,
367
- validators: true,
368
- }
369
- };
370
-
371
- it('fabricate without options', function() {
372
- proto.fabricate(moduleProto, null, mongoose);
373
- expect(moduleProto.User).to.exist;
374
- });
375
-
376
-
377
- require('./default.js')({
378
- expect,
379
- mongoose,
380
- mongod,
381
- defaultModel,
382
- moduleProto,
383
- remember
384
- });
385
-
386
- });
387
-
388
399
  };