@feathersjs/adapter-tests 5.0.0-pre.2 → 5.0.0-pre.20
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 +179 -9
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/lib/basic.d.ts +2 -1
- package/lib/basic.js +18 -0
- package/lib/basic.js.map +1 -1
- package/lib/declarations.d.ts +8 -0
- package/lib/declarations.js +3 -0
- package/lib/declarations.js.map +1 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.js +23 -5
- package/lib/index.js.map +1 -1
- package/lib/methods.d.ts +2 -1
- package/lib/methods.js +206 -139
- package/lib/methods.js.map +1 -1
- package/lib/syntax.d.ts +2 -1
- package/lib/syntax.js +116 -90
- package/lib/syntax.js.map +1 -1
- package/package.json +15 -13
- package/src/basic.ts +26 -1
- package/src/declarations.ts +90 -0
- package/src/index.ts +12 -6
- package/src/methods.ts +127 -18
- package/src/syntax.ts +42 -1
package/src/basic.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
+
import { AdapterBasicTest } from './declarations';
|
|
2
3
|
|
|
3
|
-
export default (test:
|
|
4
|
+
export default (test: AdapterBasicTest, app: any, _errors: any, serviceName: string, idProp: string) => {
|
|
4
5
|
describe('Basic Functionality', () => {
|
|
5
6
|
let service: any;
|
|
6
7
|
|
|
@@ -48,6 +49,30 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
48
49
|
test('._remove', () => {
|
|
49
50
|
assert.strictEqual(typeof service._remove, 'function');
|
|
50
51
|
});
|
|
52
|
+
|
|
53
|
+
test('.$get', () => {
|
|
54
|
+
assert.strictEqual(typeof service.$get, 'function');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('.$find', () => {
|
|
58
|
+
assert.strictEqual(typeof service.$find, 'function');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('.$create', () => {
|
|
62
|
+
assert.strictEqual(typeof service.$create, 'function');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('.$update', () => {
|
|
66
|
+
assert.strictEqual(typeof service.$update, 'function');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('.$patch', () => {
|
|
70
|
+
assert.strictEqual(typeof service.$patch, 'function');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('.$remove', () => {
|
|
74
|
+
assert.strictEqual(typeof service.$remove, 'function');
|
|
75
|
+
});
|
|
51
76
|
});
|
|
52
77
|
});
|
|
53
78
|
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export type AdapterTest = (name: AdapterTestName, runner: any) => void;
|
|
2
|
+
|
|
3
|
+
export type AdapterBasicTest = (name: AdapterBasicTestName, runner: any) => void;
|
|
4
|
+
export type AdapterMethodsTest = (name: AdapterMethodsTestName, runner: any) => void;
|
|
5
|
+
export type AdapterSyntaxTest = (name: AdapterSyntaxTestName, runner: any) => void;
|
|
6
|
+
|
|
7
|
+
export type AdapterTestName = AdapterBasicTestName | AdapterMethodsTestName | AdapterSyntaxTestName;
|
|
8
|
+
|
|
9
|
+
export type AdapterBasicTestName =
|
|
10
|
+
'.id' |
|
|
11
|
+
'.options' |
|
|
12
|
+
'.events' |
|
|
13
|
+
'._get' |
|
|
14
|
+
'._find' |
|
|
15
|
+
'._create' |
|
|
16
|
+
'._update' |
|
|
17
|
+
'._patch' |
|
|
18
|
+
'._remove'|
|
|
19
|
+
'.$get' |
|
|
20
|
+
'.$find' |
|
|
21
|
+
'.$create' |
|
|
22
|
+
'.$update' |
|
|
23
|
+
'.$patch' |
|
|
24
|
+
'.$remove';
|
|
25
|
+
|
|
26
|
+
export type AdapterMethodsTestName =
|
|
27
|
+
'.get' |
|
|
28
|
+
'.get + $select' |
|
|
29
|
+
'.get + id + query' |
|
|
30
|
+
'.get + NotFound' |
|
|
31
|
+
'.get + id + query id' |
|
|
32
|
+
'.find' |
|
|
33
|
+
'.remove' |
|
|
34
|
+
'.remove + $select' |
|
|
35
|
+
'.remove + id + query' |
|
|
36
|
+
'.remove + multi' |
|
|
37
|
+
'.remove + multi no pagination' |
|
|
38
|
+
'.remove + id + query id' |
|
|
39
|
+
'.update' |
|
|
40
|
+
'.update + $select' |
|
|
41
|
+
'.update + id + query' |
|
|
42
|
+
'.update + NotFound' |
|
|
43
|
+
'.update + query + NotFound' |
|
|
44
|
+
'.update + id + query id' |
|
|
45
|
+
'.patch' |
|
|
46
|
+
'.patch + $select' |
|
|
47
|
+
'.patch + id + query' |
|
|
48
|
+
'.patch multiple' |
|
|
49
|
+
'.patch multiple no pagination' |
|
|
50
|
+
'.patch multi query same' |
|
|
51
|
+
'.patch multi query changed' |
|
|
52
|
+
'.patch + NotFound' |
|
|
53
|
+
'.patch + query + NotFound' |
|
|
54
|
+
'.patch + id + query id' |
|
|
55
|
+
'.create' |
|
|
56
|
+
'.create + $select' |
|
|
57
|
+
'.create multi' |
|
|
58
|
+
'internal .find' |
|
|
59
|
+
'internal .get' |
|
|
60
|
+
'internal .create' |
|
|
61
|
+
'internal .update' |
|
|
62
|
+
'internal .patch' |
|
|
63
|
+
'internal .remove';
|
|
64
|
+
|
|
65
|
+
export type AdapterSyntaxTestName =
|
|
66
|
+
'.find + equal' |
|
|
67
|
+
'.find + equal multiple' |
|
|
68
|
+
'.find + $sort' |
|
|
69
|
+
'.find + $sort + string' |
|
|
70
|
+
'.find + $limit' |
|
|
71
|
+
'.find + $limit 0' |
|
|
72
|
+
'.find + $skip' |
|
|
73
|
+
'.find + $select' |
|
|
74
|
+
'.find + $or' |
|
|
75
|
+
'.find + $in' |
|
|
76
|
+
'.find + $nin' |
|
|
77
|
+
'.find + $lt' |
|
|
78
|
+
'.find + $lte' |
|
|
79
|
+
'.find + $gt' |
|
|
80
|
+
'.find + $gte' |
|
|
81
|
+
'.find + $ne' |
|
|
82
|
+
'.find + $gt + $lt + $sort' |
|
|
83
|
+
'.find + $or nested + $sort' |
|
|
84
|
+
'params.adapter + paginate' |
|
|
85
|
+
'params.adapter + multi' |
|
|
86
|
+
'.find + paginate' |
|
|
87
|
+
'.find + paginate + query' |
|
|
88
|
+
'.find + paginate + $limit + $skip' |
|
|
89
|
+
'.find + paginate + $limit 0' |
|
|
90
|
+
'.find + paginate + params';
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import basicTests from './basic';
|
|
3
|
+
import { AdapterTestName } from './declarations';
|
|
3
4
|
import methodTests from './methods';
|
|
4
5
|
import syntaxTests from './syntax';
|
|
5
6
|
|
|
6
|
-
const adapterTests = (testNames:
|
|
7
|
+
const adapterTests = (testNames: AdapterTestName[]) => {
|
|
7
8
|
return (app: any, errors: any, serviceName: any, idProp = 'id') => {
|
|
8
9
|
if (!serviceName) {
|
|
9
10
|
throw new Error('You must pass a service name');
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
const skippedTests:
|
|
13
|
-
const allTests:
|
|
13
|
+
const skippedTests: AdapterTestName[] = [];
|
|
14
|
+
const allTests: AdapterTestName[] = [];
|
|
14
15
|
|
|
15
|
-
const test = (name:
|
|
16
|
+
const test = (name: AdapterTestName, runner: any) => {
|
|
16
17
|
const skip = !testNames.includes(name);
|
|
17
18
|
const its = skip ? it.skip : it;
|
|
18
19
|
|
|
@@ -27,7 +28,6 @@ const adapterTests = (testNames: string[]) => {
|
|
|
27
28
|
|
|
28
29
|
describe(`Adapter tests for '${serviceName}' service with '${idProp}' id property`, () => {
|
|
29
30
|
after(() => {
|
|
30
|
-
console.log('\n');
|
|
31
31
|
testNames.forEach(name => {
|
|
32
32
|
if (!allTests.includes(name)) {
|
|
33
33
|
console.error(`WARNING: '${name}' test is not part of the test suite`);
|
|
@@ -46,4 +46,10 @@ const adapterTests = (testNames: string[]) => {
|
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export
|
|
49
|
+
export * from './declarations'
|
|
50
|
+
|
|
51
|
+
export default adapterTests;
|
|
52
|
+
|
|
53
|
+
if (typeof module !== 'undefined') {
|
|
54
|
+
module.exports = Object.assign(adapterTests, module.exports);
|
|
55
|
+
}
|
package/src/methods.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
+
import { AdapterMethodsTest } from './declarations';
|
|
2
3
|
|
|
3
|
-
export default (test:
|
|
4
|
+
export default (test: AdapterMethodsTest, app: any, _errors: any, serviceName: string, idProp: string) => {
|
|
4
5
|
describe(' Methods', () => {
|
|
5
6
|
let doug: any;
|
|
6
7
|
let service: any;
|
|
@@ -16,7 +17,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
16
17
|
afterEach(async () => {
|
|
17
18
|
try {
|
|
18
19
|
await app.service(serviceName).remove(doug[idProp]);
|
|
19
|
-
} catch (error) {}
|
|
20
|
+
} catch (error: any) {}
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
describe('get', () => {
|
|
@@ -48,7 +49,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
48
49
|
query: { name: 'Tester' }
|
|
49
50
|
});
|
|
50
51
|
throw new Error('Should never get here');
|
|
51
|
-
} catch (error) {
|
|
52
|
+
} catch (error: any) {
|
|
52
53
|
assert.strictEqual(error.name, 'NotFound',
|
|
53
54
|
'Got a NotFound Feathers error'
|
|
54
55
|
);
|
|
@@ -59,7 +60,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
59
60
|
try {
|
|
60
61
|
await service.get('568225fbfe21222432e836ff');
|
|
61
62
|
throw new Error('Should never get here');
|
|
62
|
-
} catch (error) {
|
|
63
|
+
} catch (error: any) {
|
|
63
64
|
assert.strictEqual(error.name, 'NotFound',
|
|
64
65
|
'Error is a NotFound Feathers error'
|
|
65
66
|
);
|
|
@@ -77,7 +78,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
77
78
|
query: { [idProp]: alice[idProp] }
|
|
78
79
|
});
|
|
79
80
|
throw new Error('Should never get here');
|
|
80
|
-
} catch (error) {
|
|
81
|
+
} catch (error: any) {
|
|
81
82
|
assert.strictEqual(error.name, 'NotFound',
|
|
82
83
|
'Got a NotFound Feathers error'
|
|
83
84
|
);
|
|
@@ -118,7 +119,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
118
119
|
query: { name: 'Tester' }
|
|
119
120
|
});
|
|
120
121
|
throw new Error('Should never get here');
|
|
121
|
-
} catch (error) {
|
|
122
|
+
} catch (error: any) {
|
|
122
123
|
assert.strictEqual(error.name, 'NotFound',
|
|
123
124
|
'Got a NotFound Feathers error'
|
|
124
125
|
);
|
|
@@ -129,7 +130,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
129
130
|
try {
|
|
130
131
|
await service.remove(null);
|
|
131
132
|
throw new Error('Should never get here');
|
|
132
|
-
} catch (error) {
|
|
133
|
+
} catch (error: any) {
|
|
133
134
|
assert.strictEqual(error.name, 'MethodNotAllowed',
|
|
134
135
|
'Removing multiple without option set throws MethodNotAllowed'
|
|
135
136
|
);
|
|
@@ -156,6 +157,51 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
156
157
|
assert.ok(names.includes('David'), 'David removed');
|
|
157
158
|
});
|
|
158
159
|
|
|
160
|
+
test('.remove + multi no pagination', async () => {
|
|
161
|
+
try {
|
|
162
|
+
await service.remove(doug[idProp]);
|
|
163
|
+
} catch (error: any) {}
|
|
164
|
+
|
|
165
|
+
const count = 14;
|
|
166
|
+
const defaultPaginate = 10;
|
|
167
|
+
|
|
168
|
+
assert.ok(count > defaultPaginate, 'count is bigger than default pagination');
|
|
169
|
+
|
|
170
|
+
const multiBefore = service.options.multi;
|
|
171
|
+
const paginateBefore = service.options.paginate;
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
service.options.multi = true;
|
|
175
|
+
service.options.paginate = {
|
|
176
|
+
'default': defaultPaginate,
|
|
177
|
+
'max': 100
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const emptyItems = await service.find({ paginate: false });
|
|
181
|
+
assert.strictEqual(emptyItems.length, 0, 'no items before')
|
|
182
|
+
|
|
183
|
+
const createdItems = await service.create(
|
|
184
|
+
Array.from(Array(count)).map((_, i) => ({ name: `name-${i}`, age: 3, created: true }))
|
|
185
|
+
);
|
|
186
|
+
assert.strictEqual(createdItems.length, count, `created ${count} items`);
|
|
187
|
+
|
|
188
|
+
const foundItems = await service.find({ paginate: false });
|
|
189
|
+
assert.strictEqual(foundItems.length, count, `created ${count} items`);
|
|
190
|
+
|
|
191
|
+
const foundPaginatedItems = await service.find({});
|
|
192
|
+
assert.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated items');
|
|
193
|
+
|
|
194
|
+
const allItems = await service.remove(null, { query: { created: true } });
|
|
195
|
+
|
|
196
|
+
assert.strictEqual(allItems.length, count, `removed all ${ count } items`);
|
|
197
|
+
} finally {
|
|
198
|
+
await service.remove(null, { query: { created: true }, paginate: false });
|
|
199
|
+
|
|
200
|
+
service.options.multi = multiBefore;
|
|
201
|
+
service.options.paginate = paginateBefore;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
159
205
|
test('.remove + id + query id', async () => {
|
|
160
206
|
const alice = await service.create({
|
|
161
207
|
name: 'Alice',
|
|
@@ -167,7 +213,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
167
213
|
query: { [idProp]: alice[idProp] }
|
|
168
214
|
});
|
|
169
215
|
throw new Error('Should never get here');
|
|
170
|
-
} catch (error) {
|
|
216
|
+
} catch (error: any) {
|
|
171
217
|
assert.strictEqual(error.name, 'NotFound',
|
|
172
218
|
'Got a NotFound Feathers error'
|
|
173
219
|
);
|
|
@@ -217,7 +263,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
217
263
|
query: { name: 'Tester' }
|
|
218
264
|
});
|
|
219
265
|
throw new Error('Should never get here');
|
|
220
|
-
} catch (error) {
|
|
266
|
+
} catch (error: any) {
|
|
221
267
|
assert.strictEqual(error.name, 'NotFound',
|
|
222
268
|
'Got a NotFound Feathers error'
|
|
223
269
|
);
|
|
@@ -228,7 +274,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
228
274
|
try {
|
|
229
275
|
await service.update('568225fbfe21222432e836ff', { name: 'NotFound' });
|
|
230
276
|
throw new Error('Should never get here');
|
|
231
|
-
} catch (error) {
|
|
277
|
+
} catch (error: any) {
|
|
232
278
|
assert.strictEqual(error.name, 'NotFound',
|
|
233
279
|
'Error is a NotFound Feathers error'
|
|
234
280
|
);
|
|
@@ -244,7 +290,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
244
290
|
{ query: { name: 'NotDave' } }
|
|
245
291
|
);
|
|
246
292
|
throw new Error('Should never get here');
|
|
247
|
-
} catch (error) {
|
|
293
|
+
} catch (error: any) {
|
|
248
294
|
assert.strictEqual(error.name, 'NotFound',
|
|
249
295
|
'Error is a NotFound Feathers error'
|
|
250
296
|
);
|
|
@@ -266,7 +312,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
266
312
|
query: { [idProp]: alice[idProp] }
|
|
267
313
|
});
|
|
268
314
|
throw new Error('Should never get here');
|
|
269
|
-
} catch (error) {
|
|
315
|
+
} catch (error: any) {
|
|
270
316
|
assert.strictEqual(error.name, 'NotFound',
|
|
271
317
|
'Got a NotFound Feathers error'
|
|
272
318
|
);
|
|
@@ -312,7 +358,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
312
358
|
query: { name: 'Tester' }
|
|
313
359
|
});
|
|
314
360
|
throw new Error('Should never get here');
|
|
315
|
-
} catch (error) {
|
|
361
|
+
} catch (error: any) {
|
|
316
362
|
assert.strictEqual(error.name, 'NotFound',
|
|
317
363
|
'Got a NotFound Feathers error'
|
|
318
364
|
);
|
|
@@ -323,7 +369,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
323
369
|
try {
|
|
324
370
|
await service.patch(null, {});
|
|
325
371
|
throw new Error('Should never get here');
|
|
326
|
-
} catch (error) {
|
|
372
|
+
} catch (error: any) {
|
|
327
373
|
assert.strictEqual(error.name, 'MethodNotAllowed',
|
|
328
374
|
'Removing multiple without option set throws MethodNotAllowed'
|
|
329
375
|
);
|
|
@@ -357,8 +403,63 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
357
403
|
await service.remove(david[idProp]);
|
|
358
404
|
});
|
|
359
405
|
|
|
406
|
+
test('.patch multiple no pagination', async () => {
|
|
407
|
+
try {
|
|
408
|
+
await service.remove(doug[idProp]);
|
|
409
|
+
} catch (error: any) {}
|
|
410
|
+
|
|
411
|
+
const count = 14;
|
|
412
|
+
const defaultPaginate = 10;
|
|
413
|
+
|
|
414
|
+
assert.ok(count > defaultPaginate, 'count is bigger than default pagination');
|
|
415
|
+
|
|
416
|
+
const multiBefore = service.options.multi;
|
|
417
|
+
const paginateBefore = service.options.paginate;
|
|
418
|
+
|
|
419
|
+
let ids: any[];
|
|
420
|
+
|
|
421
|
+
try {
|
|
422
|
+
service.options.multi = true;
|
|
423
|
+
service.options.paginate = {
|
|
424
|
+
'default': defaultPaginate,
|
|
425
|
+
'max': 100
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
const emptyItems = await service.find({ paginate: false });
|
|
429
|
+
assert.strictEqual(emptyItems.length, 0, 'no items before')
|
|
430
|
+
|
|
431
|
+
const createdItems = await service.create(
|
|
432
|
+
Array.from(Array(count)).map((_, i) => ({ name: `name-${i}`, age: 3, created: true }))
|
|
433
|
+
);
|
|
434
|
+
assert.strictEqual(createdItems.length, count, `created ${count} items`);
|
|
435
|
+
ids = createdItems.map((item: any) => item[idProp]);
|
|
436
|
+
|
|
437
|
+
const foundItems = await service.find({ paginate: false });
|
|
438
|
+
assert.strictEqual(foundItems.length, count, `created ${count} items`);
|
|
439
|
+
|
|
440
|
+
const foundPaginatedItems = await service.find({});
|
|
441
|
+
assert.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated data')
|
|
442
|
+
|
|
443
|
+
const allItems = await service.patch(null, { age: 4 }, { query: { created: true } })
|
|
444
|
+
|
|
445
|
+
assert.strictEqual(allItems.length, count, `patched all ${ count } items`);
|
|
446
|
+
} finally {
|
|
447
|
+
service.options.multi = multiBefore;
|
|
448
|
+
service.options.paginate = paginateBefore;
|
|
449
|
+
if (ids) {
|
|
450
|
+
await Promise.all(
|
|
451
|
+
ids.map(id => service.remove(id))
|
|
452
|
+
)
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
|
|
360
457
|
test('.patch multi query same', async () => {
|
|
361
458
|
const service = app.service(serviceName);
|
|
459
|
+
const multiBefore = service.options.multi;
|
|
460
|
+
|
|
461
|
+
service.options.multi = true;
|
|
462
|
+
|
|
362
463
|
const params = {
|
|
363
464
|
query: { age: { $lt: 10 } }
|
|
364
465
|
};
|
|
@@ -383,10 +484,16 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
383
484
|
|
|
384
485
|
await service.remove(dave[idProp]);
|
|
385
486
|
await service.remove(david[idProp]);
|
|
487
|
+
|
|
488
|
+
service.options.multi = multiBefore;
|
|
386
489
|
});
|
|
387
490
|
|
|
388
491
|
test('.patch multi query changed', async () => {
|
|
389
492
|
const service = app.service(serviceName);
|
|
493
|
+
const multiBefore = service.options.multi;
|
|
494
|
+
|
|
495
|
+
service.options.multi = true;
|
|
496
|
+
|
|
390
497
|
const params = {
|
|
391
498
|
query: { age: 10 }
|
|
392
499
|
};
|
|
@@ -411,13 +518,15 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
411
518
|
|
|
412
519
|
await service.remove(dave[idProp]);
|
|
413
520
|
await service.remove(david[idProp]);
|
|
521
|
+
|
|
522
|
+
service.options.multi = multiBefore;
|
|
414
523
|
});
|
|
415
524
|
|
|
416
525
|
test('.patch + NotFound', async () => {
|
|
417
526
|
try {
|
|
418
527
|
await service.patch('568225fbfe21222432e836ff', { name: 'PatchDoug' });
|
|
419
528
|
throw new Error('Should never get here');
|
|
420
|
-
} catch (error) {
|
|
529
|
+
} catch (error: any) {
|
|
421
530
|
assert.strictEqual(error.name, 'NotFound',
|
|
422
531
|
'Error is a NotFound Feathers error'
|
|
423
532
|
);
|
|
@@ -433,7 +542,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
433
542
|
{ query: { name: 'NotDave' } }
|
|
434
543
|
);
|
|
435
544
|
throw new Error('Should never get here');
|
|
436
|
-
} catch (error) {
|
|
545
|
+
} catch (error: any) {
|
|
437
546
|
assert.strictEqual(error.name, 'NotFound',
|
|
438
547
|
'Error is a NotFound Feathers error'
|
|
439
548
|
);
|
|
@@ -454,7 +563,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
454
563
|
query: { [idProp]: alice[idProp] }
|
|
455
564
|
});
|
|
456
565
|
throw new Error('Should never get here');
|
|
457
|
-
} catch (error) {
|
|
566
|
+
} catch (error: any) {
|
|
458
567
|
assert.strictEqual(error.name, 'NotFound',
|
|
459
568
|
'Got a NotFound Feathers error'
|
|
460
569
|
);
|
|
@@ -503,7 +612,7 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
503
612
|
try {
|
|
504
613
|
await service.create([], {});
|
|
505
614
|
throw new Error('Should never get here');
|
|
506
|
-
} catch (error) {
|
|
615
|
+
} catch (error: any) {
|
|
507
616
|
assert.strictEqual(error.name, 'MethodNotAllowed',
|
|
508
617
|
'Removing multiple without option set throws MethodNotAllowed'
|
|
509
618
|
);
|
package/src/syntax.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
+
import { AdapterSyntaxTest } from './declarations';
|
|
2
3
|
|
|
3
|
-
export default (test:
|
|
4
|
+
export default (test: AdapterSyntaxTest, app: any, _errors: any, serviceName: string, idProp: string) => {
|
|
4
5
|
describe('Query Syntax', () => {
|
|
5
6
|
let bob: any;
|
|
6
7
|
let alice: any;
|
|
@@ -276,6 +277,46 @@ export default (test: any, app: any, _errors: any, serviceName: string, idProp:
|
|
|
276
277
|
assert.strictEqual(data[1].name, 'Doug');
|
|
277
278
|
});
|
|
278
279
|
|
|
280
|
+
describe('params.adapter', () => {
|
|
281
|
+
test('params.adapter + paginate', async () => {
|
|
282
|
+
const page = await service.find({
|
|
283
|
+
adapter: {
|
|
284
|
+
paginate: { default: 3 }
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
assert.strictEqual(page.limit, 3);
|
|
289
|
+
assert.strictEqual(page.skip, 0);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('params.adapter + multi', async () => {
|
|
293
|
+
const items = [
|
|
294
|
+
{
|
|
295
|
+
name: 'Garald',
|
|
296
|
+
age: 200
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
name: 'Harald',
|
|
300
|
+
age: 24
|
|
301
|
+
}
|
|
302
|
+
];
|
|
303
|
+
const multiParams = {
|
|
304
|
+
adapter: {
|
|
305
|
+
multi: ['create']
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
const users = await service.create(items, multiParams);
|
|
309
|
+
|
|
310
|
+
assert.strictEqual(users.length, 2);
|
|
311
|
+
|
|
312
|
+
await service.remove(users[0][idProp]);
|
|
313
|
+
await service.remove(users[1][idProp]);
|
|
314
|
+
await assert.rejects(() => service.patch(null, { age: 2 }, multiParams), {
|
|
315
|
+
message: 'Can not patch multiple entries'
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
279
320
|
describe('paginate', function () {
|
|
280
321
|
beforeEach(() => {
|
|
281
322
|
service.options.paginate = {
|