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.
- package/package.json +1 -1
- package/src/bootstrap/route.js +29 -2
- package/src/core/fields/ID.js +4 -0
- package/src/fields/index.js +2 -2
- package/src/manifest/module.js +18 -0
- package/src/model/exceptions.js +3 -3
- package/src/model/routine.js +11 -6
- package/src/model/versioning.js +2 -2
- package/test/auth/fields.js +308 -281
- package/test/auth/routes.js +166 -168
- package/test/fields.js +271 -266
- package/test/model/increment.js +235 -220
- package/test/model/proto.js +380 -369
- package/test/model/versioning.js +366 -310
- package/test/notModel.js +44 -48
package/test/model/increment.js
CHANGED
|
@@ -1,224 +1,239 @@
|
|
|
1
|
-
const expect = require(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
module.exports = ({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
try {
|
|
98
|
-
increment.formId(modelName, filterFields, data);
|
|
99
|
-
expect(true).to.be.false;
|
|
100
|
-
} catch (e) {
|
|
101
|
-
expect(e).to.be.instanceof(Error);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
//
|
|
106
|
-
describe('secureUpdate', () => {
|
|
107
|
-
it('updateOne', async () => {
|
|
108
|
-
const thisM = {
|
|
109
|
-
updateOne(...params) {
|
|
110
|
-
return {
|
|
111
|
-
async exec() {
|
|
112
|
-
return params.join('.');
|
|
1
|
+
const expect = require("chai").expect,
|
|
2
|
+
increment = require("../../src/model/increment");
|
|
3
|
+
|
|
4
|
+
module.exports = ({ mongod, mongoose }) => {
|
|
5
|
+
describe("Increment", function () {
|
|
6
|
+
describe("notContainedInData", () => {
|
|
7
|
+
it("fields empty, object not empty", () => {
|
|
8
|
+
const fields = [];
|
|
9
|
+
const obj = {
|
|
10
|
+
meat: 1,
|
|
11
|
+
};
|
|
12
|
+
const res = increment.notContainedInData(fields, obj);
|
|
13
|
+
expect(res).to.be.instanceof(Array);
|
|
14
|
+
expect(res).to.be.deep.equal([]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("fields empty, object empty", () => {
|
|
18
|
+
const fields = [];
|
|
19
|
+
const obj = {};
|
|
20
|
+
const res = increment.notContainedInData(fields, obj);
|
|
21
|
+
expect(res).to.be.instanceof(Array);
|
|
22
|
+
expect(res).to.be.deep.equal([]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("fields not empty, object contains em all", () => {
|
|
26
|
+
const fields = ["meat", "laser"];
|
|
27
|
+
const obj = {
|
|
28
|
+
meat: 1,
|
|
29
|
+
laser: 3,
|
|
30
|
+
lepricon: true,
|
|
31
|
+
};
|
|
32
|
+
const res = increment.notContainedInData(fields, obj);
|
|
33
|
+
expect(res).to.be.instanceof(Array);
|
|
34
|
+
expect(res).to.be.deep.equal([]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("fields not empty, object contains none", () => {
|
|
38
|
+
const fields = ["meat", "laser"];
|
|
39
|
+
const obj = {
|
|
40
|
+
meat1: 1,
|
|
41
|
+
laser1: 3,
|
|
42
|
+
lepricon1: true,
|
|
43
|
+
};
|
|
44
|
+
const res = increment.notContainedInData(fields, obj);
|
|
45
|
+
expect(res).to.be.instanceof(Array);
|
|
46
|
+
expect(res.sort()).to.be.deep.equal(["meat", "laser"].sort());
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("formId", () => {
|
|
51
|
+
it("modelName - not empty, filterFields - empty, data - empty", () => {
|
|
52
|
+
const modelName = "user",
|
|
53
|
+
filterFields = [],
|
|
54
|
+
data = {};
|
|
55
|
+
const res = increment.formId(modelName, filterFields, data);
|
|
56
|
+
expect(typeof res).to.be.equal("string");
|
|
57
|
+
expect(res).to.be.deep.equal(modelName);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("modelName - not empty, filterFields - one field, data - contains fields", () => {
|
|
61
|
+
const modelName = "user",
|
|
62
|
+
filterFields = ["group"],
|
|
63
|
+
data = {
|
|
64
|
+
group: 1,
|
|
65
|
+
name: "lego",
|
|
66
|
+
};
|
|
67
|
+
const res = increment.formId(modelName, filterFields, data);
|
|
68
|
+
expect(typeof res).to.be.equal("string");
|
|
69
|
+
expect(res).to.be.deep.equal(`${modelName}_${data.group}`);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("modelName - not empty, filterFields - two fields, data - contains fields", () => {
|
|
73
|
+
const modelName = "user",
|
|
74
|
+
filterFields = ["group", "long"],
|
|
75
|
+
data = {
|
|
76
|
+
group: 1,
|
|
77
|
+
long: true,
|
|
78
|
+
name: "lego",
|
|
79
|
+
};
|
|
80
|
+
const res = increment.formId(modelName, filterFields, data);
|
|
81
|
+
expect(typeof res).to.be.equal("string");
|
|
82
|
+
expect(res).to.be.deep.equal(`${modelName}_${data.group}_true`);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("modelName - not empty, filterFields - two fields, data - contains none", () => {
|
|
86
|
+
const modelName = "user",
|
|
87
|
+
filterFields = ["group", "long"],
|
|
88
|
+
data = {
|
|
89
|
+
name: "lego",
|
|
90
|
+
};
|
|
91
|
+
try {
|
|
92
|
+
increment.formId(modelName, filterFields, data);
|
|
93
|
+
expect(true).to.be.false;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
expect(e).to.be.instanceof(Error);
|
|
113
96
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
//
|
|
100
|
+
describe("secureUpdate", () => {
|
|
101
|
+
it("updateOne", async () => {
|
|
102
|
+
const thisM = {
|
|
103
|
+
updateOne(...params) {
|
|
104
|
+
return {
|
|
105
|
+
async exec() {
|
|
106
|
+
return params.join(".");
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
which = 1,
|
|
112
|
+
cmd = 2,
|
|
113
|
+
opts = 3;
|
|
114
|
+
expect(
|
|
115
|
+
await increment.secureUpdate(thisM, which, cmd, opts).exec()
|
|
116
|
+
).to.be.equal("1.2.3");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("update", async () => {
|
|
120
|
+
const thisM = {
|
|
121
|
+
update(...params) {
|
|
122
|
+
return {
|
|
123
|
+
async exec() {
|
|
124
|
+
return params.join(".");
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
which = 1,
|
|
130
|
+
cmd = 2,
|
|
131
|
+
opts = 3;
|
|
132
|
+
expect(
|
|
133
|
+
await increment.secureUpdate(thisM, which, cmd, opts).exec()
|
|
134
|
+
).to.be.equal("1.2.3");
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("init", () => {
|
|
139
|
+
it("before init", function () {
|
|
140
|
+
expect(increment.next).to.not.exist;
|
|
141
|
+
expect(increment.model).to.not.exist;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("after init", function () {
|
|
145
|
+
increment.init(mongoose);
|
|
146
|
+
expect(increment.next).to.exist;
|
|
147
|
+
expect(increment.model).to.exist;
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("second time", function () {
|
|
151
|
+
increment.init(mongoose);
|
|
152
|
+
expect(increment.next).to.exist;
|
|
153
|
+
expect(increment.model).to.exist;
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("getNext", () => {
|
|
158
|
+
it("first time", async () => {
|
|
159
|
+
const nextID = await increment.next("modelName");
|
|
160
|
+
expect(nextID).to.deep.equal(1);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("second time", async () => {
|
|
164
|
+
const nextID = await increment.next("modelName");
|
|
165
|
+
expect(nextID).to.deep.equal(2);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("with error", async () => {
|
|
169
|
+
try {
|
|
170
|
+
await increment.next({
|
|
171
|
+
some: 1,
|
|
172
|
+
object: 2,
|
|
173
|
+
});
|
|
174
|
+
expect(true).to.be.false;
|
|
175
|
+
} catch (err) {
|
|
176
|
+
expect(err).to.exist;
|
|
177
|
+
expect(err).to.be.instanceof(Error);
|
|
129
178
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
nextID = await increment.next('uberModelName', ['carrot'], {carrot: 2});
|
|
190
|
-
expect(nextID).to.deep.equal(2);
|
|
191
|
-
nextID = await increment.next('uberModelName', ['carrot'], {carrot: 3});
|
|
192
|
-
expect(nextID).to.deep.equal(2);
|
|
193
|
-
nextID = await increment.next('uberModelName', ['carrot'], {carrot: 5});
|
|
194
|
-
expect(nextID).to.deep.equal(1);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('missing fields, throw out', async () => {
|
|
198
|
-
try{
|
|
199
|
-
await increment.next('uberModelName', ['carrot'], {});
|
|
200
|
-
throw 'no error';
|
|
201
|
-
}catch(e){
|
|
202
|
-
expect(e).to.be.instanceof(Error);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
describe('newRebase', () => {
|
|
209
|
-
it('doing cold start rebase', async () => {
|
|
210
|
-
let nextID = await increment.rebase('rebasedModelName_true', 10);
|
|
211
|
-
expect(nextID).to.deep.equal(10);
|
|
212
|
-
nextID = await increment.next('rebasedModelName', ['carrot'], {carrot: true});
|
|
213
|
-
expect(nextID).to.deep.equal(11);
|
|
214
|
-
nextID = await increment.next('rebasedModelName', ['carrot'], {carrot: true});
|
|
215
|
-
expect(nextID).to.deep.equal(12);
|
|
216
|
-
nextID = await increment.rebase('rebasedModelName_true', 10);
|
|
217
|
-
expect(nextID).to.deep.equal(10);
|
|
218
|
-
nextID = await increment.next('rebasedModelName', ['carrot'], {carrot: true});
|
|
219
|
-
expect(nextID).to.deep.equal(11);
|
|
220
|
-
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("sequence with filterFields for different groups", async () => {
|
|
182
|
+
let nextID;
|
|
183
|
+
nextID = await increment.next("uberModelName", ["carrot"], {
|
|
184
|
+
carrot: 2,
|
|
185
|
+
});
|
|
186
|
+
expect(nextID).to.deep.equal(1);
|
|
187
|
+
nextID = await increment.next("uberModelName", ["carrot"], {
|
|
188
|
+
carrot: 3,
|
|
189
|
+
});
|
|
190
|
+
expect(nextID).to.deep.equal(1);
|
|
191
|
+
nextID = await increment.next("uberModelName", ["carrot"], {
|
|
192
|
+
carrot: 2,
|
|
193
|
+
});
|
|
194
|
+
expect(nextID).to.deep.equal(2);
|
|
195
|
+
nextID = await increment.next("uberModelName", ["carrot"], {
|
|
196
|
+
carrot: 3,
|
|
197
|
+
});
|
|
198
|
+
expect(nextID).to.deep.equal(2);
|
|
199
|
+
nextID = await increment.next("uberModelName", ["carrot"], {
|
|
200
|
+
carrot: 5,
|
|
201
|
+
});
|
|
202
|
+
expect(nextID).to.deep.equal(1);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("missing fields, throw out", async () => {
|
|
206
|
+
try {
|
|
207
|
+
await increment.next("uberModelName", ["carrot"], {});
|
|
208
|
+
throw "no error";
|
|
209
|
+
} catch (e) {
|
|
210
|
+
expect(e).to.be.instanceof(Error);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe("newRebase", () => {
|
|
216
|
+
it("doing cold start rebase", async () => {
|
|
217
|
+
let nextID = await increment.rebase(
|
|
218
|
+
"rebasedModelName_true",
|
|
219
|
+
10
|
|
220
|
+
);
|
|
221
|
+
expect(nextID).to.deep.equal(10);
|
|
222
|
+
nextID = await increment.next("rebasedModelName", ["carrot"], {
|
|
223
|
+
carrot: true,
|
|
224
|
+
});
|
|
225
|
+
expect(nextID).to.deep.equal(11);
|
|
226
|
+
nextID = await increment.next("rebasedModelName", ["carrot"], {
|
|
227
|
+
carrot: true,
|
|
228
|
+
});
|
|
229
|
+
expect(nextID).to.deep.equal(12);
|
|
230
|
+
nextID = await increment.rebase("rebasedModelName_true", 10);
|
|
231
|
+
expect(nextID).to.deep.equal(10);
|
|
232
|
+
nextID = await increment.next("rebasedModelName", ["carrot"], {
|
|
233
|
+
carrot: true,
|
|
234
|
+
});
|
|
235
|
+
expect(nextID).to.deep.equal(11);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
221
238
|
});
|
|
222
|
-
|
|
223
|
-
});
|
|
224
239
|
};
|