not-node 5.1.25 → 5.1.28
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/exceptions/db.js +12 -0
- package/src/generic/logic.js +139 -0
- package/src/generic/route.js +18 -0
- package/src/model/increment.js +2 -2
- package/src/model/routine.js +17 -12
- package/src/model/utils.js +1 -1
- package/test/model/default.js +950 -810
- package/test/model/routine.js +178 -175
- package/test/module/fields.js +169 -157
- package/test/module/index.js +52 -52
package/test/model/routine.js
CHANGED
|
@@ -1,188 +1,191 @@
|
|
|
1
|
-
const expect = require(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
before(async () => {
|
|
16
|
-
ModelProto.fabricate(plainProto, null, mongoose);
|
|
17
|
-
ModelProto.fabricate(plainProtoIncremental, null, mongoose);
|
|
18
|
-
ModelProto.fabricate(userProto, null, mongoose);
|
|
19
|
-
ModelProto.fabricate(userProtoNotIncremental, null, mongoose);
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('Routine', function() {
|
|
24
|
-
|
|
25
|
-
describe('addWithoutVersion', () => {
|
|
26
|
-
it('ok', async () => {
|
|
27
|
-
let PlainModel = plainProto.PlainModel;
|
|
28
|
-
let item = await routine.addWithoutVersion(PlainModel, {
|
|
29
|
-
name: 'User name 1',
|
|
30
|
-
price: 10
|
|
31
|
-
})
|
|
32
|
-
expect(item).to.exist;
|
|
33
|
-
expect(item.plainModelID).to.not.exist;
|
|
34
|
-
expect(item.name).to.be.equal('User name 1');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('with validation error', async () => {
|
|
38
|
-
let PlainModel = plainProto.PlainModel;
|
|
39
|
-
try {
|
|
40
|
-
await routine.addWithoutVersion(PlainModel, {
|
|
41
|
-
name: 'User name 1'
|
|
42
|
-
});
|
|
43
|
-
} catch (err) {
|
|
44
|
-
expect(err).to.exist;
|
|
45
|
-
expect(err.errors).to.have.key('price');
|
|
46
|
-
}
|
|
47
|
-
});
|
|
1
|
+
const expect = require("chai").expect,
|
|
2
|
+
userProto = require("../testies/module/models/user.js"),
|
|
3
|
+
userProtoNotIncremental = require("../testies/module/models/userNotIncremental.js"),
|
|
4
|
+
plainProto = require("../testies/module/models/plainModel.js"),
|
|
5
|
+
plainProtoIncremental = require("../testies/module/models/plainModelIncremental.js"),
|
|
6
|
+
routine = require("../../src/model/routine"),
|
|
7
|
+
ModelProto = require("../../src/model/proto");
|
|
8
|
+
|
|
9
|
+
module.exports = ({ mongod, mongoose }) => {
|
|
10
|
+
before(async () => {
|
|
11
|
+
ModelProto.fabricate(plainProto, null, mongoose);
|
|
12
|
+
ModelProto.fabricate(plainProtoIncremental, null, mongoose);
|
|
13
|
+
ModelProto.fabricate(userProto, null, mongoose);
|
|
14
|
+
ModelProto.fabricate(userProtoNotIncremental, null, mongoose);
|
|
48
15
|
});
|
|
49
16
|
|
|
50
|
-
describe(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
expect(err.errors).to.have.key('userLocalID');
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe('add', () => {
|
|
80
|
-
it('versioning OFF, incremental OFF', async () => {
|
|
81
|
-
let PlainModel = plainProto.PlainModel;
|
|
82
|
-
let item = await routine.add(PlainModel, {
|
|
83
|
-
name: 'User name 1',
|
|
84
|
-
price: 10
|
|
85
|
-
});
|
|
86
|
-
expect(item).to.exist;
|
|
87
|
-
expect(item.plainModelID).to.not.exist;
|
|
88
|
-
expect(item.name).to.be.equal('User name 1');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('versioning OFF, incremental ON', async () => {
|
|
92
|
-
let PlainModelIncremental = plainProtoIncremental.PlainModelIncremental;
|
|
93
|
-
let item = await routine.add(PlainModelIncremental, {
|
|
94
|
-
name: 'User name 1',
|
|
95
|
-
price: 10
|
|
17
|
+
describe("Routine", function () {
|
|
18
|
+
describe("addWithoutVersion", () => {
|
|
19
|
+
it("ok", async () => {
|
|
20
|
+
let PlainModel = plainProto.PlainModel;
|
|
21
|
+
let item = await routine.addWithoutVersion(PlainModel, {
|
|
22
|
+
name: "User name 1",
|
|
23
|
+
price: 10,
|
|
24
|
+
});
|
|
25
|
+
expect(item).to.exist;
|
|
26
|
+
expect(item.plainModelID).to.not.exist;
|
|
27
|
+
expect(item.name).to.be.equal("User name 1");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("with validation error", async () => {
|
|
31
|
+
let PlainModel = plainProto.PlainModel;
|
|
32
|
+
try {
|
|
33
|
+
await routine.addWithoutVersion(PlainModel, {
|
|
34
|
+
name: "User name 1",
|
|
35
|
+
});
|
|
36
|
+
} catch (err) {
|
|
37
|
+
expect(err).to.exist;
|
|
38
|
+
expect(err.errors).to.have.key("price");
|
|
39
|
+
}
|
|
40
|
+
});
|
|
96
41
|
});
|
|
97
|
-
expect(item).to.exist;
|
|
98
|
-
expect(item.plainModelIncrementalID).to.exist;
|
|
99
|
-
expect(item.name).to.be.equal('User name 1');
|
|
100
|
-
});
|
|
101
42
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
43
|
+
describe("addWithoutVersion", () => {
|
|
44
|
+
it("ok", async () => {
|
|
45
|
+
let User = userProto.UserLocal;
|
|
46
|
+
let item = await routine.addWithVersion(User, {
|
|
47
|
+
userLocalID: 1,
|
|
48
|
+
name: "User name 1",
|
|
49
|
+
price: 10,
|
|
50
|
+
});
|
|
51
|
+
expect(item).to.exist;
|
|
52
|
+
expect(item.userLocalID).to.exist;
|
|
53
|
+
expect(item.__latest).to.exist;
|
|
54
|
+
expect(item.name).to.be.equal("User name 1");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("with validation error", async () => {
|
|
58
|
+
let User = userProto.UserLocal;
|
|
59
|
+
try {
|
|
60
|
+
await routine.addWithVersion(User, {
|
|
61
|
+
name: "User name 1",
|
|
62
|
+
price: 10,
|
|
63
|
+
});
|
|
64
|
+
expect(true).to.be.false;
|
|
65
|
+
} catch (err) {
|
|
66
|
+
expect(err).to.exist;
|
|
67
|
+
expect(err.errors).to.have.key("userLocalID");
|
|
68
|
+
}
|
|
69
|
+
});
|
|
107
70
|
});
|
|
108
|
-
expect(item).to.exist;
|
|
109
|
-
expect(item.userLocalNotIncrementalID).to.not.exist;
|
|
110
|
-
expect(item.name).to.be.equal('User name 1');
|
|
111
|
-
});
|
|
112
71
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
72
|
+
describe("add", () => {
|
|
73
|
+
it("versioning OFF, incremental OFF", async () => {
|
|
74
|
+
let PlainModel = plainProto.PlainModel;
|
|
75
|
+
let item = await routine.add(PlainModel, {
|
|
76
|
+
name: "User name 1",
|
|
77
|
+
price: 10,
|
|
78
|
+
});
|
|
79
|
+
expect(item).to.exist;
|
|
80
|
+
expect(item.plainModelID).to.not.exist;
|
|
81
|
+
expect(item.name).to.be.equal("User name 1");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("versioning OFF, incremental ON", async () => {
|
|
85
|
+
let PlainModelIncremental =
|
|
86
|
+
plainProtoIncremental.PlainModelIncremental;
|
|
87
|
+
let item = await routine.add(PlainModelIncremental, {
|
|
88
|
+
name: "User name 1",
|
|
89
|
+
price: 10,
|
|
90
|
+
});
|
|
91
|
+
expect(item).to.exist;
|
|
92
|
+
expect(item.plainModelIncrementalID).to.exist;
|
|
93
|
+
expect(item.name).to.be.equal("User name 1");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("versioning ON, incremental OFF", async () => {
|
|
97
|
+
let UserLocalNotIncremental =
|
|
98
|
+
userProtoNotIncremental.UserLocalNotIncremental;
|
|
99
|
+
let item = await routine.add(UserLocalNotIncremental, {
|
|
100
|
+
name: "User name 1",
|
|
101
|
+
price: 10,
|
|
102
|
+
});
|
|
103
|
+
expect(item).to.exist;
|
|
104
|
+
expect(item.userLocalNotIncrementalID).to.not.exist;
|
|
105
|
+
expect(item.name).to.be.equal("User name 1");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("versioning ON, ID=1", async () => {
|
|
109
|
+
let User = userProto.UserLocal;
|
|
110
|
+
expect(userProto.mongooseSchema.methods).to.have.keys([
|
|
111
|
+
"close",
|
|
112
|
+
"getID",
|
|
113
|
+
"saveNewVersion",
|
|
114
|
+
]);
|
|
115
|
+
let item = await routine.add(User, {
|
|
116
|
+
name: "User name 1",
|
|
117
|
+
price: 10,
|
|
118
|
+
});
|
|
119
|
+
expect(item).to.exist;
|
|
120
|
+
expect(item.userLocalID).to.exist;
|
|
121
|
+
expect(item.getID()).to.be.equal(1);
|
|
122
|
+
expect(item.__latest).to.exist;
|
|
123
|
+
expect(item.name).to.be.equal("User name 1");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("versioning ON, ID=2", async () => {
|
|
127
|
+
let User = userProto.UserLocal;
|
|
128
|
+
let item = await routine.add(User, {
|
|
129
|
+
name: "User name 12",
|
|
130
|
+
price: 11,
|
|
131
|
+
});
|
|
132
|
+
expect(item).to.exist;
|
|
133
|
+
expect(item.userLocalID).to.exist;
|
|
134
|
+
expect(item.getID()).to.be.equal(2);
|
|
135
|
+
expect(item.__latest).to.exist;
|
|
136
|
+
expect(item.name).to.be.equal("User name 12");
|
|
137
|
+
});
|
|
119
138
|
});
|
|
120
|
-
expect(item).to.exist;
|
|
121
|
-
expect(item.userLocalID).to.exist;
|
|
122
|
-
expect(item.getID()).to.be.equal(1);
|
|
123
|
-
expect(item.__latest).to.exist;
|
|
124
|
-
expect(item.name).to.be.equal('User name 1');
|
|
125
|
-
});
|
|
126
139
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
price: 115
|
|
140
|
+
describe("update", () => {
|
|
141
|
+
it("versioning OFF", async () => {
|
|
142
|
+
const PlainModelIncremental =
|
|
143
|
+
plainProtoIncremental.PlainModelIncremental;
|
|
144
|
+
let item = await routine.add(PlainModelIncremental, {
|
|
145
|
+
name: "User name 32",
|
|
146
|
+
price: 115,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const res = await routine.update(
|
|
150
|
+
PlainModelIncremental,
|
|
151
|
+
{ _id: item._id, price: 115 },
|
|
152
|
+
{
|
|
153
|
+
price: 555,
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(res._id.toString()).to.be.equal(item._id.toString());
|
|
158
|
+
expect(res.price).to.be.equal(555);
|
|
159
|
+
});
|
|
148
160
|
});
|
|
149
161
|
|
|
150
|
-
|
|
151
|
-
|
|
162
|
+
describe("updateMany", () => {
|
|
163
|
+
it("versioning OFF", async () => {
|
|
164
|
+
const PlainModelIncremental =
|
|
165
|
+
plainProtoIncremental.PlainModelIncremental;
|
|
166
|
+
let item1 = await routine.add(PlainModelIncremental, {
|
|
167
|
+
name: "User name 321",
|
|
168
|
+
price: 111,
|
|
169
|
+
});
|
|
170
|
+
let item2 = await routine.add(PlainModelIncremental, {
|
|
171
|
+
name: "User name 322",
|
|
172
|
+
price: 104,
|
|
173
|
+
});
|
|
174
|
+
let item3 = await routine.add(PlainModelIncremental, {
|
|
175
|
+
name: "User name 323",
|
|
176
|
+
price: 102,
|
|
177
|
+
});
|
|
178
|
+
const res = await routine.updateMany(
|
|
179
|
+
PlainModelIncremental,
|
|
180
|
+
{ price: { $gte: 100, $lte: 120 } },
|
|
181
|
+
{ price: 200 }
|
|
182
|
+
);
|
|
183
|
+
//console.log(res.map(itm => itm.toObject()));
|
|
184
|
+
const cnt = await PlainModelIncremental.countDocuments({
|
|
185
|
+
price: 200,
|
|
186
|
+
});
|
|
187
|
+
expect(cnt).to.be.equal(3);
|
|
188
|
+
});
|
|
152
189
|
});
|
|
153
|
-
|
|
154
|
-
expect(res._id.toString()).to.be.equal(item._id.toString());
|
|
155
|
-
expect(res.price).to.be.equal(555);
|
|
156
|
-
});
|
|
157
190
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
describe('updateMany', ()=>{
|
|
161
|
-
it('versioning OFF', async () => {
|
|
162
|
-
const PlainModelIncremental = plainProtoIncremental.PlainModelIncremental;
|
|
163
|
-
let item1 = await routine.add(PlainModelIncremental, {
|
|
164
|
-
name: 'User name 321',
|
|
165
|
-
price: 111
|
|
166
|
-
});
|
|
167
|
-
let item2 = await routine.add(PlainModelIncremental, {
|
|
168
|
-
name: 'User name 322',
|
|
169
|
-
price: 104
|
|
170
|
-
});
|
|
171
|
-
let item3 = await routine.add(PlainModelIncremental, {
|
|
172
|
-
name: 'User name 323',
|
|
173
|
-
price: 102
|
|
174
|
-
});
|
|
175
|
-
const res = await routine.updateMany(
|
|
176
|
-
PlainModelIncremental,
|
|
177
|
-
{price:{$gte: 100, $lte: 120}},
|
|
178
|
-
{price: 200}
|
|
179
|
-
);
|
|
180
|
-
//console.log(res.map(itm => itm.toObject()));
|
|
181
|
-
const cnt = await PlainModelIncremental.countDocuments({price: 200});
|
|
182
|
-
expect(cnt).to.be.equal(3);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
});
|
|
187
|
-
|
|
188
191
|
};
|