@feathersjs/adapter-tests 4.5.2 → 4.5.12
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 +38 -0
- package/LICENSE +1 -1
- package/lib/basic.d.ts +2 -0
- package/lib/basic.js +42 -51
- package/lib/basic.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +46 -44
- package/lib/index.js.map +1 -0
- package/lib/methods.d.ts +2 -0
- package/lib/methods.js +469 -528
- package/lib/methods.js.map +1 -0
- package/lib/syntax.d.ts +2 -0
- package/lib/syntax.js +296 -337
- package/lib/syntax.js.map +1 -0
- package/package.json +19 -9
- package/src/basic.ts +53 -0
- package/src/index.ts +53 -0
- package/src/methods.ts +600 -0
- package/src/syntax.ts +342 -0
package/src/methods.ts
ADDED
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
|
|
3
|
+
export default (test: any, app: any, _errors: any, serviceName: string, idProp: string) => {
|
|
4
|
+
describe(' Methods', () => {
|
|
5
|
+
let doug: any;
|
|
6
|
+
let service: any;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
service = app.service(serviceName);
|
|
10
|
+
doug = await app.service(serviceName).create({
|
|
11
|
+
name: 'Doug',
|
|
12
|
+
age: 32
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
try {
|
|
18
|
+
await app.service(serviceName).remove(doug[idProp]);
|
|
19
|
+
} catch (error: any) {}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('get', () => {
|
|
23
|
+
test('.get', async () => {
|
|
24
|
+
const data = await service.get(doug[idProp]);
|
|
25
|
+
|
|
26
|
+
assert.strictEqual(data[idProp].toString(), doug[idProp].toString(),
|
|
27
|
+
`${idProp} id matches`
|
|
28
|
+
);
|
|
29
|
+
assert.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
30
|
+
assert.strictEqual(data.age, 32, 'data.age matches');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('.get + $select', async () => {
|
|
34
|
+
const data = await service.get(doug[idProp], {
|
|
35
|
+
query: { $select: [ 'name' ] }
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
assert.strictEqual(data[idProp].toString(), doug[idProp].toString(),
|
|
39
|
+
`${idProp} id property matches`
|
|
40
|
+
);
|
|
41
|
+
assert.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
42
|
+
assert.ok(!data.age, 'data.age is falsy');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('.get + id + query', async () => {
|
|
46
|
+
try {
|
|
47
|
+
await service.get(doug[idProp], {
|
|
48
|
+
query: { name: 'Tester' }
|
|
49
|
+
});
|
|
50
|
+
throw new Error('Should never get here');
|
|
51
|
+
} catch (error: any) {
|
|
52
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
53
|
+
'Got a NotFound Feathers error'
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('.get + NotFound', async () => {
|
|
59
|
+
try {
|
|
60
|
+
await service.get('568225fbfe21222432e836ff');
|
|
61
|
+
throw new Error('Should never get here');
|
|
62
|
+
} catch (error: any) {
|
|
63
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
64
|
+
'Error is a NotFound Feathers error'
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('.get + id + query id', async () => {
|
|
70
|
+
const alice = await service.create({
|
|
71
|
+
name: 'Alice',
|
|
72
|
+
age: 12
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
await service.get(doug[idProp], {
|
|
77
|
+
query: { [idProp]: alice[idProp] }
|
|
78
|
+
});
|
|
79
|
+
throw new Error('Should never get here');
|
|
80
|
+
} catch (error: any) {
|
|
81
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
82
|
+
'Got a NotFound Feathers error'
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
await service.remove(alice[idProp]);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('find', () => {
|
|
91
|
+
test('.find', async () => {
|
|
92
|
+
const data = await service.find();
|
|
93
|
+
|
|
94
|
+
assert.ok(Array.isArray(data), 'Data is an array');
|
|
95
|
+
assert.strictEqual(data.length, 1, 'Got one entry');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('remove', () => {
|
|
100
|
+
test('.remove', async () => {
|
|
101
|
+
const data = await service.remove(doug[idProp]);
|
|
102
|
+
|
|
103
|
+
assert.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('.remove + $select', async () => {
|
|
107
|
+
const data = await service.remove(doug[idProp], {
|
|
108
|
+
query: { $select: [ 'name' ] }
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
assert.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
112
|
+
assert.ok(!data.age, 'data.age is falsy');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('.remove + id + query', async () => {
|
|
116
|
+
try {
|
|
117
|
+
await service.remove(doug[idProp], {
|
|
118
|
+
query: { name: 'Tester' }
|
|
119
|
+
});
|
|
120
|
+
throw new Error('Should never get here');
|
|
121
|
+
} catch (error: any) {
|
|
122
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
123
|
+
'Got a NotFound Feathers error'
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('.remove + multi', async () => {
|
|
129
|
+
try {
|
|
130
|
+
await service.remove(null);
|
|
131
|
+
throw new Error('Should never get here');
|
|
132
|
+
} catch (error: any) {
|
|
133
|
+
assert.strictEqual(error.name, 'MethodNotAllowed',
|
|
134
|
+
'Removing multiple without option set throws MethodNotAllowed'
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
service.options.multi = [ 'remove' ];
|
|
139
|
+
|
|
140
|
+
await service.create({ name: 'Dave', age: 29, created: true });
|
|
141
|
+
await service.create({
|
|
142
|
+
name: 'David',
|
|
143
|
+
age: 3,
|
|
144
|
+
created: true
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const data = await service.remove(null, {
|
|
148
|
+
query: { created: true }
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
assert.strictEqual(data.length, 2);
|
|
152
|
+
|
|
153
|
+
const names = data.map((person: any) => person.name);
|
|
154
|
+
|
|
155
|
+
assert.ok(names.includes('Dave'), 'Dave removed');
|
|
156
|
+
assert.ok(names.includes('David'), 'David removed');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('.remove + id + query id', async () => {
|
|
160
|
+
const alice = await service.create({
|
|
161
|
+
name: 'Alice',
|
|
162
|
+
age: 12
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
await service.remove(doug[idProp], {
|
|
167
|
+
query: { [idProp]: alice[idProp] }
|
|
168
|
+
});
|
|
169
|
+
throw new Error('Should never get here');
|
|
170
|
+
} catch (error: any) {
|
|
171
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
172
|
+
'Got a NotFound Feathers error'
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
await service.remove(alice[idProp]);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('update', () => {
|
|
181
|
+
test('.update', async () => {
|
|
182
|
+
const originalData = { [idProp]: doug[idProp], name: 'Dougler' };
|
|
183
|
+
const originalCopy = Object.assign({}, originalData);
|
|
184
|
+
|
|
185
|
+
const data = await service.update(doug[idProp], originalData);
|
|
186
|
+
|
|
187
|
+
assert.deepStrictEqual(originalData, originalCopy,
|
|
188
|
+
'data was not modified'
|
|
189
|
+
);
|
|
190
|
+
assert.strictEqual(data[idProp].toString(), doug[idProp].toString(),
|
|
191
|
+
`${idProp} id matches`
|
|
192
|
+
);
|
|
193
|
+
assert.strictEqual(data.name, 'Dougler', 'data.name matches');
|
|
194
|
+
assert.ok(!data.age, 'data.age is falsy');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('.update + $select', async () => {
|
|
198
|
+
const originalData = {
|
|
199
|
+
[idProp]: doug[idProp],
|
|
200
|
+
name: 'Dougler',
|
|
201
|
+
age: 10
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const data = await service.update(doug[idProp], originalData, {
|
|
205
|
+
query: { $select: [ 'name' ] }
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
assert.strictEqual(data.name, 'Dougler', 'data.name matches');
|
|
209
|
+
assert.ok(!data.age, 'data.age is falsy');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('.update + id + query', async () => {
|
|
213
|
+
try {
|
|
214
|
+
await service.update(doug[idProp], {
|
|
215
|
+
name: 'Dougler'
|
|
216
|
+
}, {
|
|
217
|
+
query: { name: 'Tester' }
|
|
218
|
+
});
|
|
219
|
+
throw new Error('Should never get here');
|
|
220
|
+
} catch (error: any) {
|
|
221
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
222
|
+
'Got a NotFound Feathers error'
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('.update + NotFound', async () => {
|
|
228
|
+
try {
|
|
229
|
+
await service.update('568225fbfe21222432e836ff', { name: 'NotFound' });
|
|
230
|
+
throw new Error('Should never get here');
|
|
231
|
+
} catch (error: any) {
|
|
232
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
233
|
+
'Error is a NotFound Feathers error'
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('.update + query + NotFound', async () => {
|
|
239
|
+
const dave = await service.create({ name: 'Dave' });
|
|
240
|
+
try {
|
|
241
|
+
await service.update(
|
|
242
|
+
dave[idProp],
|
|
243
|
+
{ name: 'UpdatedDave' },
|
|
244
|
+
{ query: { name: 'NotDave' } }
|
|
245
|
+
);
|
|
246
|
+
throw new Error('Should never get here');
|
|
247
|
+
} catch (error: any) {
|
|
248
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
249
|
+
'Error is a NotFound Feathers error'
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
await service.remove(dave[idProp]);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('.update + id + query id', async () => {
|
|
256
|
+
const alice = await service.create({
|
|
257
|
+
name: 'Alice',
|
|
258
|
+
age: 12
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
await service.update(doug[idProp], {
|
|
263
|
+
name: 'Dougler',
|
|
264
|
+
age: 33
|
|
265
|
+
}, {
|
|
266
|
+
query: { [idProp]: alice[idProp] }
|
|
267
|
+
});
|
|
268
|
+
throw new Error('Should never get here');
|
|
269
|
+
} catch (error: any) {
|
|
270
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
271
|
+
'Got a NotFound Feathers error'
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
await service.remove(alice[idProp]);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe('patch', () => {
|
|
280
|
+
test('.patch', async () => {
|
|
281
|
+
const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' };
|
|
282
|
+
const originalCopy = Object.assign({}, originalData);
|
|
283
|
+
|
|
284
|
+
const data = await service.patch(doug[idProp], originalData);
|
|
285
|
+
|
|
286
|
+
assert.deepStrictEqual(originalData, originalCopy,
|
|
287
|
+
'original data was not modified'
|
|
288
|
+
);
|
|
289
|
+
assert.strictEqual(data[idProp].toString(), doug[idProp].toString(),
|
|
290
|
+
`${idProp} id matches`
|
|
291
|
+
);
|
|
292
|
+
assert.strictEqual(data.name, 'PatchDoug', 'data.name matches');
|
|
293
|
+
assert.strictEqual(data.age, 32, 'data.age matches');
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('.patch + $select', async () => {
|
|
297
|
+
const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' };
|
|
298
|
+
|
|
299
|
+
const data = await service.patch(doug[idProp], originalData, {
|
|
300
|
+
query: { $select: [ 'name' ] }
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
assert.strictEqual(data.name, 'PatchDoug', 'data.name matches');
|
|
304
|
+
assert.ok(!data.age, 'data.age is falsy');
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test('.patch + id + query', async () => {
|
|
308
|
+
try {
|
|
309
|
+
await service.patch(doug[idProp], {
|
|
310
|
+
name: 'id patched doug'
|
|
311
|
+
}, {
|
|
312
|
+
query: { name: 'Tester' }
|
|
313
|
+
});
|
|
314
|
+
throw new Error('Should never get here');
|
|
315
|
+
} catch (error: any) {
|
|
316
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
317
|
+
'Got a NotFound Feathers error'
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test('.patch multiple', async () => {
|
|
323
|
+
try {
|
|
324
|
+
await service.patch(null, {});
|
|
325
|
+
throw new Error('Should never get here');
|
|
326
|
+
} catch (error: any) {
|
|
327
|
+
assert.strictEqual(error.name, 'MethodNotAllowed',
|
|
328
|
+
'Removing multiple without option set throws MethodNotAllowed'
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const params = {
|
|
333
|
+
query: { created: true }
|
|
334
|
+
};
|
|
335
|
+
const dave = await service.create({
|
|
336
|
+
name: 'Dave',
|
|
337
|
+
age: 29,
|
|
338
|
+
created: true
|
|
339
|
+
});
|
|
340
|
+
const david = await service.create({
|
|
341
|
+
name: 'David',
|
|
342
|
+
age: 3,
|
|
343
|
+
created: true
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
service.options.multi = [ 'patch' ];
|
|
347
|
+
|
|
348
|
+
const data = await service.patch(null, {
|
|
349
|
+
age: 2
|
|
350
|
+
}, params);
|
|
351
|
+
|
|
352
|
+
assert.strictEqual(data.length, 2, 'returned two entries');
|
|
353
|
+
assert.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
354
|
+
assert.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
355
|
+
|
|
356
|
+
await service.remove(dave[idProp]);
|
|
357
|
+
await service.remove(david[idProp]);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('.patch multi query same', async () => {
|
|
361
|
+
const service = app.service(serviceName);
|
|
362
|
+
const params = {
|
|
363
|
+
query: { age: { $lt: 10 } }
|
|
364
|
+
};
|
|
365
|
+
const dave = await service.create({
|
|
366
|
+
name: 'Dave',
|
|
367
|
+
age: 8,
|
|
368
|
+
created: true
|
|
369
|
+
});
|
|
370
|
+
const david = await service.create({
|
|
371
|
+
name: 'David',
|
|
372
|
+
age: 4,
|
|
373
|
+
created: true
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
const data = await service.patch(null, {
|
|
377
|
+
age: 2
|
|
378
|
+
}, params);
|
|
379
|
+
|
|
380
|
+
assert.strictEqual(data.length, 2, 'returned two entries');
|
|
381
|
+
assert.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
382
|
+
assert.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
383
|
+
|
|
384
|
+
await service.remove(dave[idProp]);
|
|
385
|
+
await service.remove(david[idProp]);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test('.patch multi query changed', async () => {
|
|
389
|
+
const service = app.service(serviceName);
|
|
390
|
+
const params = {
|
|
391
|
+
query: { age: 10 }
|
|
392
|
+
};
|
|
393
|
+
const dave = await service.create({
|
|
394
|
+
name: 'Dave',
|
|
395
|
+
age: 10,
|
|
396
|
+
created: true
|
|
397
|
+
});
|
|
398
|
+
const david = await service.create({
|
|
399
|
+
name: 'David',
|
|
400
|
+
age: 10,
|
|
401
|
+
created: true
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
const data = await service.patch(null, {
|
|
405
|
+
age: 2
|
|
406
|
+
}, params);
|
|
407
|
+
|
|
408
|
+
assert.strictEqual(data.length, 2, 'returned two entries');
|
|
409
|
+
assert.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
410
|
+
assert.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
411
|
+
|
|
412
|
+
await service.remove(dave[idProp]);
|
|
413
|
+
await service.remove(david[idProp]);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test('.patch + NotFound', async () => {
|
|
417
|
+
try {
|
|
418
|
+
await service.patch('568225fbfe21222432e836ff', { name: 'PatchDoug' });
|
|
419
|
+
throw new Error('Should never get here');
|
|
420
|
+
} catch (error: any) {
|
|
421
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
422
|
+
'Error is a NotFound Feathers error'
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test('.patch + query + NotFound', async () => {
|
|
428
|
+
const dave = await service.create({ name: 'Dave' });
|
|
429
|
+
try {
|
|
430
|
+
await service.patch(
|
|
431
|
+
dave[idProp],
|
|
432
|
+
{ name: 'PatchedDave' },
|
|
433
|
+
{ query: { name: 'NotDave' } }
|
|
434
|
+
);
|
|
435
|
+
throw new Error('Should never get here');
|
|
436
|
+
} catch (error: any) {
|
|
437
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
438
|
+
'Error is a NotFound Feathers error'
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
await service.remove(dave[idProp]);
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
test('.patch + id + query id', async () => {
|
|
445
|
+
const alice = await service.create({
|
|
446
|
+
name: 'Alice',
|
|
447
|
+
age: 12
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
try {
|
|
451
|
+
await service.patch(doug[idProp], {
|
|
452
|
+
age: 33
|
|
453
|
+
}, {
|
|
454
|
+
query: { [idProp]: alice[idProp] }
|
|
455
|
+
});
|
|
456
|
+
throw new Error('Should never get here');
|
|
457
|
+
} catch (error: any) {
|
|
458
|
+
assert.strictEqual(error.name, 'NotFound',
|
|
459
|
+
'Got a NotFound Feathers error'
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
await service.remove(alice[idProp]);
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
describe('create', () => {
|
|
468
|
+
test('.create', async () => {
|
|
469
|
+
const originalData = {
|
|
470
|
+
name: 'Bill',
|
|
471
|
+
age: 40
|
|
472
|
+
};
|
|
473
|
+
const originalCopy = Object.assign({}, originalData);
|
|
474
|
+
|
|
475
|
+
const data = await service.create(originalData);
|
|
476
|
+
|
|
477
|
+
assert.deepStrictEqual(originalData, originalCopy,
|
|
478
|
+
'original data was not modified'
|
|
479
|
+
);
|
|
480
|
+
assert.ok(data instanceof Object, 'data is an object');
|
|
481
|
+
assert.strictEqual(data.name, 'Bill', 'data.name matches');
|
|
482
|
+
|
|
483
|
+
await service.remove(data[idProp]);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
test('.create + $select', async () => {
|
|
487
|
+
const originalData = {
|
|
488
|
+
name: 'William',
|
|
489
|
+
age: 23
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const data = await service.create(originalData, {
|
|
493
|
+
query: { $select: [ 'name' ] }
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
assert.strictEqual(data.name, 'William', 'data.name matches');
|
|
497
|
+
assert.ok(!data.age, 'data.age is falsy');
|
|
498
|
+
|
|
499
|
+
await service.remove(data[idProp]);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
test('.create multi', async () => {
|
|
503
|
+
try {
|
|
504
|
+
await service.create([], {});
|
|
505
|
+
throw new Error('Should never get here');
|
|
506
|
+
} catch (error: any) {
|
|
507
|
+
assert.strictEqual(error.name, 'MethodNotAllowed',
|
|
508
|
+
'Removing multiple without option set throws MethodNotAllowed'
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const items = [
|
|
513
|
+
{
|
|
514
|
+
name: 'Gerald',
|
|
515
|
+
age: 18
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
name: 'Herald',
|
|
519
|
+
age: 18
|
|
520
|
+
}
|
|
521
|
+
];
|
|
522
|
+
|
|
523
|
+
service.options.multi = [ 'create', 'patch' ];
|
|
524
|
+
|
|
525
|
+
const data = await service.create(items);
|
|
526
|
+
|
|
527
|
+
assert.ok(Array.isArray(data), 'data is an array');
|
|
528
|
+
assert.ok(typeof data[0][idProp] !== 'undefined', 'id is set');
|
|
529
|
+
assert.strictEqual(data[0].name, 'Gerald', 'first name matches');
|
|
530
|
+
assert.ok(typeof data[1][idProp] !== 'undefined', 'id is set');
|
|
531
|
+
assert.strictEqual(data[1].name, 'Herald', 'second name macthes');
|
|
532
|
+
|
|
533
|
+
await service.remove(data[0][idProp]);
|
|
534
|
+
await service.remove(data[1][idProp]);
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
describe('doesn\'t call public methods internally', () => {
|
|
539
|
+
let throwing: any;
|
|
540
|
+
|
|
541
|
+
before(() => {
|
|
542
|
+
throwing = app.service(serviceName).extend({
|
|
543
|
+
get store () {
|
|
544
|
+
return app.service(serviceName).store;
|
|
545
|
+
},
|
|
546
|
+
|
|
547
|
+
find () {
|
|
548
|
+
throw new Error('find method called');
|
|
549
|
+
},
|
|
550
|
+
get () {
|
|
551
|
+
throw new Error('get method called');
|
|
552
|
+
},
|
|
553
|
+
create () {
|
|
554
|
+
throw new Error('create method called');
|
|
555
|
+
},
|
|
556
|
+
update () {
|
|
557
|
+
throw new Error('update method called');
|
|
558
|
+
},
|
|
559
|
+
patch () {
|
|
560
|
+
throw new Error('patch method called');
|
|
561
|
+
},
|
|
562
|
+
remove () {
|
|
563
|
+
throw new Error('remove method called');
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
test('internal .find', () => app.service(serviceName).find.call(throwing));
|
|
569
|
+
|
|
570
|
+
test('internal .get', () =>
|
|
571
|
+
service.get.call(throwing, doug[idProp])
|
|
572
|
+
);
|
|
573
|
+
|
|
574
|
+
test('internal .create', async () => {
|
|
575
|
+
const bob = await service.create.call(throwing, {
|
|
576
|
+
name: 'Bob',
|
|
577
|
+
age: 25
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
await service.remove(bob[idProp]);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
test('internal .update', () =>
|
|
584
|
+
service.update.call(throwing, doug[idProp], {
|
|
585
|
+
name: 'Dougler'
|
|
586
|
+
})
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
test('internal .patch', () =>
|
|
590
|
+
service.patch.call(throwing, doug[idProp], {
|
|
591
|
+
name: 'PatchDoug'
|
|
592
|
+
})
|
|
593
|
+
);
|
|
594
|
+
|
|
595
|
+
test('internal .remove', () =>
|
|
596
|
+
service.remove.call(throwing, doug[idProp])
|
|
597
|
+
);
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
};
|