feathers-adapter-vitest 0.0.14 → 0.0.16

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.
@@ -0,0 +1,11 @@
1
+ import type { Test } from './declarations.js';
2
+ import type { Application } from '@feathersjs/feathers';
3
+ type BasicTestOptions = {
4
+ app: Application;
5
+ test: Test;
6
+ serviceName: string;
7
+ idProp: string;
8
+ };
9
+ export type AdapterTestNameBasic = '.id' | '.options' | '.events' | '._get' | '._find' | '._create' | '._update' | '._patch' | '._remove';
10
+ declare const _default: (options: BasicTestOptions) => void;
11
+ export default _default;
@@ -0,0 +1,46 @@
1
+ import { describe, beforeEach, expect } from 'vitest';
2
+ export default (options) => {
3
+ const { test, app, serviceName, idProp } = options;
4
+ describe('Basic', () => {
5
+ let service;
6
+ beforeEach(() => {
7
+ service = app.service(serviceName);
8
+ });
9
+ const config = {
10
+ '.id': () => {
11
+ expect(service.id, 'id property is set to expected name').toBe(idProp);
12
+ },
13
+ '.options': () => {
14
+ expect(service, 'service.options is defined').toHaveProperty('options');
15
+ expect(service.options, 'Options are available in service.options').toBeTypeOf('object');
16
+ },
17
+ '.events': () => {
18
+ expect(service, 'service has events').toHaveProperty('events');
19
+ expect(service.events, 'service.events is an array').toBeInstanceOf(Array);
20
+ expect(service.events.includes('testing'), 'service.events includes "testing"').toBe(true);
21
+ },
22
+ '._get': () => {
23
+ expect(typeof service._get).toBe('function');
24
+ },
25
+ '._find': () => {
26
+ expect(typeof service._find).toBe('function');
27
+ },
28
+ '._create': () => {
29
+ expect(typeof service._create).toBe('function');
30
+ },
31
+ '._update': () => {
32
+ expect(typeof service._update).toBe('function');
33
+ },
34
+ '._patch': () => {
35
+ expect(typeof service._patch).toBe('function');
36
+ },
37
+ '._remove': () => {
38
+ expect(typeof service._remove).toBe('function');
39
+ },
40
+ };
41
+ for (const testName in config) {
42
+ test(testName, async () => config[testName]());
43
+ }
44
+ });
45
+ };
46
+ //# sourceMappingURL=basic.js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,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAC9C,CAAC;YACD,QAAQ,EAAE,GAAG,EAAE;gBACb,MAAM,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAC/C,CAAC;YACD,UAAU,EAAE,GAAG,EAAE;gBACf,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YACjD,CAAC;YACD,UAAU,EAAE,GAAG,EAAE;gBACf,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YACjD,CAAC;YACD,SAAS,EAAE,GAAG,EAAE;gBACd,MAAM,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAChD,CAAC;YACD,UAAU,EAAE,GAAG,EAAE;gBACf,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YACjD,CAAC;SACF,CAAA;QAED,KAAK,MAAM,QAAQ,IAAI,MAAM,EAAE,CAAC;YAC9B,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAE,MAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACzD,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export type Test = (name: string, runner: any) => void;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=declarations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declarations.js","sourceRoot":"","sources":["../../src/declarations.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { Application } from '@feathersjs/feathers';
2
+ import type { AdapterTestNameBasic } from './basic.js';
3
+ import type { AdapterTestNameMethods } from './methods.js';
4
+ import type { AdapterTestNameSyntax } from './syntax.js';
5
+ export type TestSuiteOptions = {
6
+ app: Application;
7
+ serviceName: string;
8
+ /**
9
+ * @default 'id'
10
+ */
11
+ idProp?: string;
12
+ };
13
+ export type AdapterTestName = AdapterTestNameBasic | AdapterTestNameMethods | AdapterTestNameSyntax;
14
+ export type AdapterTestMap = Record<AdapterTestName, boolean>;
15
+ export type DefineTestSuiteOptions = {
16
+ blacklist?: AdapterTestName[];
17
+ only?: AdapterTestName[];
18
+ };
19
+ export declare const defineTestSuite: (defineOptions?: DefineTestSuiteOptions) => (options: TestSuiteOptions) => void;
20
+ export { withOptions } from './utils.js';
21
+ export * from './declarations.js';
@@ -0,0 +1,51 @@
1
+ import basicTests from './basic.js';
2
+ import methodTests from './methods.js';
3
+ import syntaxTests from './syntax.js';
4
+ import { describe, it, beforeAll, assert } from 'vitest';
5
+ export const defineTestSuite = (defineOptions) => {
6
+ return (options) => {
7
+ const { app, serviceName, idProp = 'id' } = options;
8
+ const test = (name, runner) => {
9
+ let skip = false;
10
+ if (defineOptions?.blacklist?.includes(name)) {
11
+ skip = true;
12
+ }
13
+ if (defineOptions?.only?.length &&
14
+ !defineOptions.only.includes(name)) {
15
+ skip = true;
16
+ }
17
+ const maybeSkip = skip ? it.skip : it;
18
+ maybeSkip(name, runner);
19
+ };
20
+ describe(`app.service('${serviceName}') with options.id: '${idProp}'`, () => {
21
+ beforeAll(async () => {
22
+ const service = app.service(serviceName);
23
+ let items = await service.find({ paginate: false });
24
+ assert.ok(Array.isArray(items), 'find with paginate:false did not return an array. Before you start to test the adapter make sure simple find works.');
25
+ await Promise.all(items.map((item) => service.remove(item[idProp])));
26
+ // test create
27
+ const doug = await service.create({
28
+ name: 'Doug',
29
+ age: 32,
30
+ });
31
+ assert.ok(doug[idProp] !== null, `simple 'create' failed (no ${idProp}). Before you start to test the adapter make sure simple create works.`);
32
+ assert.strictEqual(doug.name, 'Doug', "simple 'create' failed (no name). Before you start to test the adapter make sure simple create works.");
33
+ assert.strictEqual(doug.age, 32, "simple 'create' failed (no age). Before you start to test the adapter make sure simple create works.");
34
+ // test delete
35
+ items = await service.find({ paginate: false });
36
+ assert.ok(Array.isArray(items), 'find with paginate:false did not return an array. Before you start to test the adapter make sure simple find works.');
37
+ assert.strictEqual(items.length, 1, 'find should return an item. Before you start to test the adapter make sure simple find works.');
38
+ assert.ok(idProp in items[0], `'find' should return an item with ${idProp}. Before you start to test the adapter make sure simple find works.`);
39
+ await Promise.all(items.map((item) => service.remove(item[idProp])));
40
+ const itemsAfterRemove = await service.find({ paginate: false });
41
+ assert.ok(itemsAfterRemove.length === 0, "'remove' does not work. Before you start to test the adapter make sure simple remove works.");
42
+ });
43
+ basicTests({ test, app, serviceName, idProp });
44
+ methodTests({ test, app, serviceName, idProp });
45
+ syntaxTests({ test, app, serviceName, idProp });
46
+ });
47
+ };
48
+ };
49
+ export { withOptions } from './utils.js';
50
+ export * from './declarations.js';
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,YAAY,CAAA;AAEnC,OAAO,WAAW,MAAM,cAAc,CAAA;AAEtC,OAAO,WAAW,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAuBxD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,aAAsC,EAAE,EAAE;IACxE,OAAO,CAAC,OAAyB,EAAE,EAAE;QACnC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;QAEnD,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,MAAW,EAAE,EAAE;YACzC,IAAI,IAAI,GAAG,KAAK,CAAA;YAChB,IAAI,aAAa,EAAE,SAAS,EAAE,QAAQ,CAAC,IAAuB,CAAC,EAAE,CAA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,0 +1,20 @@
1
+ import type { Test } from './declarations.js';
2
+ import type { Application } from '@feathersjs/feathers';
3
+ type MethodTestOptions = {
4
+ app: Application;
5
+ test: Test;
6
+ serviceName: string;
7
+ idProp: string;
8
+ };
9
+ type MethodTests = {
10
+ find: '.find';
11
+ get: '.get' | '.get + $select' | '.get + id + query' | '.get + id + query id' | '.get + NotFound (string)' | '.get + NotFound (integer)';
12
+ remove: '.remove' | '.remove + $select' | '.remove + id + query' | '.remove + id + query id' | '.remove + NotFound (string)' | '.remove + NotFound (integer)' | '.remove + multi' | '.remove + multi no pagination';
13
+ update: '.update' | '.update + $select' | '.update + id + query' | '.update + id + query id' | '.update + NotFound (string)' | '.update + NotFound (integer)' | '.update + query + NotFound';
14
+ patch: '.patch' | '.patch + $select' | '.patch + $select unchanged' | '.patch + id + query' | '.patch + id + query id' | '.patch multiple' | '.patch multiple no pagination' | '.patch multi query same' | '.patch multi query changed' | '.patch + NotFound (string)' | '.patch + NotFound (integer)';
15
+ create: '.create' | '.create + $select' | '.create multi' | '.create ignores query';
16
+ internal: 'internal .find' | 'internal .get' | 'internal .create' | 'internal .update' | 'internal .patch' | 'internal .remove';
17
+ };
18
+ export type AdapterTestNameMethods = MethodTests[keyof MethodTests];
19
+ declare const _default: (options: MethodTestOptions) => void;
20
+ export default _default;