@nymphjs/server 1.0.0-beta.0 → 1.0.0-beta.2
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/CHANGELOG.md +10 -0
- package/dist/cache.test.js +21 -32
- package/dist/cache.test.js.map +1 -1
- package/dist/index.js +152 -161
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +171 -185
- package/dist/index.test.js.map +1 -1
- package/dist/testArtifacts.js +22 -47
- package/dist/testArtifacts.js.map +1 -1
- package/package.json +6 -6
- package/tsconfig.json +2 -0
package/dist/index.test.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -32,48 +23,45 @@ const nymph = new client_node_1.Nymph({
|
|
|
32
23
|
});
|
|
33
24
|
nymph.addEntityClass(testArtifacts_1.Employee);
|
|
34
25
|
describe('Nymph REST Server and Client', () => {
|
|
35
|
-
function createJane() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return jane;
|
|
52
|
-
});
|
|
26
|
+
async function createJane() {
|
|
27
|
+
const jane = await testArtifacts_1.Employee.factory();
|
|
28
|
+
jane.name = 'Jane Doe';
|
|
29
|
+
jane.current = true;
|
|
30
|
+
jane.salary = 8000000;
|
|
31
|
+
jane.startDate = Date.now();
|
|
32
|
+
jane.subordinates = [];
|
|
33
|
+
jane.title = 'Seniorer Person';
|
|
34
|
+
try {
|
|
35
|
+
await jane.$save();
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
console.error('Error creating entity: ', e);
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
return jane;
|
|
53
42
|
}
|
|
54
|
-
it('create an entity', () =>
|
|
55
|
-
const jane =
|
|
43
|
+
it('create an entity', async () => {
|
|
44
|
+
const jane = await createJane();
|
|
56
45
|
expect(jane.guid).not.toBeNull();
|
|
57
46
|
expect(typeof jane.guid).toEqual('string');
|
|
58
|
-
})
|
|
59
|
-
it('mdate is updated on save', () =>
|
|
60
|
-
|
|
61
|
-
const jane = yield createJane();
|
|
47
|
+
});
|
|
48
|
+
it('mdate is updated on save', async () => {
|
|
49
|
+
const jane = await createJane();
|
|
62
50
|
expect(jane.guid).not.toBeNull();
|
|
63
|
-
const oldMdate =
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
const oldMdate = jane.mdate ?? Infinity;
|
|
52
|
+
await new Promise((resolve) => setTimeout(() => resolve(true), 100));
|
|
53
|
+
await jane.$save();
|
|
66
54
|
expect(jane.mdate).toBeGreaterThan(oldMdate);
|
|
67
|
-
})
|
|
68
|
-
it('create two unrelated entities', () =>
|
|
69
|
-
const entity =
|
|
55
|
+
});
|
|
56
|
+
it('create two unrelated entities', async () => {
|
|
57
|
+
const entity = await testArtifacts_1.Employee.factory();
|
|
70
58
|
entity.name = 'Jane Doe';
|
|
71
59
|
entity.current = true;
|
|
72
60
|
entity.salary = 8000000;
|
|
73
61
|
entity.startDate = Date.now();
|
|
74
62
|
entity.subordinates = [];
|
|
75
63
|
entity.title = 'Seniorer Person';
|
|
76
|
-
const entity2 =
|
|
64
|
+
const entity2 = await testArtifacts_1.Employee.factory();
|
|
77
65
|
entity2.name = 'John Doe';
|
|
78
66
|
entity2.current = true;
|
|
79
67
|
entity2.salary = 8000000;
|
|
@@ -81,28 +69,28 @@ describe('Nymph REST Server and Client', () => {
|
|
|
81
69
|
entity2.subordinates = [];
|
|
82
70
|
entity2.title = 'Seniorer Person';
|
|
83
71
|
const entities = [entity, entity2];
|
|
84
|
-
|
|
72
|
+
await nymph.saveEntities(entities);
|
|
85
73
|
if (entity.guid == null || entity2.guid == null) {
|
|
86
74
|
throw new Error('Entity is null.');
|
|
87
75
|
}
|
|
88
76
|
entity.building = 'J2';
|
|
89
77
|
entity2.building = 'B4';
|
|
90
|
-
|
|
91
|
-
const jane =
|
|
92
|
-
const john =
|
|
93
|
-
expect(jane
|
|
94
|
-
expect(john
|
|
95
|
-
})
|
|
96
|
-
it('create two related entities', () =>
|
|
97
|
-
const jane =
|
|
78
|
+
await nymph.saveEntities(entities);
|
|
79
|
+
const jane = await nymph.getEntity({ class: testArtifacts_1.Employee }, entity.guid);
|
|
80
|
+
const john = await nymph.getEntity({ class: testArtifacts_1.Employee }, entity2.guid);
|
|
81
|
+
expect(jane?.building).toEqual('J2');
|
|
82
|
+
expect(john?.building).toEqual('B4');
|
|
83
|
+
});
|
|
84
|
+
it('create two related entities', async () => {
|
|
85
|
+
const jane = await testArtifacts_1.Employee.factory();
|
|
98
86
|
jane.name = 'Jane Doe';
|
|
99
87
|
jane.current = true;
|
|
100
88
|
jane.salary = 8000000;
|
|
101
89
|
jane.startDate = Date.now();
|
|
102
90
|
jane.subordinates = [];
|
|
103
91
|
jane.title = 'Seniorer Person';
|
|
104
|
-
|
|
105
|
-
const steve =
|
|
92
|
+
await jane.$save();
|
|
93
|
+
const steve = await testArtifacts_1.Employee.factory();
|
|
106
94
|
steve.$addTag('boss', 'bigcheese');
|
|
107
95
|
steve.name = 'Steve Guy';
|
|
108
96
|
steve.current = true;
|
|
@@ -110,26 +98,26 @@ describe('Nymph REST Server and Client', () => {
|
|
|
110
98
|
steve.startDate = Date.now();
|
|
111
99
|
steve.subordinates = [jane];
|
|
112
100
|
steve.title = 'Executive Person';
|
|
113
|
-
|
|
101
|
+
await steve.$save();
|
|
114
102
|
if (jane.guid == null || steve.guid == null) {
|
|
115
103
|
throw new Error('Entity is null.');
|
|
116
104
|
}
|
|
117
|
-
const checkSteve =
|
|
105
|
+
const checkSteve = await nymph.getEntity({ class: testArtifacts_1.Employee }, {
|
|
118
106
|
type: '&',
|
|
119
107
|
ref: ['subordinates', jane],
|
|
120
108
|
});
|
|
121
|
-
expect(checkSteve
|
|
122
|
-
const checkSteveQref =
|
|
109
|
+
expect(checkSteve?.guid).toEqual(steve.guid);
|
|
110
|
+
const checkSteveQref = await nymph.getEntity({ class: testArtifacts_1.Employee }, {
|
|
123
111
|
type: '&',
|
|
124
112
|
qref: [
|
|
125
113
|
'subordinates',
|
|
126
114
|
[{ class: testArtifacts_1.Employee }, { type: '&', guid: jane.guid }],
|
|
127
115
|
],
|
|
128
116
|
});
|
|
129
|
-
expect(checkSteveQref
|
|
130
|
-
})
|
|
131
|
-
it('add, check, and remove tags', () =>
|
|
132
|
-
const entity =
|
|
117
|
+
expect(checkSteveQref?.guid).toEqual(steve.guid);
|
|
118
|
+
});
|
|
119
|
+
it('add, check, and remove tags', async () => {
|
|
120
|
+
const entity = await client_1.Entity.factory();
|
|
133
121
|
entity.$addTag('test');
|
|
134
122
|
expect(entity.$hasTag('test')).toEqual(true);
|
|
135
123
|
entity.$addTag('test', 'test2');
|
|
@@ -143,9 +131,9 @@ describe('Nymph REST Server and Client', () => {
|
|
|
143
131
|
entity.$removeTag('test5', 'test6');
|
|
144
132
|
expect(!entity.$hasTag('test5', 'test6')).toEqual(true);
|
|
145
133
|
expect(!(entity.tags < ['test'] || entity.tags > ['test'])).toEqual(true);
|
|
146
|
-
})
|
|
147
|
-
it('wake a sleeping reference', () =>
|
|
148
|
-
const jane =
|
|
134
|
+
});
|
|
135
|
+
it('wake a sleeping reference', async () => {
|
|
136
|
+
const jane = await createJane();
|
|
149
137
|
if (jane.guid == null) {
|
|
150
138
|
throw new Error('Entity is null.');
|
|
151
139
|
}
|
|
@@ -154,55 +142,53 @@ describe('Nymph REST Server and Client', () => {
|
|
|
154
142
|
jane.guid,
|
|
155
143
|
'Employee',
|
|
156
144
|
]);
|
|
157
|
-
|
|
158
|
-
expect(jane
|
|
159
|
-
})
|
|
160
|
-
it('change an entity', () =>
|
|
161
|
-
|
|
162
|
-
const employee = yield createJane();
|
|
145
|
+
await entity.$ready();
|
|
146
|
+
expect(jane?.name).toEqual('Jane Doe');
|
|
147
|
+
});
|
|
148
|
+
it('change an entity', async () => {
|
|
149
|
+
const employee = await createJane();
|
|
163
150
|
if (employee.guid == null) {
|
|
164
151
|
throw new Error('Entity is null.');
|
|
165
152
|
}
|
|
166
153
|
delete employee.salary;
|
|
167
154
|
employee.current = false;
|
|
168
155
|
employee.endDate = Date.now() + 1;
|
|
169
|
-
|
|
170
|
-
const check =
|
|
156
|
+
await employee.$save();
|
|
157
|
+
const check = await testArtifacts_1.Employee.factory(employee.guid);
|
|
171
158
|
expect(check.salary).toBeUndefined();
|
|
172
159
|
expect(check.current).toEqual(false);
|
|
173
|
-
expect(check.endDate).toBeGreaterThan(
|
|
174
|
-
})
|
|
175
|
-
it('patch an entity', () =>
|
|
176
|
-
|
|
177
|
-
const employee = yield createJane();
|
|
160
|
+
expect(check.endDate).toBeGreaterThan(check.startDate ?? 0);
|
|
161
|
+
});
|
|
162
|
+
it('patch an entity', async () => {
|
|
163
|
+
const employee = await createJane();
|
|
178
164
|
if (employee.guid == null) {
|
|
179
165
|
throw new Error('Entity is null.');
|
|
180
166
|
}
|
|
181
167
|
delete employee.salary;
|
|
182
168
|
employee.current = false;
|
|
183
169
|
employee.endDate = Date.now() + 1;
|
|
184
|
-
|
|
185
|
-
const check =
|
|
170
|
+
await employee.$patch();
|
|
171
|
+
const check = await testArtifacts_1.Employee.factory(employee.guid);
|
|
186
172
|
expect(check.salary).toBeUndefined();
|
|
187
173
|
expect(check.current).toEqual(false);
|
|
188
|
-
expect(check.endDate).toBeGreaterThan(
|
|
189
|
-
})
|
|
190
|
-
it('get an entity', () =>
|
|
191
|
-
|
|
192
|
-
const jane =
|
|
174
|
+
expect(check.endDate).toBeGreaterThan(check.startDate ?? 0);
|
|
175
|
+
});
|
|
176
|
+
it('get an entity', async () => {
|
|
177
|
+
await createJane();
|
|
178
|
+
const jane = await nymph.getEntity({
|
|
193
179
|
class: testArtifacts_1.Employee,
|
|
194
180
|
}, {
|
|
195
181
|
type: '&',
|
|
196
182
|
equal: ['name', 'Jane Doe'],
|
|
197
183
|
});
|
|
198
184
|
expect(jane).not.toBeNull();
|
|
199
|
-
expect(jane
|
|
200
|
-
})
|
|
201
|
-
it('get entities', () =>
|
|
185
|
+
expect(jane?.guid).not.toBeNull();
|
|
186
|
+
});
|
|
187
|
+
it('get entities', async () => {
|
|
202
188
|
for (let i = 0; i < 4; i++) {
|
|
203
|
-
|
|
189
|
+
await createJane();
|
|
204
190
|
}
|
|
205
|
-
const entities =
|
|
191
|
+
const entities = await nymph.getEntities({
|
|
206
192
|
class: testArtifacts_1.Employee,
|
|
207
193
|
limit: 4,
|
|
208
194
|
}, {
|
|
@@ -213,41 +199,41 @@ describe('Nymph REST Server and Client', () => {
|
|
|
213
199
|
entities.forEach((entity) => {
|
|
214
200
|
expect(entity.guid).not.toBeNull();
|
|
215
201
|
});
|
|
216
|
-
})
|
|
217
|
-
it('get entity counts', () =>
|
|
202
|
+
});
|
|
203
|
+
it('get entity counts', async () => {
|
|
218
204
|
for (let i = 0; i < 20; i++) {
|
|
219
|
-
|
|
205
|
+
await createJane();
|
|
220
206
|
}
|
|
221
|
-
const result =
|
|
222
|
-
const resultCount =
|
|
207
|
+
const result = await nymph.getEntities({ class: testArtifacts_1.Employee });
|
|
208
|
+
const resultCount = await nymph.getEntities({
|
|
223
209
|
class: testArtifacts_1.Employee,
|
|
224
210
|
return: 'count',
|
|
225
211
|
});
|
|
226
212
|
expect(resultCount).toBeGreaterThanOrEqual(1);
|
|
227
213
|
expect(resultCount).toEqual(result.length);
|
|
228
|
-
const resultSelectors =
|
|
229
|
-
const resultSelectorsCount =
|
|
214
|
+
const resultSelectors = await nymph.getEntities({ class: testArtifacts_1.Employee }, { type: '&', equal: ['name', 'Jane Doe'] });
|
|
215
|
+
const resultSelectorsCount = await nymph.getEntities({ class: testArtifacts_1.Employee, return: 'count' }, { type: '&', equal: ['name', 'Jane Doe'] });
|
|
230
216
|
expect(resultSelectorsCount).toBeGreaterThanOrEqual(1);
|
|
231
217
|
expect(resultSelectorsCount).toEqual(resultSelectors.length);
|
|
232
|
-
const resultSelectorsLimit =
|
|
218
|
+
const resultSelectorsLimit = await nymph.getEntities({
|
|
233
219
|
class: testArtifacts_1.Employee,
|
|
234
220
|
limit: 1,
|
|
235
221
|
return: 'count',
|
|
236
222
|
});
|
|
237
223
|
expect(resultSelectorsLimit).toEqual(1);
|
|
238
|
-
const resultSelectorsSingle =
|
|
224
|
+
const resultSelectorsSingle = await nymph.getEntity({
|
|
239
225
|
class: testArtifacts_1.Employee,
|
|
240
226
|
return: 'count',
|
|
241
227
|
});
|
|
242
228
|
expect(resultSelectorsSingle).toEqual(1);
|
|
243
|
-
const resultSelectorsEmpty =
|
|
229
|
+
const resultSelectorsEmpty = await nymph.getEntities({ class: testArtifacts_1.Employee, return: 'count' }, { type: '&', tag: 'pickle' });
|
|
244
230
|
expect(resultSelectorsEmpty).toEqual(0);
|
|
245
|
-
})
|
|
246
|
-
it('get entity GUIDs', () =>
|
|
231
|
+
});
|
|
232
|
+
it('get entity GUIDs', async () => {
|
|
247
233
|
for (let i = 0; i < 4; i++) {
|
|
248
|
-
|
|
234
|
+
await createJane();
|
|
249
235
|
}
|
|
250
|
-
const entities =
|
|
236
|
+
const entities = await nymph.getEntities({
|
|
251
237
|
class: testArtifacts_1.Employee,
|
|
252
238
|
limit: 4,
|
|
253
239
|
return: 'guid',
|
|
@@ -259,12 +245,12 @@ describe('Nymph REST Server and Client', () => {
|
|
|
259
245
|
entities.forEach((guid) => {
|
|
260
246
|
expect(typeof guid).toEqual('string');
|
|
261
247
|
});
|
|
262
|
-
})
|
|
263
|
-
it('use two selectors', () =>
|
|
248
|
+
});
|
|
249
|
+
it('use two selectors', async () => {
|
|
264
250
|
for (let i = 0; i < 4; i++) {
|
|
265
|
-
|
|
251
|
+
await createJane();
|
|
266
252
|
}
|
|
267
|
-
const entities =
|
|
253
|
+
const entities = await nymph.getEntities({
|
|
268
254
|
class: testArtifacts_1.Employee,
|
|
269
255
|
limit: 4,
|
|
270
256
|
}, {
|
|
@@ -278,12 +264,12 @@ describe('Nymph REST Server and Client', () => {
|
|
|
278
264
|
entities.forEach((entity) => {
|
|
279
265
|
expect(entity.guid).not.toBeNull();
|
|
280
266
|
});
|
|
281
|
-
})
|
|
282
|
-
it('use deep selector', () =>
|
|
267
|
+
});
|
|
268
|
+
it('use deep selector', async () => {
|
|
283
269
|
for (let i = 0; i < 4; i++) {
|
|
284
|
-
|
|
270
|
+
await createJane();
|
|
285
271
|
}
|
|
286
|
-
const entities =
|
|
272
|
+
const entities = await nymph.getEntities({
|
|
287
273
|
class: testArtifacts_1.Employee,
|
|
288
274
|
limit: 4,
|
|
289
275
|
}, {
|
|
@@ -298,12 +284,12 @@ describe('Nymph REST Server and Client', () => {
|
|
|
298
284
|
entities.forEach((entity) => {
|
|
299
285
|
expect(entity.guid).not.toBeNull();
|
|
300
286
|
});
|
|
301
|
-
})
|
|
302
|
-
it('use really deep selector', () =>
|
|
287
|
+
});
|
|
288
|
+
it('use really deep selector', async () => {
|
|
303
289
|
for (let i = 0; i < 4; i++) {
|
|
304
|
-
|
|
290
|
+
await createJane();
|
|
305
291
|
}
|
|
306
|
-
const entities =
|
|
292
|
+
const entities = await nymph.getEntities({
|
|
307
293
|
class: testArtifacts_1.Employee,
|
|
308
294
|
limit: 4,
|
|
309
295
|
}, {
|
|
@@ -327,121 +313,121 @@ describe('Nymph REST Server and Client', () => {
|
|
|
327
313
|
entities.forEach((entity) => {
|
|
328
314
|
expect(entity.guid).not.toBeNull();
|
|
329
315
|
});
|
|
330
|
-
})
|
|
331
|
-
it('delete an entity', () =>
|
|
332
|
-
const jane =
|
|
316
|
+
});
|
|
317
|
+
it('delete an entity', async () => {
|
|
318
|
+
const jane = await createJane();
|
|
333
319
|
const guid = jane.guid;
|
|
334
320
|
if (guid == null) {
|
|
335
321
|
throw new Error('Entity is null.');
|
|
336
322
|
}
|
|
337
|
-
const deleted =
|
|
323
|
+
const deleted = await jane.$delete();
|
|
338
324
|
expect(deleted).toEqual(true);
|
|
339
|
-
const check =
|
|
325
|
+
const check = await nymph.getEntities({ class: testArtifacts_1.Employee }, {
|
|
340
326
|
type: '&',
|
|
341
327
|
guid,
|
|
342
328
|
});
|
|
343
329
|
expect(check.length).toEqual(0);
|
|
344
|
-
})
|
|
345
|
-
it('delete entities', () =>
|
|
346
|
-
const janes = [
|
|
330
|
+
});
|
|
331
|
+
it('delete entities', async () => {
|
|
332
|
+
const janes = [await createJane(), await createJane()];
|
|
347
333
|
const guids = janes.map((jane) => {
|
|
348
334
|
if (jane.guid == null) {
|
|
349
335
|
throw new Error('Entity is null.');
|
|
350
336
|
}
|
|
351
337
|
return jane.guid;
|
|
352
338
|
});
|
|
353
|
-
const deleted =
|
|
339
|
+
const deleted = await nymph.deleteEntities(janes);
|
|
354
340
|
expect(deleted).toEqual(guids);
|
|
355
|
-
const check =
|
|
341
|
+
const check = await nymph.getEntities({ class: testArtifacts_1.Employee }, {
|
|
356
342
|
type: '|',
|
|
357
343
|
guid: guids,
|
|
358
344
|
});
|
|
359
345
|
expect(check.length).toEqual(0);
|
|
360
|
-
})
|
|
361
|
-
it('try to save Entity class directly', () =>
|
|
346
|
+
});
|
|
347
|
+
it('try to save Entity class directly', async () => {
|
|
362
348
|
const entity = new client_1.Entity();
|
|
363
349
|
entity.$nymph = nymph;
|
|
364
350
|
entity.something = 'Anything';
|
|
365
351
|
let error = { message: '' };
|
|
366
352
|
try {
|
|
367
|
-
|
|
353
|
+
await entity.$save();
|
|
368
354
|
}
|
|
369
355
|
catch (e) {
|
|
370
356
|
error = e;
|
|
371
357
|
}
|
|
372
358
|
expect(error.message).toEqual("Can't use Entity class directly from the front end.");
|
|
373
|
-
})
|
|
374
|
-
it('handle forbidden method', () =>
|
|
359
|
+
});
|
|
360
|
+
it('handle forbidden method', async () => {
|
|
375
361
|
let error = { status: 200 };
|
|
376
362
|
try {
|
|
377
|
-
|
|
363
|
+
await testArtifacts_1.Employee.inaccessibleMethod();
|
|
378
364
|
}
|
|
379
365
|
catch (e) {
|
|
380
366
|
error = e;
|
|
381
367
|
}
|
|
382
368
|
expect(error.status).toEqual(403);
|
|
383
|
-
})
|
|
384
|
-
it('handle server side static error', () =>
|
|
369
|
+
});
|
|
370
|
+
it('handle server side static error', async () => {
|
|
385
371
|
let error = { error: { name: '' } };
|
|
386
372
|
try {
|
|
387
|
-
|
|
373
|
+
await testArtifacts_1.Employee.throwErrorStatic();
|
|
388
374
|
}
|
|
389
375
|
catch (e) {
|
|
390
376
|
error = e;
|
|
391
377
|
}
|
|
392
378
|
expect(error.error.name).toEqual('BadFunctionCallError');
|
|
393
|
-
})
|
|
394
|
-
it('handle server side error', () =>
|
|
395
|
-
const jane =
|
|
379
|
+
});
|
|
380
|
+
it('handle server side error', async () => {
|
|
381
|
+
const jane = await createJane();
|
|
396
382
|
let error = { error: { name: '' } };
|
|
397
383
|
try {
|
|
398
|
-
|
|
384
|
+
await jane.$throwError();
|
|
399
385
|
}
|
|
400
386
|
catch (e) {
|
|
401
387
|
error = e;
|
|
402
388
|
}
|
|
403
389
|
expect(error.error.name).toEqual('BadFunctionCallError');
|
|
404
|
-
})
|
|
405
|
-
it('call a server side static method', () =>
|
|
406
|
-
const data =
|
|
390
|
+
});
|
|
391
|
+
it('call a server side static method', async () => {
|
|
392
|
+
const data = await testArtifacts_1.Employee.testStatic(5);
|
|
407
393
|
expect(data).toEqual(10);
|
|
408
|
-
})
|
|
409
|
-
it('call a stateless server side method', () =>
|
|
410
|
-
const jane =
|
|
411
|
-
const data =
|
|
394
|
+
});
|
|
395
|
+
it('call a stateless server side method', async () => {
|
|
396
|
+
const jane = await createJane();
|
|
397
|
+
const data = await jane?.$testMethodStateless(5);
|
|
412
398
|
expect(data).toEqual(6);
|
|
413
|
-
expect(jane
|
|
414
|
-
})
|
|
415
|
-
it('call a server side method', () =>
|
|
416
|
-
const jane =
|
|
417
|
-
expect(jane
|
|
418
|
-
const data =
|
|
399
|
+
expect(jane?.name).toEqual('Jane Doe');
|
|
400
|
+
});
|
|
401
|
+
it('call a server side method', async () => {
|
|
402
|
+
const jane = await createJane();
|
|
403
|
+
expect(jane?.current).toEqual(true);
|
|
404
|
+
const data = await jane?.$testMethod(5);
|
|
419
405
|
expect(data).toEqual(7);
|
|
420
|
-
expect(jane
|
|
421
|
-
})
|
|
422
|
-
it('refresh an entity', () =>
|
|
423
|
-
const jane1 =
|
|
406
|
+
expect(jane?.current).toEqual(false);
|
|
407
|
+
});
|
|
408
|
+
it('refresh an entity', async () => {
|
|
409
|
+
const jane1 = await createJane();
|
|
424
410
|
if (jane1.guid == null) {
|
|
425
411
|
throw new Error('Entity is null.');
|
|
426
412
|
}
|
|
427
|
-
const jane2 =
|
|
413
|
+
const jane2 = await nymph.getEntity({
|
|
428
414
|
class: testArtifacts_1.Employee,
|
|
429
415
|
}, jane1.guid);
|
|
430
416
|
if (jane1 == null || jane2 == null) {
|
|
431
417
|
throw new Error('Entity is null.');
|
|
432
418
|
}
|
|
433
419
|
jane1.name = 'Janet Doe';
|
|
434
|
-
|
|
420
|
+
await jane1.$save();
|
|
435
421
|
expect(jane2.name).toEqual('Jane Doe');
|
|
436
|
-
|
|
422
|
+
await jane2.$refresh();
|
|
437
423
|
expect(jane2.name).toEqual('Janet Doe');
|
|
438
|
-
})
|
|
439
|
-
it('check two entities are equal', () =>
|
|
440
|
-
const first =
|
|
424
|
+
});
|
|
425
|
+
it('check two entities are equal', async () => {
|
|
426
|
+
const first = await createJane();
|
|
441
427
|
if (first.guid == null) {
|
|
442
428
|
throw new Error('Entity is null.');
|
|
443
429
|
}
|
|
444
|
-
const second =
|
|
430
|
+
const second = await nymph.getEntity({
|
|
445
431
|
class: testArtifacts_1.Employee,
|
|
446
432
|
}, first.guid);
|
|
447
433
|
if (second == null || second.guid == null) {
|
|
@@ -455,13 +441,13 @@ describe('Nymph REST Server and Client', () => {
|
|
|
455
441
|
second.other = 'that';
|
|
456
442
|
second.thing = 'that';
|
|
457
443
|
expect(first.$equals(second)).toEqual(false);
|
|
458
|
-
})
|
|
459
|
-
it('check two objects are the same entity', () =>
|
|
460
|
-
const first =
|
|
444
|
+
});
|
|
445
|
+
it('check two objects are the same entity', async () => {
|
|
446
|
+
const first = await createJane();
|
|
461
447
|
if (first.guid == null) {
|
|
462
448
|
throw new Error('Entity is null.');
|
|
463
449
|
}
|
|
464
|
-
const second =
|
|
450
|
+
const second = await nymph.getEntity({
|
|
465
451
|
class: testArtifacts_1.Employee,
|
|
466
452
|
}, first.guid);
|
|
467
453
|
if (second == null || second.guid == null) {
|
|
@@ -471,8 +457,8 @@ describe('Nymph REST Server and Client', () => {
|
|
|
471
457
|
second.other = 'this';
|
|
472
458
|
second.thing = 'this';
|
|
473
459
|
expect(first.$is(second)).toEqual(true);
|
|
474
|
-
|
|
475
|
-
const third =
|
|
460
|
+
await createJane();
|
|
461
|
+
const third = await nymph.getEntity({
|
|
476
462
|
class: testArtifacts_1.Employee,
|
|
477
463
|
}, {
|
|
478
464
|
type: '&',
|
|
@@ -482,47 +468,47 @@ describe('Nymph REST Server and Client', () => {
|
|
|
482
468
|
throw new Error('Entity is null.');
|
|
483
469
|
}
|
|
484
470
|
expect(first.$is(third)).toEqual(false);
|
|
485
|
-
})
|
|
486
|
-
it('get a new UID', () =>
|
|
487
|
-
const uidValue =
|
|
471
|
+
});
|
|
472
|
+
it('get a new UID', async () => {
|
|
473
|
+
const uidValue = await nymph.newUID('employee');
|
|
488
474
|
expect(typeof uidValue).toEqual('number');
|
|
489
475
|
expect(uidValue).toBeGreaterThan(0);
|
|
490
|
-
const uidValue2 =
|
|
476
|
+
const uidValue2 = await nymph.newUID('employee');
|
|
491
477
|
expect(typeof uidValue2).toEqual('number');
|
|
492
478
|
expect(uidValue2).toBeGreaterThan(uidValue);
|
|
493
|
-
})
|
|
494
|
-
it('get UID value', () =>
|
|
495
|
-
const uidValue =
|
|
479
|
+
});
|
|
480
|
+
it('get UID value', async () => {
|
|
481
|
+
const uidValue = await nymph.getUID('employee');
|
|
496
482
|
expect(typeof uidValue).toEqual('number');
|
|
497
483
|
expect(uidValue).toBeGreaterThan(0);
|
|
498
|
-
const uidValue2 =
|
|
484
|
+
const uidValue2 = await nymph.getUID('employee');
|
|
499
485
|
expect(typeof uidValue2).toEqual('number');
|
|
500
486
|
expect(uidValue2).toEqual(uidValue);
|
|
501
|
-
})
|
|
502
|
-
it('set UID value', () =>
|
|
503
|
-
const uidValue =
|
|
487
|
+
});
|
|
488
|
+
it('set UID value', async () => {
|
|
489
|
+
const uidValue = await nymph.newUID('employee');
|
|
504
490
|
expect(typeof uidValue).toEqual('number');
|
|
505
491
|
expect(uidValue).toBeGreaterThan(0);
|
|
506
|
-
const success =
|
|
492
|
+
const success = await nymph.setUID('employee', uidValue - 1);
|
|
507
493
|
expect(success).toEqual(true);
|
|
508
|
-
const uidValue2 =
|
|
494
|
+
const uidValue2 = await nymph.getUID('employee');
|
|
509
495
|
expect(typeof uidValue2).toEqual('number');
|
|
510
496
|
expect(uidValue2).toEqual(uidValue - 1);
|
|
511
|
-
})
|
|
512
|
-
it('delete UID', () =>
|
|
513
|
-
const uidValue =
|
|
497
|
+
});
|
|
498
|
+
it('delete UID', async () => {
|
|
499
|
+
const uidValue = await nymph.newUID('temp');
|
|
514
500
|
expect(typeof uidValue).toEqual('number');
|
|
515
501
|
expect(uidValue).toEqual(1);
|
|
516
|
-
|
|
502
|
+
await nymph.deleteUID('temp');
|
|
517
503
|
let error = { status: 200 };
|
|
518
504
|
try {
|
|
519
|
-
|
|
505
|
+
await nymph.getUID('temp');
|
|
520
506
|
}
|
|
521
507
|
catch (e) {
|
|
522
508
|
error = e;
|
|
523
509
|
}
|
|
524
510
|
expect(error.status).toEqual(404);
|
|
525
|
-
})
|
|
511
|
+
});
|
|
526
512
|
afterAll(() => {
|
|
527
513
|
server.close();
|
|
528
514
|
});
|