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/versioning.js
CHANGED
|
@@ -1,338 +1,394 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const {
|
|
2
|
+
VersioningExceptioNoPreviousVersions,
|
|
3
|
+
} = require("../../src/model/exceptions.js");
|
|
4
|
+
|
|
5
|
+
const expect = require("chai").expect,
|
|
6
|
+
increment = require("../../src/model/increment"),
|
|
7
|
+
ModelFabricate = require("../../src/model/proto"),
|
|
8
|
+
ModelVersioning = require("../../src/model/versioning"),
|
|
9
|
+
validators = require("./../validators");
|
|
6
10
|
|
|
7
11
|
let modelProto = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
thisSchema: {
|
|
13
|
+
username: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
validate: validators.title,
|
|
17
|
+
},
|
|
18
|
+
default: {
|
|
19
|
+
type: Boolean,
|
|
20
|
+
required: true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
thisModelName: "Document",
|
|
24
|
+
thisMethods: {},
|
|
25
|
+
thisStatics: {},
|
|
26
|
+
enrich: {
|
|
27
|
+
versioning: true,
|
|
28
|
+
increment: true,
|
|
29
|
+
validators: true,
|
|
13
30
|
},
|
|
14
|
-
default: {
|
|
15
|
-
type: Boolean,
|
|
16
|
-
required: true,
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
thisModelName: 'Document',
|
|
20
|
-
thisMethods: {},
|
|
21
|
-
thisStatics: {},
|
|
22
|
-
enrich: {
|
|
23
|
-
versioning: true,
|
|
24
|
-
increment: true,
|
|
25
|
-
validators: true,
|
|
26
|
-
}
|
|
27
31
|
};
|
|
28
32
|
|
|
29
|
-
module.exports = ({mongoose})=>{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
module.exports = ({ mongoose }) => {
|
|
34
|
+
describe("Versioning", function () {
|
|
35
|
+
before(async () => {
|
|
36
|
+
increment.init(mongoose);
|
|
37
|
+
ModelFabricate.fabricate(modelProto, {}, mongoose);
|
|
38
|
+
});
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
describe("extractVersionNumber", function () {
|
|
41
|
+
it("version exist", function () {
|
|
42
|
+
const a = {
|
|
43
|
+
__version: 2,
|
|
44
|
+
};
|
|
45
|
+
const b = ModelVersioning.extractVersionNumber(a);
|
|
46
|
+
expect(b).to.deep.equal(2);
|
|
47
|
+
});
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
49
|
+
it("version doesnt exist, goes with default = 0", function () {
|
|
50
|
+
const a = {};
|
|
51
|
+
const b = ModelVersioning.extractVersionNumber(a);
|
|
52
|
+
expect(b).to.deep.equal(0);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
describe("stripTechData", function () {
|
|
57
|
+
it("remove fields, with deletable", function () {
|
|
58
|
+
const dt = new Date();
|
|
59
|
+
const a = {
|
|
60
|
+
a: "f",
|
|
61
|
+
b: 2,
|
|
62
|
+
c: dt,
|
|
63
|
+
d: ["f"],
|
|
64
|
+
_id: "345weqrwqer234",
|
|
65
|
+
__version: 2,
|
|
66
|
+
__versions: [],
|
|
67
|
+
__v: 2,
|
|
68
|
+
__latest: true,
|
|
69
|
+
};
|
|
70
|
+
const a_clean = {
|
|
71
|
+
a: "f",
|
|
72
|
+
b: 2,
|
|
73
|
+
c: dt,
|
|
74
|
+
d: ["f"],
|
|
75
|
+
};
|
|
76
|
+
const b = ModelVersioning.stripTechData(a);
|
|
77
|
+
expect(b).to.deep.equal(a_clean);
|
|
78
|
+
});
|
|
76
79
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
80
|
+
it("remove fields, without deletable", function () {
|
|
81
|
+
const dt = new Date();
|
|
82
|
+
const a = {
|
|
83
|
+
a: "f",
|
|
84
|
+
b: 2,
|
|
85
|
+
c: dt,
|
|
86
|
+
d: ["f"],
|
|
87
|
+
};
|
|
88
|
+
const a_clean = {
|
|
89
|
+
a: "f",
|
|
90
|
+
b: 2,
|
|
91
|
+
c: dt,
|
|
92
|
+
d: ["f"],
|
|
93
|
+
};
|
|
94
|
+
const b = ModelVersioning.stripTechData(a);
|
|
95
|
+
expect(b).to.deep.equal(a_clean);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
99
|
+
describe("isThisDocsDifferent", function () {
|
|
100
|
+
it("identical", function () {
|
|
101
|
+
const dt = new Date();
|
|
102
|
+
const a = {
|
|
103
|
+
a: "f",
|
|
104
|
+
b: 2,
|
|
105
|
+
c: dt,
|
|
106
|
+
d: ["f"],
|
|
107
|
+
_id: "345weqrwqer234",
|
|
108
|
+
__version: 2,
|
|
109
|
+
__versions: [],
|
|
110
|
+
__v: 2,
|
|
111
|
+
__latest: true,
|
|
112
|
+
};
|
|
113
|
+
const a_clean = {
|
|
114
|
+
a: "f",
|
|
115
|
+
b: 2,
|
|
116
|
+
c: dt,
|
|
117
|
+
d: ["f"],
|
|
118
|
+
};
|
|
119
|
+
const result = ModelVersioning.isThisDocsDifferent(a, a_clean);
|
|
120
|
+
expect(result).to.be.false;
|
|
121
|
+
});
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
123
|
+
it("different in content of array", function () {
|
|
124
|
+
const dt = new Date();
|
|
125
|
+
const a = {
|
|
126
|
+
a: "f",
|
|
127
|
+
b: 2,
|
|
128
|
+
c: dt,
|
|
129
|
+
d: ["f", "asd"],
|
|
130
|
+
_id: "345weqrwqer234",
|
|
131
|
+
__version: 2,
|
|
132
|
+
__versions: [],
|
|
133
|
+
__v: 2,
|
|
134
|
+
__latest: true,
|
|
135
|
+
};
|
|
136
|
+
const a_clean = {
|
|
137
|
+
a: "f",
|
|
138
|
+
b: 2,
|
|
139
|
+
c: dt,
|
|
140
|
+
d: ["f"],
|
|
141
|
+
};
|
|
142
|
+
const result = ModelVersioning.isThisDocsDifferent(a, a_clean);
|
|
143
|
+
expect(result).to.be.true;
|
|
144
|
+
});
|
|
142
145
|
|
|
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
|
-
describe('isNew', function() {
|
|
174
|
-
let firstHistoryVersion = {
|
|
175
|
-
documentID: 1,
|
|
176
|
-
username: 'username1',
|
|
177
|
-
default: true,
|
|
178
|
-
__latest: false,
|
|
179
|
-
__versions: [],
|
|
180
|
-
__version: 1,
|
|
181
|
-
__closed: false
|
|
182
|
-
},
|
|
183
|
-
secondHistoryVersion = {
|
|
184
|
-
...firstHistoryVersion,
|
|
185
|
-
username: 'username2',
|
|
186
|
-
default: false,
|
|
187
|
-
__version: 2,
|
|
188
|
-
__closed: false
|
|
189
|
-
};
|
|
146
|
+
it("different in content of sub object", function () {
|
|
147
|
+
const dt = new Date();
|
|
148
|
+
const a = {
|
|
149
|
+
a: "f",
|
|
150
|
+
b: 2,
|
|
151
|
+
c: dt,
|
|
152
|
+
le: {
|
|
153
|
+
h: 1,
|
|
154
|
+
},
|
|
155
|
+
d: ["f"],
|
|
156
|
+
_id: "345weqrwqer234",
|
|
157
|
+
__version: 2,
|
|
158
|
+
__versions: [],
|
|
159
|
+
__v: 2,
|
|
160
|
+
__latest: true,
|
|
161
|
+
};
|
|
162
|
+
const a_clean = {
|
|
163
|
+
a: "f",
|
|
164
|
+
b: 2,
|
|
165
|
+
le: {
|
|
166
|
+
h: 2,
|
|
167
|
+
},
|
|
168
|
+
c: dt,
|
|
169
|
+
d: ["f"],
|
|
170
|
+
};
|
|
171
|
+
const result = ModelVersioning.isThisDocsDifferent(a, a_clean);
|
|
172
|
+
expect(result).to.be.true;
|
|
173
|
+
});
|
|
174
|
+
});
|
|
190
175
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
176
|
+
describe("isNew", function () {
|
|
177
|
+
let firstHistoryVersion = {
|
|
178
|
+
documentID: 1,
|
|
179
|
+
username: "username1",
|
|
180
|
+
default: true,
|
|
181
|
+
__latest: false,
|
|
182
|
+
__versions: [],
|
|
183
|
+
__version: 1,
|
|
184
|
+
__closed: false,
|
|
185
|
+
},
|
|
186
|
+
secondHistoryVersion = {
|
|
187
|
+
...firstHistoryVersion,
|
|
188
|
+
username: "username2",
|
|
189
|
+
default: false,
|
|
190
|
+
__version: 2,
|
|
191
|
+
__closed: false,
|
|
192
|
+
};
|
|
194
193
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
secondHistoryVersion.__versions = [first._id];
|
|
199
|
-
let second = await (new modelProto.Document(secondHistoryVersion)).save();
|
|
200
|
-
let latest = {
|
|
201
|
-
...secondHistoryVersion,
|
|
202
|
-
__versions: [second._id, first._id],
|
|
203
|
-
__latest: true
|
|
204
|
-
};
|
|
205
|
-
await (new modelProto.Document(latest)).save();
|
|
206
|
-
//case
|
|
207
|
-
const b = await ModelVersioning.isNew(modelProto.Document, latest);
|
|
208
|
-
expect(b).to.be.false;
|
|
209
|
-
});
|
|
194
|
+
beforeEach(async () => {
|
|
195
|
+
await modelProto.Document.deleteMany({});
|
|
196
|
+
});
|
|
210
197
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
198
|
+
it("same version", async () => {
|
|
199
|
+
//setup
|
|
200
|
+
let first = await new modelProto.Document(
|
|
201
|
+
firstHistoryVersion
|
|
202
|
+
).save();
|
|
203
|
+
secondHistoryVersion.__versions = [first._id];
|
|
204
|
+
let second = await new modelProto.Document(
|
|
205
|
+
secondHistoryVersion
|
|
206
|
+
).save();
|
|
207
|
+
let latest = {
|
|
208
|
+
...secondHistoryVersion,
|
|
209
|
+
__versions: [second._id, first._id],
|
|
210
|
+
__latest: true,
|
|
211
|
+
};
|
|
212
|
+
await new modelProto.Document(latest).save();
|
|
213
|
+
//case
|
|
214
|
+
const b = await ModelVersioning.isNew(
|
|
215
|
+
modelProto.Document,
|
|
216
|
+
latest
|
|
217
|
+
);
|
|
218
|
+
expect(b).to.be.false;
|
|
219
|
+
});
|
|
227
220
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
221
|
+
it("new version, without archived copy", async () => {
|
|
222
|
+
//setup
|
|
223
|
+
let first = await new modelProto.Document(
|
|
224
|
+
firstHistoryVersion
|
|
225
|
+
).save();
|
|
226
|
+
secondHistoryVersion.__versions = [first._id];
|
|
227
|
+
let second = await new modelProto.Document(
|
|
228
|
+
secondHistoryVersion
|
|
229
|
+
).save();
|
|
230
|
+
let latest = {
|
|
231
|
+
...secondHistoryVersion,
|
|
232
|
+
username: "username3",
|
|
233
|
+
__versions: [second._id, first._id],
|
|
234
|
+
__latest: true,
|
|
235
|
+
};
|
|
236
|
+
await new modelProto.Document(latest).save();
|
|
237
|
+
//case
|
|
238
|
+
const b = await ModelVersioning.isNew(
|
|
239
|
+
modelProto.Document,
|
|
240
|
+
latest
|
|
241
|
+
);
|
|
242
|
+
expect(b).to.be.true;
|
|
243
|
+
});
|
|
249
244
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
245
|
+
it("new version, with falty versions list", async () => {
|
|
246
|
+
//setup
|
|
247
|
+
let first = await new modelProto.Document(
|
|
248
|
+
firstHistoryVersion
|
|
249
|
+
).save();
|
|
250
|
+
secondHistoryVersion.__versions = [first._id];
|
|
251
|
+
let second = await new modelProto.Document(
|
|
252
|
+
secondHistoryVersion
|
|
253
|
+
).save();
|
|
254
|
+
let latest = {
|
|
255
|
+
...secondHistoryVersion,
|
|
256
|
+
username: "username3",
|
|
257
|
+
__versions: [
|
|
258
|
+
mongoose.Types.ObjectId(),
|
|
259
|
+
second._id,
|
|
260
|
+
first._id,
|
|
261
|
+
],
|
|
262
|
+
__latest: true,
|
|
263
|
+
};
|
|
264
|
+
await new modelProto.Document(latest).save();
|
|
265
|
+
//case
|
|
266
|
+
try {
|
|
267
|
+
await ModelVersioning.isNew(modelProto.Document, latest);
|
|
268
|
+
} catch (e) {
|
|
269
|
+
expect(e).to.be.instanceOf(
|
|
270
|
+
VersioningExceptioNoPreviousVersions
|
|
271
|
+
);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
throw new Error(
|
|
275
|
+
"no exception from inside, VersioningExceptioNoPreviousVersions"
|
|
276
|
+
);
|
|
277
|
+
});
|
|
254
278
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
279
|
+
afterEach(async () => {
|
|
280
|
+
await modelProto.Document.deleteMany({});
|
|
281
|
+
});
|
|
282
|
+
});
|
|
259
283
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
username: 'username',
|
|
265
|
-
default: true,
|
|
266
|
-
__versions: [],
|
|
267
|
-
__version: 1,
|
|
268
|
-
};
|
|
269
|
-
let first = await (new(modelProto.Document)(firstHistoryVersion)).save();
|
|
270
|
-
let secondHistoryVersion = {
|
|
271
|
-
...firstHistoryVersion,
|
|
272
|
-
__versions: [first._id],
|
|
273
|
-
__version: 2,
|
|
274
|
-
};
|
|
275
|
-
let second = await (new(modelProto.Document)(secondHistoryVersion)).save();
|
|
276
|
-
try{
|
|
277
|
-
await ModelVersioning.version.call(modelProto.Document, second._id)
|
|
278
|
-
}catch(e){
|
|
279
|
-
expect(e.message).to.be.equal(ModelVersioning.ERR_SAME_OLD_DATA);
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
throw new Error('no exception from inside, ModelVersioning.ERR_SAME_OLD_DATA');
|
|
283
|
-
});
|
|
284
|
+
describe("saveVersion", function () {
|
|
285
|
+
beforeEach(async () => {
|
|
286
|
+
await modelProto.Document.deleteMany({});
|
|
287
|
+
});
|
|
284
288
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
289
|
+
it("same version, should throw ERR_SAME_OLD_DATA", async () => {
|
|
290
|
+
//setup
|
|
291
|
+
let firstHistoryVersion = {
|
|
292
|
+
documentID: 1,
|
|
293
|
+
username: "username",
|
|
294
|
+
default: true,
|
|
295
|
+
__versions: [],
|
|
296
|
+
__version: 1,
|
|
297
|
+
};
|
|
298
|
+
let first = await new modelProto.Document(
|
|
299
|
+
firstHistoryVersion
|
|
300
|
+
).save();
|
|
301
|
+
let secondHistoryVersion = {
|
|
302
|
+
...firstHistoryVersion,
|
|
303
|
+
__versions: [first._id],
|
|
304
|
+
__version: 2,
|
|
305
|
+
};
|
|
306
|
+
let second = await new modelProto.Document(
|
|
307
|
+
secondHistoryVersion
|
|
308
|
+
).save();
|
|
309
|
+
try {
|
|
310
|
+
await ModelVersioning.version.call(
|
|
311
|
+
modelProto.Document,
|
|
312
|
+
second._id
|
|
313
|
+
);
|
|
314
|
+
} catch (e) {
|
|
315
|
+
expect(e.message).to.be.equal(
|
|
316
|
+
"not-node:versioning_error_same_old_data"
|
|
317
|
+
);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
throw new Error(
|
|
321
|
+
"no exception from inside, not-node:versioning_error_same_old_data"
|
|
322
|
+
);
|
|
323
|
+
});
|
|
316
324
|
|
|
317
|
-
|
|
318
|
-
|
|
325
|
+
it("update existing document", async () => {
|
|
326
|
+
//setup
|
|
327
|
+
let firstHistoryVersion = {
|
|
328
|
+
documentID: 1,
|
|
329
|
+
username: "username",
|
|
330
|
+
default: true,
|
|
331
|
+
__versions: [],
|
|
332
|
+
__version: 1,
|
|
333
|
+
__latest: false,
|
|
334
|
+
__closed: false,
|
|
335
|
+
};
|
|
336
|
+
let first = await new modelProto.Document(
|
|
337
|
+
firstHistoryVersion
|
|
338
|
+
).save();
|
|
339
|
+
let secondHistoryVersion = {
|
|
340
|
+
...firstHistoryVersion,
|
|
341
|
+
__versions: [first._id],
|
|
342
|
+
__version: 1,
|
|
343
|
+
__latest: true,
|
|
344
|
+
__closed: false,
|
|
345
|
+
};
|
|
346
|
+
let second = await new modelProto.Document(
|
|
347
|
+
secondHistoryVersion
|
|
348
|
+
).save();
|
|
349
|
+
second.username = "username4";
|
|
350
|
+
await second.save();
|
|
351
|
+
let secondAfterVersioning = await ModelVersioning.version.call(
|
|
352
|
+
modelProto.Document,
|
|
353
|
+
second._id
|
|
354
|
+
);
|
|
355
|
+
expect(secondAfterVersioning.__version).to.be.equal(2);
|
|
356
|
+
expect(secondAfterVersioning.__versions.length).to.be.equal(2);
|
|
357
|
+
expect(secondAfterVersioning.__latest).to.be.true;
|
|
358
|
+
expect(secondAfterVersioning.__closed).to.be.false;
|
|
359
|
+
expect(secondAfterVersioning.username).to.be.equal("username4");
|
|
360
|
+
let list = await modelProto.Document.find({}).exec();
|
|
361
|
+
//console.log(list.map(doc => doc.toObject()));
|
|
362
|
+
expect(list.length).to.be.equal(3);
|
|
319
363
|
|
|
320
|
-
|
|
321
|
-
|
|
364
|
+
let latestCount = await modelProto.Document.countDocuments({
|
|
365
|
+
__latest: true,
|
|
366
|
+
});
|
|
367
|
+
expect(latestCount).to.be.equal(1);
|
|
322
368
|
|
|
323
|
-
|
|
324
|
-
|
|
369
|
+
let notLatestCount = await modelProto.Document.countDocuments({
|
|
370
|
+
__latest: false,
|
|
371
|
+
});
|
|
372
|
+
expect(notLatestCount).to.be.equal(2);
|
|
325
373
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
374
|
+
let notLatestNotClosedCount =
|
|
375
|
+
await modelProto.Document.countDocuments({
|
|
376
|
+
__latest: false,
|
|
377
|
+
__closed: false,
|
|
378
|
+
});
|
|
379
|
+
expect(notLatestNotClosedCount).to.be.equal(2);
|
|
329
380
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
381
|
+
let currentCount = await modelProto.Document.countDocuments({
|
|
382
|
+
__latest: true,
|
|
383
|
+
__closed: false,
|
|
384
|
+
__version: 2,
|
|
385
|
+
});
|
|
386
|
+
expect(currentCount).to.be.equal(1);
|
|
387
|
+
});
|
|
333
388
|
|
|
389
|
+
afterEach(async () => {
|
|
390
|
+
await modelProto.Document.deleteMany({});
|
|
391
|
+
});
|
|
392
|
+
});
|
|
334
393
|
});
|
|
335
|
-
|
|
336
|
-
});
|
|
337
|
-
|
|
338
394
|
};
|