feathers-adapter-vitest 0.0.2 → 0.0.3
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/dist/basic.d.ts +8 -1
- package/dist/basic.js +2 -1
- package/dist/declarations.d.ts +1 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +7 -15
- package/dist/methods.d.ts +8 -1
- package/dist/methods.js +64 -139
- package/dist/syntax.d.ts +8 -1
- package/dist/syntax.js +2 -1
- package/package.json +3 -1
- package/src/methods.ts +129 -209
package/dist/basic.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { AdapterBasicTest } from './declarations.js';
|
|
2
|
-
|
|
2
|
+
import type { Application } from '@feathersjs/feathers';
|
|
3
|
+
type BasicTestOptions = {
|
|
4
|
+
app: Application;
|
|
5
|
+
test: AdapterBasicTest;
|
|
6
|
+
serviceName: string;
|
|
7
|
+
idProp: string;
|
|
8
|
+
};
|
|
9
|
+
declare const _default: (options: BasicTestOptions) => void;
|
|
3
10
|
export default _default;
|
package/dist/basic.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { describe, beforeEach, it } from 'vitest';
|
|
3
|
-
export default (
|
|
3
|
+
export default (options) => {
|
|
4
|
+
const { test, app, serviceName, idProp } = options;
|
|
4
5
|
describe('Basic Functionality', () => {
|
|
5
6
|
let service;
|
|
6
7
|
beforeEach(() => {
|
package/dist/declarations.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type AdapterBasicTest = (name: AdapterBasicTestName, runner: any) => void
|
|
|
3
3
|
export type AdapterMethodsTest = (name: AdapterMethodsTestName, runner: any) => void;
|
|
4
4
|
export type AdapterSyntaxTest = (name: AdapterSyntaxTestName, runner: any) => void;
|
|
5
5
|
export type AdapterTestName = AdapterBasicTestName | AdapterMethodsTestName | AdapterSyntaxTestName;
|
|
6
|
+
export type AdapterTestMap = Record<AdapterTestName, boolean>;
|
|
6
7
|
export type AdapterBasicTestName = '.id' | '.options' | '.events' | '._get' | '._find' | '._create' | '._update' | '._patch' | '._remove' | '.$get' | '.$find' | '.$create' | '.$update' | '.$patch' | '.$remove';
|
|
7
8
|
export type AdapterMethodsTestName = '.get' | '.get + $select' | '.get + id + query' | '.get + NotFound' | '.get + id + query id' | '.find' | '.remove' | '.remove + $select' | '.remove + id + query' | '.remove + multi' | '.remove + multi no pagination' | '.remove + id + query id' | '.update' | '.update + $select' | '.update + id + query' | '.update + NotFound' | '.update + query + NotFound' | '.update + id + query id' | '.patch' | '.patch + $select' | '.patch + id + query' | '.patch multiple' | '.patch multiple no pagination' | '.patch multi query same' | '.patch multi query changed' | '.patch + NotFound' | '.patch + query + NotFound' | '.patch + id + query id' | '.create' | '.create + $select' | '.create multi' | '.create ignores query' | 'internal .find' | 'internal .get' | 'internal .create' | 'internal .update' | 'internal .patch' | 'internal .remove';
|
|
8
9
|
export type AdapterSyntaxTestName = '.find + equal' | '.find + equal multiple' | '.find + $sort' | '.find + $sort + string' | '.find + $limit' | '.find + $limit 0' | '.find + $skip' | '.find + $select' | '.find + $or' | '.find + $in' | '.find + $nin' | '.find + $lt' | '.find + $lte' | '.find + $gt' | '.find + $gte' | '.find + $ne' | '.find + $gt + $lt + $sort' | '.find + $or nested + $sort' | '.find + $and' | '.find + $and + $or' | 'params.adapter + paginate' | 'params.adapter + multi' | '.find + paginate' | '.find + paginate + query' | '.find + paginate + $limit + $skip' | '.find + paginate + $limit 0' | '.find + paginate + params';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { Application } from '@feathersjs/feathers';
|
|
2
|
+
import type { AdapterTestMap } from './declarations.js';
|
|
3
|
+
export type TestSuiteOptions = {
|
|
4
|
+
app: Application;
|
|
5
|
+
serviceName: string;
|
|
6
|
+
/**
|
|
7
|
+
* @default 'id'
|
|
8
|
+
*/
|
|
9
|
+
idProp?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const defineTestSuite: (testMap?: AdapterTestMap) => (options: TestSuiteOptions) => void;
|
|
3
12
|
export * from './declarations.js';
|
|
4
|
-
export default adapterTests;
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,13 @@ import basicTests from './basic.js';
|
|
|
2
2
|
import methodTests from './methods.js';
|
|
3
3
|
import syntaxTests from './syntax.js';
|
|
4
4
|
import { describe, it, afterAll } from 'vitest';
|
|
5
|
-
export const
|
|
6
|
-
return (
|
|
7
|
-
|
|
8
|
-
throw new Error('You must pass a service name');
|
|
9
|
-
}
|
|
5
|
+
export const defineTestSuite = (testMap) => {
|
|
6
|
+
return (options) => {
|
|
7
|
+
const { app, serviceName, idProp = 'id' } = options;
|
|
10
8
|
const skippedTests = [];
|
|
11
9
|
const allTests = [];
|
|
12
10
|
const test = (name, runner) => {
|
|
13
|
-
const skip = !
|
|
11
|
+
const skip = testMap ? !testMap[name] : false;
|
|
14
12
|
const its = skip ? it.skip : it;
|
|
15
13
|
if (skip) {
|
|
16
14
|
skippedTests.push(name);
|
|
@@ -20,21 +18,15 @@ export const adapterTests = (testNames) => {
|
|
|
20
18
|
};
|
|
21
19
|
describe(`Adapter tests for '${serviceName}' service with '${idProp}' id property`, () => {
|
|
22
20
|
afterAll(() => {
|
|
23
|
-
testNames.forEach((name) => {
|
|
24
|
-
if (!allTests.includes(name)) {
|
|
25
|
-
console.error(`WARNING: '${name}' test is not part of the test suite`);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
21
|
if (skippedTests.length) {
|
|
29
22
|
console.log(`\nSkipped the following ${skippedTests.length} Feathers adapter test(s) out of ${allTests.length} total:`);
|
|
30
23
|
console.log(JSON.stringify(skippedTests, null, ' '));
|
|
31
24
|
}
|
|
32
25
|
});
|
|
33
|
-
basicTests(test, app,
|
|
34
|
-
methodTests(test, app,
|
|
35
|
-
syntaxTests(test, app,
|
|
26
|
+
basicTests({ test, app, serviceName, idProp });
|
|
27
|
+
methodTests({ test, app, serviceName, idProp });
|
|
28
|
+
syntaxTests({ test, app, serviceName, idProp });
|
|
36
29
|
});
|
|
37
30
|
};
|
|
38
31
|
};
|
|
39
32
|
export * from './declarations.js';
|
|
40
|
-
export default adapterTests;
|
package/dist/methods.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { AdapterMethodsTest } from './declarations.js';
|
|
2
|
-
|
|
2
|
+
import type { Application } from '@feathersjs/feathers';
|
|
3
|
+
type MethodTestOptions = {
|
|
4
|
+
app: Application;
|
|
5
|
+
test: AdapterMethodsTest;
|
|
6
|
+
serviceName: string;
|
|
7
|
+
idProp: string;
|
|
8
|
+
};
|
|
9
|
+
declare const _default: (options: MethodTestOptions) => void;
|
|
3
10
|
export default _default;
|
package/dist/methods.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { describe, beforeEach, afterEach, beforeAll } from 'vitest';
|
|
3
|
-
|
|
3
|
+
import { MethodNotAllowed, NotFound } from '@feathersjs/errors';
|
|
4
|
+
export default (options) => {
|
|
5
|
+
const { test, app, serviceName, idProp } = options;
|
|
4
6
|
describe(' Methods', () => {
|
|
5
7
|
let doug;
|
|
6
8
|
let service;
|
|
@@ -35,39 +37,21 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
35
37
|
assert.ok(!data.age, 'data.age is falsy');
|
|
36
38
|
});
|
|
37
39
|
test('.get + id + query', async () => {
|
|
38
|
-
|
|
39
|
-
await service.get(doug[idProp], {
|
|
40
|
-
query: { name: 'Tester' },
|
|
41
|
-
});
|
|
42
|
-
throw new Error('Should never get here');
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
46
|
-
}
|
|
40
|
+
await assert.rejects(() => service.get(doug[idProp], { query: { name: 'Tester' } }), NotFound);
|
|
47
41
|
});
|
|
48
42
|
test('.get + NotFound', async () => {
|
|
49
|
-
|
|
43
|
+
await assert.rejects(async () => {
|
|
50
44
|
await service.get('568225fbfe21222432e836ff');
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
assert.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
55
|
-
}
|
|
45
|
+
}, NotFound);
|
|
56
46
|
});
|
|
57
47
|
test('.get + id + query id', async () => {
|
|
58
48
|
const alice = await service.create({
|
|
59
49
|
name: 'Alice',
|
|
60
50
|
age: 12,
|
|
61
51
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
throw new Error('Should never get here');
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
70
|
-
}
|
|
52
|
+
await assert.rejects(() => service.get(doug[idProp], {
|
|
53
|
+
query: { [idProp]: alice[idProp] },
|
|
54
|
+
}), NotFound);
|
|
71
55
|
await service.remove(alice[idProp]);
|
|
72
56
|
});
|
|
73
57
|
});
|
|
@@ -92,24 +76,14 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
92
76
|
assert.ok(!data.age, 'data.age is falsy');
|
|
93
77
|
});
|
|
94
78
|
test('.remove + id + query', async () => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
103
|
-
}
|
|
79
|
+
await assert.rejects(() => service.remove(doug[idProp], {
|
|
80
|
+
query: { name: 'Tester' },
|
|
81
|
+
}), NotFound);
|
|
82
|
+
const stillExists = await service.get(doug[idProp]);
|
|
83
|
+
assert.ok(stillExists, 'Doug still exists');
|
|
104
84
|
});
|
|
105
85
|
test('.remove + multi', async () => {
|
|
106
|
-
|
|
107
|
-
await service.remove(null);
|
|
108
|
-
throw new Error('Should never get here');
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
assert.strictEqual(error.name, 'MethodNotAllowed', 'Removing multiple without option set throws MethodNotAllowed');
|
|
112
|
-
}
|
|
86
|
+
await assert.rejects(() => service.remove(null), MethodNotAllowed);
|
|
113
87
|
service.options.multi = ['remove'];
|
|
114
88
|
await service.create({ name: 'Dave', age: 29, created: true });
|
|
115
89
|
await service.create({
|
|
@@ -174,15 +148,11 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
174
148
|
name: 'Alice',
|
|
175
149
|
age: 12,
|
|
176
150
|
});
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
catch (error) {
|
|
184
|
-
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
185
|
-
}
|
|
151
|
+
await assert.rejects(() => service.remove(doug[idProp], {
|
|
152
|
+
query: { [idProp]: alice[idProp] },
|
|
153
|
+
}), NotFound);
|
|
154
|
+
const stillExists = await service.get(doug[idProp]);
|
|
155
|
+
assert.ok(stillExists, 'Doug still exists');
|
|
186
156
|
await service.remove(alice[idProp]);
|
|
187
157
|
});
|
|
188
158
|
});
|
|
@@ -208,40 +178,23 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
208
178
|
assert.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id property matches`);
|
|
209
179
|
assert.strictEqual(data.name, 'Dougler', 'data.name matches');
|
|
210
180
|
assert.ok(!data.age, 'data.age is falsy');
|
|
181
|
+
// TODO: service.get(doug[idProp]) should have age set to 10
|
|
211
182
|
});
|
|
212
183
|
test('.update + id + query', async () => {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
});
|
|
219
|
-
throw new Error('Should never get here');
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
223
|
-
}
|
|
184
|
+
await assert.rejects(() => service.update(doug[idProp], {
|
|
185
|
+
name: 'Dougler',
|
|
186
|
+
}, {
|
|
187
|
+
query: { name: 'Tester' },
|
|
188
|
+
}), NotFound);
|
|
224
189
|
});
|
|
225
190
|
test('.update + NotFound', async () => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
});
|
|
230
|
-
throw new Error('Should never get here');
|
|
231
|
-
}
|
|
232
|
-
catch (error) {
|
|
233
|
-
assert.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
234
|
-
}
|
|
191
|
+
await assert.rejects(() => service.update('568225fbfe21222432e836ff', {
|
|
192
|
+
name: 'NotFound',
|
|
193
|
+
}), NotFound);
|
|
235
194
|
});
|
|
236
195
|
test('.update + query + NotFound', async () => {
|
|
237
196
|
const dave = await service.create({ name: 'Dave' });
|
|
238
|
-
|
|
239
|
-
await service.update(dave[idProp], { name: 'UpdatedDave' }, { query: { name: 'NotDave' } });
|
|
240
|
-
throw new Error('Should never get here');
|
|
241
|
-
}
|
|
242
|
-
catch (error) {
|
|
243
|
-
assert.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
244
|
-
}
|
|
197
|
+
await assert.rejects(() => service.update(dave[idProp], { name: 'UpdatedDave' }, { query: { name: 'NotDave' } }), NotFound);
|
|
245
198
|
await service.remove(dave[idProp]);
|
|
246
199
|
});
|
|
247
200
|
test('.update + id + query id', async () => {
|
|
@@ -249,18 +202,12 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
249
202
|
name: 'Alice',
|
|
250
203
|
age: 12,
|
|
251
204
|
});
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
},
|
|
257
|
-
|
|
258
|
-
});
|
|
259
|
-
throw new Error('Should never get here');
|
|
260
|
-
}
|
|
261
|
-
catch (error) {
|
|
262
|
-
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
263
|
-
}
|
|
205
|
+
await assert.rejects(() => service.update(doug[idProp], {
|
|
206
|
+
name: 'Dougler',
|
|
207
|
+
age: 33,
|
|
208
|
+
}, {
|
|
209
|
+
query: { [idProp]: alice[idProp] },
|
|
210
|
+
}), NotFound);
|
|
264
211
|
await service.remove(alice[idProp]);
|
|
265
212
|
});
|
|
266
213
|
});
|
|
@@ -282,28 +229,17 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
282
229
|
assert.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id property matches`);
|
|
283
230
|
assert.strictEqual(data.name, 'PatchDoug', 'data.name matches');
|
|
284
231
|
assert.ok(!data.age, 'data.age is falsy');
|
|
232
|
+
// TODO: service.get(doug[idProp]) should have age set to 10
|
|
285
233
|
});
|
|
286
234
|
test('.patch + id + query', async () => {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
},
|
|
291
|
-
|
|
292
|
-
});
|
|
293
|
-
throw new Error('Should never get here');
|
|
294
|
-
}
|
|
295
|
-
catch (error) {
|
|
296
|
-
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
297
|
-
}
|
|
235
|
+
await assert.rejects(() => service.patch(doug[idProp], {
|
|
236
|
+
name: 'id patched doug',
|
|
237
|
+
}, {
|
|
238
|
+
query: { name: 'Tester' },
|
|
239
|
+
}), NotFound);
|
|
298
240
|
});
|
|
299
241
|
test('.patch multiple', async () => {
|
|
300
|
-
|
|
301
|
-
await service.patch(null, {});
|
|
302
|
-
throw new Error('Should never get here');
|
|
303
|
-
}
|
|
304
|
-
catch (error) {
|
|
305
|
-
assert.strictEqual(error.name, 'MethodNotAllowed', 'Removing multiple without option set throws MethodNotAllowed');
|
|
306
|
-
}
|
|
242
|
+
await assert.rejects(() => service.patch(null, {}), MethodNotAllowed);
|
|
307
243
|
const params = {
|
|
308
244
|
query: { created: true },
|
|
309
245
|
};
|
|
@@ -372,7 +308,11 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
372
308
|
});
|
|
373
309
|
test('.patch multi query same', async () => {
|
|
374
310
|
const service = app.service(serviceName);
|
|
375
|
-
|
|
311
|
+
// @ts-expect-error options may not exist
|
|
312
|
+
const multiBefore = service.options?.multi;
|
|
313
|
+
// @ts-expect-error options may not exist
|
|
314
|
+
service.options ??= {};
|
|
315
|
+
// @ts-expect-error options may not exist
|
|
376
316
|
service.options.multi = true;
|
|
377
317
|
const params = {
|
|
378
318
|
query: { age: { $lt: 10 } },
|
|
@@ -395,11 +335,14 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
395
335
|
assert.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
396
336
|
await service.remove(dave[idProp]);
|
|
397
337
|
await service.remove(david[idProp]);
|
|
338
|
+
// @ts-expect-error options may not exist
|
|
398
339
|
service.options.multi = multiBefore;
|
|
399
340
|
});
|
|
400
341
|
test('.patch multi query changed', async () => {
|
|
401
342
|
const service = app.service(serviceName);
|
|
343
|
+
// @ts-expect-error options may not exist
|
|
402
344
|
const multiBefore = service.options.multi;
|
|
345
|
+
// @ts-expect-error options may not exist
|
|
403
346
|
service.options.multi = true;
|
|
404
347
|
const params = {
|
|
405
348
|
query: { age: 10 },
|
|
@@ -422,28 +365,19 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
422
365
|
assert.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
423
366
|
await service.remove(dave[idProp]);
|
|
424
367
|
await service.remove(david[idProp]);
|
|
368
|
+
// @ts-expect-error options may not exist
|
|
425
369
|
service.options.multi = multiBefore;
|
|
426
370
|
});
|
|
427
371
|
test('.patch + NotFound', async () => {
|
|
428
|
-
|
|
372
|
+
await assert.rejects(async () => {
|
|
429
373
|
await service.patch('568225fbfe21222432e836ff', {
|
|
430
374
|
name: 'PatchDoug',
|
|
431
375
|
});
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
catch (error) {
|
|
435
|
-
assert.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
436
|
-
}
|
|
376
|
+
}, NotFound);
|
|
437
377
|
});
|
|
438
378
|
test('.patch + query + NotFound', async () => {
|
|
439
379
|
const dave = await service.create({ name: 'Dave' });
|
|
440
|
-
|
|
441
|
-
await service.patch(dave[idProp], { name: 'PatchedDave' }, { query: { name: 'NotDave' } });
|
|
442
|
-
throw new Error('Should never get here');
|
|
443
|
-
}
|
|
444
|
-
catch (error) {
|
|
445
|
-
assert.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
446
|
-
}
|
|
380
|
+
await assert.rejects(() => service.patch(dave[idProp], { name: 'PatchedDave' }, { query: { name: 'NotDave' } }), NotFound);
|
|
447
381
|
await service.remove(dave[idProp]);
|
|
448
382
|
});
|
|
449
383
|
test('.patch + id + query id', async () => {
|
|
@@ -451,17 +385,11 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
451
385
|
name: 'Alice',
|
|
452
386
|
age: 12,
|
|
453
387
|
});
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
},
|
|
458
|
-
|
|
459
|
-
});
|
|
460
|
-
throw new Error('Should never get here');
|
|
461
|
-
}
|
|
462
|
-
catch (error) {
|
|
463
|
-
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
464
|
-
}
|
|
388
|
+
await assert.rejects(() => service.patch(doug[idProp], {
|
|
389
|
+
age: 33,
|
|
390
|
+
}, {
|
|
391
|
+
query: { [idProp]: alice[idProp] },
|
|
392
|
+
}), NotFound);
|
|
465
393
|
await service.remove(alice[idProp]);
|
|
466
394
|
});
|
|
467
395
|
});
|
|
@@ -502,16 +430,12 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
502
430
|
assert.ok(idProp in data, 'data has id');
|
|
503
431
|
assert.strictEqual(data.name, 'William', 'data.name matches');
|
|
504
432
|
assert.ok(!data.age, 'data.age is falsy');
|
|
433
|
+
const created = await service.get(data[idProp]);
|
|
434
|
+
assert.strictEqual(created.age, 23, 'data.age created');
|
|
505
435
|
await service.remove(data[idProp]);
|
|
506
436
|
});
|
|
507
437
|
test('.create multi', async () => {
|
|
508
|
-
|
|
509
|
-
await service.create([], {});
|
|
510
|
-
throw new Error('Should never get here');
|
|
511
|
-
}
|
|
512
|
-
catch (error) {
|
|
513
|
-
assert.strictEqual(error.name, 'MethodNotAllowed', 'Removing multiple without option set throws MethodNotAllowed');
|
|
514
|
-
}
|
|
438
|
+
await assert.rejects(() => service.create([]), MethodNotAllowed);
|
|
515
439
|
const items = [
|
|
516
440
|
{
|
|
517
441
|
name: 'Gerald',
|
|
@@ -538,6 +462,7 @@ export default (test, app, _errors, serviceName, idProp) => {
|
|
|
538
462
|
beforeAll(() => {
|
|
539
463
|
throwing = Object.assign(Object.create(app.service(serviceName)), {
|
|
540
464
|
get store() {
|
|
465
|
+
// @ts-expect-error just ignore it for now
|
|
541
466
|
return app.service(serviceName).store;
|
|
542
467
|
},
|
|
543
468
|
find() {
|
package/dist/syntax.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { AdapterSyntaxTest } from './declarations.js';
|
|
2
|
-
|
|
2
|
+
import type { Application } from '@feathersjs/feathers';
|
|
3
|
+
type SyntaxTestOptions = {
|
|
4
|
+
app: Application;
|
|
5
|
+
test: AdapterSyntaxTest;
|
|
6
|
+
serviceName: string;
|
|
7
|
+
idProp: string;
|
|
8
|
+
};
|
|
9
|
+
declare const _default: (options: SyntaxTestOptions) => void;
|
|
3
10
|
export default _default;
|
package/dist/syntax.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { describe, beforeEach, afterEach } from 'vitest';
|
|
3
|
-
export default (
|
|
3
|
+
export default (options) => {
|
|
4
|
+
const { test, app, serviceName, idProp } = options;
|
|
4
5
|
describe('Query Syntax', () => {
|
|
5
6
|
let bob;
|
|
6
7
|
let alice;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feathers-adapter-vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Feathers shared database adapter test suite with vitest",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"keywords": [
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
+
"@feathersjs/errors": "^5.0.35",
|
|
45
46
|
"@feathersjs/feathers": "^5.0.35"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
},
|
|
59
60
|
"scripts": {
|
|
60
61
|
"build": "tsc",
|
|
62
|
+
"version": "pnpm build",
|
|
61
63
|
"lint": "eslint",
|
|
62
64
|
"test": "vitest run"
|
|
63
65
|
}
|
package/src/methods.ts
CHANGED
|
@@ -2,6 +2,7 @@ import assert from 'node:assert'
|
|
|
2
2
|
import type { AdapterMethodsTest } from './declarations.js'
|
|
3
3
|
import { describe, beforeEach, afterEach, beforeAll } from 'vitest'
|
|
4
4
|
import type { Application } from '@feathersjs/feathers'
|
|
5
|
+
import { MethodNotAllowed, NotFound } from '@feathersjs/errors'
|
|
5
6
|
|
|
6
7
|
type MethodTestOptions = {
|
|
7
8
|
app: Application
|
|
@@ -61,31 +62,16 @@ export default (options: MethodTestOptions) => {
|
|
|
61
62
|
})
|
|
62
63
|
|
|
63
64
|
test('.get + id + query', async () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
throw new Error('Should never get here')
|
|
69
|
-
} catch (error: any) {
|
|
70
|
-
assert.strictEqual(
|
|
71
|
-
error.name,
|
|
72
|
-
'NotFound',
|
|
73
|
-
'Got a NotFound Feathers error',
|
|
74
|
-
)
|
|
75
|
-
}
|
|
65
|
+
await assert.rejects(
|
|
66
|
+
() => service.get(doug[idProp], { query: { name: 'Tester' } }),
|
|
67
|
+
NotFound,
|
|
68
|
+
)
|
|
76
69
|
})
|
|
77
70
|
|
|
78
71
|
test('.get + NotFound', async () => {
|
|
79
|
-
|
|
72
|
+
await assert.rejects(async () => {
|
|
80
73
|
await service.get('568225fbfe21222432e836ff')
|
|
81
|
-
|
|
82
|
-
} catch (error: any) {
|
|
83
|
-
assert.strictEqual(
|
|
84
|
-
error.name,
|
|
85
|
-
'NotFound',
|
|
86
|
-
'Error is a NotFound Feathers error',
|
|
87
|
-
)
|
|
88
|
-
}
|
|
74
|
+
}, NotFound)
|
|
89
75
|
})
|
|
90
76
|
|
|
91
77
|
test('.get + id + query id', async () => {
|
|
@@ -94,18 +80,13 @@ export default (options: MethodTestOptions) => {
|
|
|
94
80
|
age: 12,
|
|
95
81
|
})
|
|
96
82
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
error.name,
|
|
105
|
-
'NotFound',
|
|
106
|
-
'Got a NotFound Feathers error',
|
|
107
|
-
)
|
|
108
|
-
}
|
|
83
|
+
await assert.rejects(
|
|
84
|
+
() =>
|
|
85
|
+
service.get(doug[idProp], {
|
|
86
|
+
query: { [idProp]: alice[idProp] },
|
|
87
|
+
}),
|
|
88
|
+
NotFound,
|
|
89
|
+
)
|
|
109
90
|
|
|
110
91
|
await service.remove(alice[idProp])
|
|
111
92
|
})
|
|
@@ -142,31 +123,20 @@ export default (options: MethodTestOptions) => {
|
|
|
142
123
|
})
|
|
143
124
|
|
|
144
125
|
test('.remove + id + query', async () => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
)
|
|
156
|
-
}
|
|
126
|
+
await assert.rejects(
|
|
127
|
+
() =>
|
|
128
|
+
service.remove(doug[idProp], {
|
|
129
|
+
query: { name: 'Tester' },
|
|
130
|
+
}),
|
|
131
|
+
NotFound,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
const stillExists = await service.get(doug[idProp])
|
|
135
|
+
assert.ok(stillExists, 'Doug still exists')
|
|
157
136
|
})
|
|
158
137
|
|
|
159
138
|
test('.remove + multi', async () => {
|
|
160
|
-
|
|
161
|
-
await service.remove(null)
|
|
162
|
-
throw new Error('Should never get here')
|
|
163
|
-
} catch (error: any) {
|
|
164
|
-
assert.strictEqual(
|
|
165
|
-
error.name,
|
|
166
|
-
'MethodNotAllowed',
|
|
167
|
-
'Removing multiple without option set throws MethodNotAllowed',
|
|
168
|
-
)
|
|
169
|
-
}
|
|
139
|
+
await assert.rejects(() => service.remove(null), MethodNotAllowed)
|
|
170
140
|
|
|
171
141
|
service.options.multi = ['remove']
|
|
172
142
|
|
|
@@ -266,18 +236,16 @@ export default (options: MethodTestOptions) => {
|
|
|
266
236
|
age: 12,
|
|
267
237
|
})
|
|
268
238
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
)
|
|
280
|
-
}
|
|
239
|
+
await assert.rejects(
|
|
240
|
+
() =>
|
|
241
|
+
service.remove(doug[idProp], {
|
|
242
|
+
query: { [idProp]: alice[idProp] },
|
|
243
|
+
}),
|
|
244
|
+
NotFound,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
const stillExists = await service.get(doug[idProp])
|
|
248
|
+
assert.ok(stillExists, 'Doug still exists')
|
|
281
249
|
|
|
282
250
|
await service.remove(alice[idProp])
|
|
283
251
|
})
|
|
@@ -322,60 +290,49 @@ export default (options: MethodTestOptions) => {
|
|
|
322
290
|
)
|
|
323
291
|
assert.strictEqual(data.name, 'Dougler', 'data.name matches')
|
|
324
292
|
assert.ok(!data.age, 'data.age is falsy')
|
|
293
|
+
|
|
294
|
+
// TODO: service.get(doug[idProp]) should have age set to 10
|
|
325
295
|
})
|
|
326
296
|
|
|
327
297
|
test('.update + id + query', async () => {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
error.name,
|
|
342
|
-
'NotFound',
|
|
343
|
-
'Got a NotFound Feathers error',
|
|
344
|
-
)
|
|
345
|
-
}
|
|
298
|
+
await assert.rejects(
|
|
299
|
+
() =>
|
|
300
|
+
service.update(
|
|
301
|
+
doug[idProp],
|
|
302
|
+
{
|
|
303
|
+
name: 'Dougler',
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
query: { name: 'Tester' },
|
|
307
|
+
},
|
|
308
|
+
),
|
|
309
|
+
NotFound,
|
|
310
|
+
)
|
|
346
311
|
})
|
|
347
312
|
|
|
348
313
|
test('.update + NotFound', async () => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
error.name,
|
|
357
|
-
'NotFound',
|
|
358
|
-
'Error is a NotFound Feathers error',
|
|
359
|
-
)
|
|
360
|
-
}
|
|
314
|
+
await assert.rejects(
|
|
315
|
+
() =>
|
|
316
|
+
service.update('568225fbfe21222432e836ff', {
|
|
317
|
+
name: 'NotFound',
|
|
318
|
+
}),
|
|
319
|
+
NotFound,
|
|
320
|
+
)
|
|
361
321
|
})
|
|
362
322
|
|
|
363
323
|
test('.update + query + NotFound', async () => {
|
|
364
324
|
const dave = await service.create({ name: 'Dave' })
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
'Error is a NotFound Feathers error',
|
|
377
|
-
)
|
|
378
|
-
}
|
|
325
|
+
|
|
326
|
+
await assert.rejects(
|
|
327
|
+
() =>
|
|
328
|
+
service.update(
|
|
329
|
+
dave[idProp],
|
|
330
|
+
{ name: 'UpdatedDave' },
|
|
331
|
+
{ query: { name: 'NotDave' } },
|
|
332
|
+
),
|
|
333
|
+
NotFound,
|
|
334
|
+
)
|
|
335
|
+
|
|
379
336
|
await service.remove(dave[idProp])
|
|
380
337
|
})
|
|
381
338
|
|
|
@@ -385,25 +342,20 @@ export default (options: MethodTestOptions) => {
|
|
|
385
342
|
age: 12,
|
|
386
343
|
})
|
|
387
344
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
error.name,
|
|
403
|
-
'NotFound',
|
|
404
|
-
'Got a NotFound Feathers error',
|
|
405
|
-
)
|
|
406
|
-
}
|
|
345
|
+
await assert.rejects(
|
|
346
|
+
() =>
|
|
347
|
+
service.update(
|
|
348
|
+
doug[idProp],
|
|
349
|
+
{
|
|
350
|
+
name: 'Dougler',
|
|
351
|
+
age: 33,
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
query: { [idProp]: alice[idProp] },
|
|
355
|
+
},
|
|
356
|
+
),
|
|
357
|
+
NotFound,
|
|
358
|
+
)
|
|
407
359
|
|
|
408
360
|
await service.remove(alice[idProp])
|
|
409
361
|
})
|
|
@@ -444,40 +396,28 @@ export default (options: MethodTestOptions) => {
|
|
|
444
396
|
)
|
|
445
397
|
assert.strictEqual(data.name, 'PatchDoug', 'data.name matches')
|
|
446
398
|
assert.ok(!data.age, 'data.age is falsy')
|
|
399
|
+
|
|
400
|
+
// TODO: service.get(doug[idProp]) should have age set to 10
|
|
447
401
|
})
|
|
448
402
|
|
|
449
403
|
test('.patch + id + query', async () => {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
error.name,
|
|
464
|
-
'NotFound',
|
|
465
|
-
'Got a NotFound Feathers error',
|
|
466
|
-
)
|
|
467
|
-
}
|
|
404
|
+
await assert.rejects(
|
|
405
|
+
() =>
|
|
406
|
+
service.patch(
|
|
407
|
+
doug[idProp],
|
|
408
|
+
{
|
|
409
|
+
name: 'id patched doug',
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
query: { name: 'Tester' },
|
|
413
|
+
},
|
|
414
|
+
),
|
|
415
|
+
NotFound,
|
|
416
|
+
)
|
|
468
417
|
})
|
|
469
418
|
|
|
470
419
|
test('.patch multiple', async () => {
|
|
471
|
-
|
|
472
|
-
await service.patch(null, {})
|
|
473
|
-
throw new Error('Should never get here')
|
|
474
|
-
} catch (error: any) {
|
|
475
|
-
assert.strictEqual(
|
|
476
|
-
error.name,
|
|
477
|
-
'MethodNotAllowed',
|
|
478
|
-
'Removing multiple without option set throws MethodNotAllowed',
|
|
479
|
-
)
|
|
480
|
-
}
|
|
420
|
+
await assert.rejects(() => service.patch(null, {}), MethodNotAllowed)
|
|
481
421
|
|
|
482
422
|
const params = {
|
|
483
423
|
query: { created: true },
|
|
@@ -671,36 +611,26 @@ export default (options: MethodTestOptions) => {
|
|
|
671
611
|
})
|
|
672
612
|
|
|
673
613
|
test('.patch + NotFound', async () => {
|
|
674
|
-
|
|
614
|
+
await assert.rejects(async () => {
|
|
675
615
|
await service.patch('568225fbfe21222432e836ff', {
|
|
676
616
|
name: 'PatchDoug',
|
|
677
617
|
})
|
|
678
|
-
|
|
679
|
-
} catch (error: any) {
|
|
680
|
-
assert.strictEqual(
|
|
681
|
-
error.name,
|
|
682
|
-
'NotFound',
|
|
683
|
-
'Error is a NotFound Feathers error',
|
|
684
|
-
)
|
|
685
|
-
}
|
|
618
|
+
}, NotFound)
|
|
686
619
|
})
|
|
687
620
|
|
|
688
621
|
test('.patch + query + NotFound', async () => {
|
|
689
622
|
const dave = await service.create({ name: 'Dave' })
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
'Error is a NotFound Feathers error',
|
|
702
|
-
)
|
|
703
|
-
}
|
|
623
|
+
|
|
624
|
+
await assert.rejects(
|
|
625
|
+
() =>
|
|
626
|
+
service.patch(
|
|
627
|
+
dave[idProp],
|
|
628
|
+
{ name: 'PatchedDave' },
|
|
629
|
+
{ query: { name: 'NotDave' } },
|
|
630
|
+
),
|
|
631
|
+
NotFound,
|
|
632
|
+
)
|
|
633
|
+
|
|
704
634
|
await service.remove(dave[idProp])
|
|
705
635
|
})
|
|
706
636
|
|
|
@@ -710,24 +640,19 @@ export default (options: MethodTestOptions) => {
|
|
|
710
640
|
age: 12,
|
|
711
641
|
})
|
|
712
642
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
error.name,
|
|
727
|
-
'NotFound',
|
|
728
|
-
'Got a NotFound Feathers error',
|
|
729
|
-
)
|
|
730
|
-
}
|
|
643
|
+
await assert.rejects(
|
|
644
|
+
() =>
|
|
645
|
+
service.patch(
|
|
646
|
+
doug[idProp],
|
|
647
|
+
{
|
|
648
|
+
age: 33,
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
query: { [idProp]: alice[idProp] },
|
|
652
|
+
},
|
|
653
|
+
),
|
|
654
|
+
NotFound,
|
|
655
|
+
)
|
|
731
656
|
|
|
732
657
|
await service.remove(alice[idProp])
|
|
733
658
|
})
|
|
@@ -784,20 +709,15 @@ export default (options: MethodTestOptions) => {
|
|
|
784
709
|
assert.strictEqual(data.name, 'William', 'data.name matches')
|
|
785
710
|
assert.ok(!data.age, 'data.age is falsy')
|
|
786
711
|
|
|
712
|
+
const created = await service.get(data[idProp])
|
|
713
|
+
|
|
714
|
+
assert.strictEqual(created.age, 23, 'data.age created')
|
|
715
|
+
|
|
787
716
|
await service.remove(data[idProp])
|
|
788
717
|
})
|
|
789
718
|
|
|
790
719
|
test('.create multi', async () => {
|
|
791
|
-
|
|
792
|
-
await service.create([], {})
|
|
793
|
-
throw new Error('Should never get here')
|
|
794
|
-
} catch (error: any) {
|
|
795
|
-
assert.strictEqual(
|
|
796
|
-
error.name,
|
|
797
|
-
'MethodNotAllowed',
|
|
798
|
-
'Removing multiple without option set throws MethodNotAllowed',
|
|
799
|
-
)
|
|
800
|
-
}
|
|
720
|
+
await assert.rejects(() => service.create([]), MethodNotAllowed)
|
|
801
721
|
|
|
802
722
|
const items = [
|
|
803
723
|
{
|