@opra/testing 0.2.0 → 0.4.0

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.
Files changed (72) hide show
  1. package/cjs/{expect/api-expect-array.js → api-expect/api-expect-collection.js} +48 -46
  2. package/cjs/{expect → api-expect}/api-expect-error.js +3 -4
  3. package/cjs/api-expect/api-expect-object.js +54 -0
  4. package/cjs/{expect → api-expect}/api-expect-operation-result.js +14 -6
  5. package/cjs/{expect → api-expect}/api-expect.js +30 -23
  6. package/cjs/constants.js +4 -0
  7. package/cjs/index.js +3 -22
  8. package/cjs/{expect/jest-extend → jest-extend}/common.extend.js +27 -26
  9. package/cjs/test-client.js +32 -0
  10. package/cjs/{expect/utils → utils}/object-matches.util.js +0 -0
  11. package/esm/api-expect/api-expect-collection.d.ts +19 -0
  12. package/esm/{expect/api-expect-array.js → api-expect/api-expect-collection.js} +46 -44
  13. package/esm/{expect → api-expect}/api-expect-error.d.ts +3 -3
  14. package/esm/{expect → api-expect}/api-expect-error.js +3 -4
  15. package/esm/api-expect/api-expect-object.d.ts +11 -0
  16. package/esm/api-expect/api-expect-object.js +49 -0
  17. package/esm/api-expect/api-expect-operation-result.d.ts +11 -0
  18. package/esm/{expect → api-expect}/api-expect-operation-result.js +14 -6
  19. package/esm/{expect → api-expect}/api-expect.d.ts +8 -7
  20. package/esm/{expect → api-expect}/api-expect.js +30 -23
  21. package/esm/constants.d.ts +1 -0
  22. package/esm/constants.js +1 -0
  23. package/esm/index.d.ts +2 -6
  24. package/esm/index.js +2 -19
  25. package/esm/{expect/jest-extend → jest-extend}/common.extend.d.ts +2 -2
  26. package/esm/{expect/jest-extend → jest-extend}/common.extend.js +26 -26
  27. package/esm/test-client.d.ts +18 -0
  28. package/esm/test-client.js +27 -0
  29. package/esm/{expect/utils → utils}/object-matches.util.d.ts +0 -0
  30. package/esm/{expect/utils → utils}/object-matches.util.js +0 -0
  31. package/package.json +6 -4
  32. package/cjs/api-response.js +0 -22
  33. package/cjs/expect/api-expect-object.js +0 -76
  34. package/cjs/expect/utils/print-errors.util.js +0 -15
  35. package/cjs/testers/base-operation-tester.js +0 -24
  36. package/cjs/testers/base-tester.js +0 -23
  37. package/cjs/testers/entity-create-tester.js +0 -43
  38. package/cjs/testers/entity-delete-many-tester.js +0 -27
  39. package/cjs/testers/entity-delete-tester.js +0 -24
  40. package/cjs/testers/entity-get-tester.js +0 -46
  41. package/cjs/testers/entity-search-tester.js +0 -75
  42. package/cjs/testers/entity-tester.js +0 -72
  43. package/cjs/testers/entity-update-many-tester.js +0 -31
  44. package/cjs/testers/entity-update-tester.js +0 -46
  45. package/esm/api-response.d.ts +0 -12
  46. package/esm/api-response.js +0 -18
  47. package/esm/expect/api-expect-array.d.ts +0 -17
  48. package/esm/expect/api-expect-object.d.ts +0 -12
  49. package/esm/expect/api-expect-object.js +0 -71
  50. package/esm/expect/api-expect-operation-result.d.ts +0 -9
  51. package/esm/expect/utils/print-errors.util.d.ts +0 -1
  52. package/esm/expect/utils/print-errors.util.js +0 -11
  53. package/esm/testers/base-operation-tester.d.ts +0 -8
  54. package/esm/testers/base-operation-tester.js +0 -20
  55. package/esm/testers/base-tester.d.ts +0 -13
  56. package/esm/testers/base-tester.js +0 -19
  57. package/esm/testers/entity-create-tester.d.ts +0 -17
  58. package/esm/testers/entity-create-tester.js +0 -38
  59. package/esm/testers/entity-delete-many-tester.d.ts +0 -14
  60. package/esm/testers/entity-delete-many-tester.js +0 -22
  61. package/esm/testers/entity-delete-tester.d.ts +0 -14
  62. package/esm/testers/entity-delete-tester.js +0 -19
  63. package/esm/testers/entity-get-tester.d.ts +0 -18
  64. package/esm/testers/entity-get-tester.js +0 -41
  65. package/esm/testers/entity-search-tester.d.ts +0 -22
  66. package/esm/testers/entity-search-tester.js +0 -70
  67. package/esm/testers/entity-tester.d.ts +0 -24
  68. package/esm/testers/entity-tester.js +0 -68
  69. package/esm/testers/entity-update-many-tester.d.ts +0 -16
  70. package/esm/testers/entity-update-many-tester.js +0 -26
  71. package/esm/testers/entity-update-tester.d.ts +0 -19
  72. package/esm/testers/entity-update-tester.js +0 -41
@@ -1,71 +0,0 @@
1
- import _ from 'lodash';
2
- export class ApiExpectObject {
3
- response;
4
- constructor(response) {
5
- this.response = response;
6
- }
7
- get body() {
8
- return this.response.body;
9
- }
10
- toMatch(expected) {
11
- try {
12
- const v = _.omitBy(expected, _.isNil);
13
- expect(this.response.body).toMatchObject(v);
14
- }
15
- catch (e) {
16
- Error.captureStackTrace(e, this.toMatch);
17
- throw e;
18
- }
19
- return this;
20
- }
21
- toContainAllKeys(keys) {
22
- try {
23
- expect(this.response.body).toContainAllKeys(keys);
24
- }
25
- catch (e) {
26
- Error.captureStackTrace(e, this.toContainAllKeys);
27
- throw e;
28
- }
29
- return this;
30
- }
31
- toContainKeys(keys) {
32
- try {
33
- expect(this.response.body).toContainKeys(keys);
34
- }
35
- catch (e) {
36
- Error.captureStackTrace(e, this.toContainKeys);
37
- throw e;
38
- }
39
- return this;
40
- }
41
- notToContainKeys(keys) {
42
- try {
43
- expect(this.response.body).not.toContainKeys(keys);
44
- }
45
- catch (e) {
46
- Error.captureStackTrace(e, this.notToContainKeys);
47
- throw e;
48
- }
49
- return this;
50
- }
51
- toHaveProperty(keyPath, value) {
52
- try {
53
- expect(this.response.body).toHaveProperty(keyPath, value);
54
- }
55
- catch (e) {
56
- Error.captureStackTrace(e, this.toContainKeys);
57
- throw e;
58
- }
59
- return this;
60
- }
61
- notToHaveProperty(keyPath, value) {
62
- try {
63
- expect(this.response.body).not.toHaveProperty(keyPath, value);
64
- }
65
- catch (e) {
66
- Error.captureStackTrace(e, this.toContainKeys);
67
- throw e;
68
- }
69
- return this;
70
- }
71
- }
@@ -1,9 +0,0 @@
1
- import type { ApiResponse } from '../api-response';
2
- export declare class ApiExpectOperationResult {
3
- readonly response: ApiResponse;
4
- constructor(response: ApiResponse);
5
- get body(): any;
6
- toBeAffectedExact(expected: number): this;
7
- toBeAffectedMin(expected: number): this;
8
- toBeAffectedMax(expected: number): this;
9
- }
@@ -1 +0,0 @@
1
- export declare function printErrors(errors: any[]): string;
@@ -1,11 +0,0 @@
1
- const colorReset = "\u001B[0m";
2
- const colorFgYellow = "\u001B[33m";
3
- export function printErrors(errors) {
4
- let i = 1;
5
- return errors.map((e) => {
6
- let j = 0;
7
- return ' ' + colorFgYellow + (i++) + '-' + colorReset +
8
- Object.keys(e).map(k => (j++ ? ' ' : ' ') +
9
- k + ': ' + e[k]).join('\n');
10
- }).join('\n');
11
- }
@@ -1,8 +0,0 @@
1
- import { Response } from 'supertest';
2
- import { ApiResponse } from '../api-response.js';
3
- import { BaseTester } from './base-tester.js';
4
- export declare abstract class BaseOperationTester extends BaseTester {
5
- send(): Promise<ApiResponse>;
6
- send(fn: (expect: ApiResponse) => void): Promise<void>;
7
- protected abstract _send(): Promise<Response>;
8
- }
@@ -1,20 +0,0 @@
1
- import { ApiResponse } from '../api-response.js';
2
- import { BaseTester } from './base-tester.js';
3
- export class BaseOperationTester extends BaseTester {
4
- async send(fn) {
5
- const response = await this._send();
6
- const apiResponse = new ApiResponse({
7
- status: response.status,
8
- body: response.body,
9
- headers: response.headers,
10
- rawBody: response.text,
11
- contentType: response.type,
12
- charset: response.charset
13
- });
14
- if (fn) {
15
- fn(apiResponse);
16
- return;
17
- }
18
- return apiResponse;
19
- }
20
- }
@@ -1,13 +0,0 @@
1
- import { Test } from 'supertest';
2
- export interface OpraTesterParams {
3
- app: any;
4
- prefix: string;
5
- headers: Record<string, string>;
6
- }
7
- export declare abstract class BaseTester {
8
- protected readonly _params: OpraTesterParams;
9
- constructor(params: OpraTesterParams);
10
- prefix(value: string): this;
11
- header(name: string, value: string): void;
12
- protected _prepare(test: Test): void;
13
- }
@@ -1,19 +0,0 @@
1
- export class BaseTester {
2
- _params;
3
- constructor(params) {
4
- this._params = params;
5
- }
6
- prefix(value) {
7
- this._params.prefix = value;
8
- return this;
9
- }
10
- header(name, value) {
11
- this._params.headers = this._params.headers || {};
12
- this._params.headers[name] = value;
13
- }
14
- _prepare(test) {
15
- const headers = this._params.headers;
16
- if (headers)
17
- Object.keys(headers).forEach(k => test.set(k, headers[k]));
18
- }
19
- }
@@ -1,17 +0,0 @@
1
- import { Response } from 'supertest';
2
- import { CreateInstanceQueryOptions } from '@opra/schema';
3
- import { BaseOperationTester } from './base-operation-tester.js';
4
- import type { OpraEntityTesterParams } from './entity-tester.js';
5
- export declare type OpraEntityCreateTesterParams = OpraEntityTesterParams & {
6
- data: {};
7
- options: CreateInstanceQueryOptions;
8
- };
9
- export declare class OpraEntityCreateTester extends BaseOperationTester {
10
- protected readonly _params: OpraEntityCreateTesterParams;
11
- constructor(params: OpraEntityCreateTesterParams);
12
- data(data: {}): this;
13
- omit(...fields: (string | string[])[]): this;
14
- pick(...fields: (string | string[])[]): this;
15
- include(...fields: (string | string[])[]): this;
16
- protected _send(): Promise<Response>;
17
- }
@@ -1,38 +0,0 @@
1
- import request from 'supertest';
2
- import { OpraURL } from '@opra/url';
3
- import { BaseOperationTester } from './base-operation-tester.js';
4
- export class OpraEntityCreateTester extends BaseOperationTester {
5
- constructor(params) {
6
- super(params);
7
- }
8
- data(data) {
9
- this._params.data = data;
10
- return this;
11
- }
12
- omit(...fields) {
13
- this._params.options.omit = fields.flat();
14
- return this;
15
- }
16
- pick(...fields) {
17
- this._params.options.pick = fields.flat();
18
- return this;
19
- }
20
- include(...fields) {
21
- this._params.options.include = fields.flat();
22
- return this;
23
- }
24
- async _send() {
25
- const url = new OpraURL(this._params.path);
26
- url.pathPrefix = this._params.prefix;
27
- if (this._params.options.include)
28
- url.searchParams.set('$include', this._params.options.include);
29
- if (this._params.options.pick)
30
- url.searchParams.set('$pick', this._params.options.pick);
31
- if (this._params.options.omit)
32
- url.searchParams.set('$omit', this._params.options.omit);
33
- const req = request(this._params.app);
34
- const test = req.post(url.toString());
35
- this._prepare(test);
36
- return test.send(this._params.data);
37
- }
38
- }
@@ -1,14 +0,0 @@
1
- import { Response } from 'supertest';
2
- import { DeleteCollectionQueryOption } from '@opra/schema';
3
- import { Expression } from '@opra/url';
4
- import { BaseOperationTester } from './base-operation-tester.js';
5
- import type { OpraEntityTesterParams } from './entity-tester.js';
6
- export declare type OpraEntityDeleteManyTesterParams = OpraEntityTesterParams & {
7
- options: DeleteCollectionQueryOption;
8
- };
9
- export declare class OpraEntityDeleteManyTester extends BaseOperationTester {
10
- protected readonly _params: OpraEntityDeleteManyTesterParams;
11
- constructor(params: OpraEntityDeleteManyTesterParams);
12
- filter(value: string | Expression): this;
13
- protected _send(): Promise<Response>;
14
- }
@@ -1,22 +0,0 @@
1
- import request from 'supertest';
2
- import { OpraURL } from '@opra/url';
3
- import { BaseOperationTester } from './base-operation-tester.js';
4
- export class OpraEntityDeleteManyTester extends BaseOperationTester {
5
- constructor(params) {
6
- super(params);
7
- }
8
- filter(value) {
9
- this._params.options.filter = value;
10
- return this;
11
- }
12
- async _send() {
13
- const url = new OpraURL(this._params.path);
14
- url.pathPrefix = this._params.prefix;
15
- if (this._params.options.filter)
16
- url.searchParams.set('$filter', this._params.options.filter);
17
- const req = request(this._params.app);
18
- const test = req.delete(url.toString());
19
- this._prepare(test);
20
- return test.send();
21
- }
22
- }
@@ -1,14 +0,0 @@
1
- import { Response } from 'supertest';
2
- import { CreateInstanceQueryOptions } from '@opra/schema';
3
- import { ResourceKey } from '@opra/url';
4
- import { BaseOperationTester } from './base-operation-tester.js';
5
- import type { OpraEntityTesterParams } from './entity-tester.js';
6
- export declare type OpraEntityDeleteTesterParams = OpraEntityTesterParams & {
7
- keyValue: ResourceKey;
8
- options: CreateInstanceQueryOptions;
9
- };
10
- export declare class OpraEntityDeleteTester extends BaseOperationTester {
11
- protected readonly _params: OpraEntityDeleteTesterParams;
12
- constructor(params: OpraEntityDeleteTesterParams);
13
- protected _send(): Promise<Response>;
14
- }
@@ -1,19 +0,0 @@
1
- import request from 'supertest';
2
- import { OpraURL } from '@opra/url';
3
- import { BaseOperationTester } from './base-operation-tester.js';
4
- export class OpraEntityDeleteTester extends BaseOperationTester {
5
- constructor(params) {
6
- super(params);
7
- if (!params.keyValue)
8
- throw new Error(`You must provide "keyValue"`);
9
- }
10
- async _send() {
11
- const url = new OpraURL(this._params.path);
12
- url.pathPrefix = this._params.prefix;
13
- url.path.get(url.path.size - 1).key = this._params.keyValue;
14
- const req = request(this._params.app);
15
- const test = req.delete(url.toString());
16
- this._prepare(test);
17
- return test.send();
18
- }
19
- }
@@ -1,18 +0,0 @@
1
- import { Response } from 'supertest';
2
- import { GetInstanceQueryOptions } from '@opra/schema';
3
- import { ResourceKey } from '@opra/url';
4
- import { BaseOperationTester } from './base-operation-tester.js';
5
- import type { OpraEntityTesterParams } from './entity-tester';
6
- export declare type OpraEntityGetTesterParams = OpraEntityTesterParams & {
7
- keyValue: ResourceKey;
8
- options: GetInstanceQueryOptions;
9
- };
10
- export declare class OpraEntityGetTester extends BaseOperationTester {
11
- protected readonly _params: OpraEntityGetTesterParams;
12
- constructor(params: OpraEntityGetTesterParams);
13
- keyValue(value: ResourceKey): this;
14
- omit(...fields: (string | string[])[]): this;
15
- pick(...fields: (string | string[])[]): this;
16
- include(...fields: (string | string[])[]): this;
17
- protected _send(): Promise<Response>;
18
- }
@@ -1,41 +0,0 @@
1
- import request from 'supertest';
2
- import { OpraURL } from '@opra/url';
3
- import { BaseOperationTester } from './base-operation-tester.js';
4
- export class OpraEntityGetTester extends BaseOperationTester {
5
- constructor(params) {
6
- super(params);
7
- if (!params.keyValue)
8
- throw new Error(`You must provide "keyValue"`);
9
- }
10
- keyValue(value) {
11
- this._params.keyValue = value;
12
- return this;
13
- }
14
- omit(...fields) {
15
- this._params.options.omit = fields.flat();
16
- return this;
17
- }
18
- pick(...fields) {
19
- this._params.options.pick = fields.flat();
20
- return this;
21
- }
22
- include(...fields) {
23
- this._params.options.include = fields.flat();
24
- return this;
25
- }
26
- async _send() {
27
- const url = new OpraURL(this._params.path);
28
- url.pathPrefix = this._params.prefix;
29
- url.path.get(url.path.size - 1).key = this._params.keyValue;
30
- if (this._params.options.include)
31
- url.searchParams.set('$include', this._params.options.include);
32
- if (this._params.options.pick)
33
- url.searchParams.set('$pick', this._params.options.pick);
34
- if (this._params.options.omit)
35
- url.searchParams.set('$omit', this._params.options.omit);
36
- const req = request(this._params.app);
37
- const test = req.get(url.toString());
38
- this._prepare(test);
39
- return test.send();
40
- }
41
- }
@@ -1,22 +0,0 @@
1
- import { Response } from 'supertest';
2
- import { SearchCollectionQueryOptions } from '@opra/schema';
3
- import { Expression } from '@opra/url';
4
- import { BaseOperationTester } from './base-operation-tester.js';
5
- import type { OpraEntityTesterParams } from './entity-tester';
6
- export declare type OpraEntitySearchTesterParams = OpraEntityTesterParams & {
7
- options: SearchCollectionQueryOptions;
8
- };
9
- export declare class OpraEntitySearchTester extends BaseOperationTester {
10
- protected readonly _params: OpraEntitySearchTesterParams;
11
- constructor(params: OpraEntitySearchTesterParams);
12
- limit(value: number): this;
13
- skip(value: number): this;
14
- count(value?: boolean): this;
15
- distinct(value: boolean): this;
16
- sort(...fields: (string | string[])[]): this;
17
- filter(value: string | Expression): this;
18
- omit(...fields: (string | string[])[]): this;
19
- pick(...fields: (string | string[])[]): this;
20
- include(...fields: (string | string[])[]): this;
21
- protected _send(): Promise<Response>;
22
- }
@@ -1,70 +0,0 @@
1
- import request from 'supertest';
2
- import { OpraURL } from '@opra/url';
3
- import { BaseOperationTester } from './base-operation-tester.js';
4
- export class OpraEntitySearchTester extends BaseOperationTester {
5
- constructor(params) {
6
- super(params);
7
- }
8
- limit(value) {
9
- this._params.options.limit = value;
10
- return this;
11
- }
12
- skip(value) {
13
- this._params.options.skip = value;
14
- return this;
15
- }
16
- count(value = true) {
17
- this._params.options.count = value;
18
- return this;
19
- }
20
- distinct(value) {
21
- this._params.options.distinct = value;
22
- return this;
23
- }
24
- sort(...fields) {
25
- this._params.options.sort = fields.flat();
26
- return this;
27
- }
28
- filter(value) {
29
- this._params.options.filter = value;
30
- return this;
31
- }
32
- omit(...fields) {
33
- this._params.options.omit = fields.flat();
34
- return this;
35
- }
36
- pick(...fields) {
37
- this._params.options.pick = fields.flat();
38
- return this;
39
- }
40
- include(...fields) {
41
- this._params.options.include = fields.flat();
42
- return this;
43
- }
44
- async _send() {
45
- const url = new OpraURL(this._params.path);
46
- url.pathPrefix = this._params.prefix;
47
- if (this._params.options.include)
48
- url.searchParams.set('$include', this._params.options.include);
49
- if (this._params.options.pick)
50
- url.searchParams.set('$pick', this._params.options.pick);
51
- if (this._params.options.omit)
52
- url.searchParams.set('$omit', this._params.options.omit);
53
- if (this._params.options.sort)
54
- url.searchParams.set('$sort', this._params.options.sort);
55
- if (this._params.options.filter)
56
- url.searchParams.set('$filter', this._params.options.filter);
57
- if (this._params.options.limit != null)
58
- url.searchParams.set('$limit', this._params.options.limit);
59
- if (this._params.options.skip != null)
60
- url.searchParams.set('$skip', this._params.options.skip);
61
- if (this._params.options.count != null)
62
- url.searchParams.set('$count', this._params.options.count);
63
- if (this._params.options.distinct != null)
64
- url.searchParams.set('$distinct', this._params.options.distinct);
65
- const req = request(this._params.app);
66
- const test = req.get(url.toString());
67
- this._prepare(test);
68
- return test.send();
69
- }
70
- }
@@ -1,24 +0,0 @@
1
- import { CreateInstanceQueryOptions, DeleteCollectionQueryOption, DeleteInstanceQueryOptions, GetInstanceQueryOptions, UpdateCollectionQueryOptions, UpdateInstanceQueryOptions } from '@opra/schema';
2
- import { ResourceKey } from '@opra/url';
3
- import { BaseTester, OpraTesterParams } from './base-tester.js';
4
- import { OpraEntityCreateTester } from './entity-create-tester.js';
5
- import { OpraEntityDeleteManyTester } from './entity-delete-many-tester.js';
6
- import { OpraEntityDeleteTester } from './entity-delete-tester.js';
7
- import { OpraEntityGetTester } from './entity-get-tester.js';
8
- import { OpraEntitySearchTester } from './entity-search-tester.js';
9
- import { OpraEntityUpdateManyTester } from './entity-update-many-tester.js';
10
- import { OpraEntityUpdateTester } from './entity-update-tester.js';
11
- export declare type OpraEntityTesterParams = OpraTesterParams & {
12
- path: string;
13
- };
14
- export declare class OpraEntityTester extends BaseTester {
15
- protected readonly _params: OpraEntityTesterParams;
16
- constructor(params: OpraEntityTesterParams);
17
- create(data: {}, options?: CreateInstanceQueryOptions): OpraEntityCreateTester;
18
- get(keyValue: ResourceKey, options?: GetInstanceQueryOptions): OpraEntityGetTester;
19
- search(options?: GetInstanceQueryOptions): OpraEntitySearchTester;
20
- update(keyValue: ResourceKey, data: {}, options?: UpdateInstanceQueryOptions): OpraEntityUpdateTester;
21
- updateMany(data: {}, options?: UpdateCollectionQueryOptions): OpraEntityUpdateManyTester;
22
- delete(keyValue: ResourceKey, options?: DeleteInstanceQueryOptions): OpraEntityDeleteTester;
23
- deleteMany(options?: DeleteCollectionQueryOption): OpraEntityDeleteManyTester;
24
- }
@@ -1,68 +0,0 @@
1
- import { BaseTester } from './base-tester.js';
2
- import { OpraEntityCreateTester } from './entity-create-tester.js';
3
- import { OpraEntityDeleteManyTester } from './entity-delete-many-tester.js';
4
- import { OpraEntityDeleteTester } from './entity-delete-tester.js';
5
- import { OpraEntityGetTester } from './entity-get-tester.js';
6
- import { OpraEntitySearchTester } from './entity-search-tester.js';
7
- import { OpraEntityUpdateManyTester } from './entity-update-many-tester.js';
8
- import { OpraEntityUpdateTester } from './entity-update-tester.js';
9
- export class OpraEntityTester extends BaseTester {
10
- constructor(params) {
11
- super(params);
12
- }
13
- create(data, options = {}) {
14
- return new OpraEntityCreateTester({
15
- ...this._params,
16
- headers: { ...this._params.headers },
17
- data,
18
- options
19
- });
20
- }
21
- get(keyValue, options = {}) {
22
- return new OpraEntityGetTester({
23
- ...this._params,
24
- headers: { ...this._params.headers },
25
- keyValue,
26
- options
27
- });
28
- }
29
- search(options = {}) {
30
- return new OpraEntitySearchTester({
31
- ...this._params,
32
- headers: { ...this._params.headers },
33
- options
34
- });
35
- }
36
- update(keyValue, data, options = {}) {
37
- return new OpraEntityUpdateTester({
38
- ...this._params,
39
- keyValue,
40
- headers: { ...this._params.headers },
41
- data,
42
- options
43
- });
44
- }
45
- updateMany(data, options = {}) {
46
- return new OpraEntityUpdateManyTester({
47
- ...this._params,
48
- headers: { ...this._params.headers },
49
- data,
50
- options
51
- });
52
- }
53
- delete(keyValue, options = {}) {
54
- return new OpraEntityDeleteTester({
55
- ...this._params,
56
- keyValue,
57
- headers: { ...this._params.headers },
58
- options
59
- });
60
- }
61
- deleteMany(options = {}) {
62
- return new OpraEntityDeleteManyTester({
63
- ...this._params,
64
- headers: { ...this._params.headers },
65
- options
66
- });
67
- }
68
- }
@@ -1,16 +0,0 @@
1
- import { Response } from 'supertest';
2
- import { UpdateCollectionQueryOptions } from '@opra/schema';
3
- import { Expression } from '@opra/url';
4
- import { BaseOperationTester } from './base-operation-tester.js';
5
- import type { OpraEntityTesterParams } from './entity-tester.js';
6
- export declare type OpraEntityUpdateManyTesterParams = OpraEntityTesterParams & {
7
- data: {};
8
- options: UpdateCollectionQueryOptions;
9
- };
10
- export declare class OpraEntityUpdateManyTester extends BaseOperationTester {
11
- protected readonly _params: OpraEntityUpdateManyTesterParams;
12
- constructor(params: OpraEntityUpdateManyTesterParams);
13
- data(data: {}): this;
14
- filter(value: string | Expression): this;
15
- protected _send(): Promise<Response>;
16
- }
@@ -1,26 +0,0 @@
1
- import request from 'supertest';
2
- import { OpraURL } from '@opra/url';
3
- import { BaseOperationTester } from './base-operation-tester.js';
4
- export class OpraEntityUpdateManyTester extends BaseOperationTester {
5
- constructor(params) {
6
- super(params);
7
- }
8
- data(data) {
9
- this._params.data = data;
10
- return this;
11
- }
12
- filter(value) {
13
- this._params.options.filter = value;
14
- return this;
15
- }
16
- async _send() {
17
- const url = new OpraURL(this._params.path);
18
- url.pathPrefix = this._params.prefix;
19
- if (this._params.options.filter)
20
- url.searchParams.set('$filter', this._params.options.filter);
21
- const req = request(this._params.app);
22
- const test = req.patch(url.toString());
23
- this._prepare(test);
24
- return test.send(this._params.data);
25
- }
26
- }
@@ -1,19 +0,0 @@
1
- import { Response } from 'supertest';
2
- import { UpdateInstanceQueryOptions } from '@opra/schema';
3
- import { ResourceKey } from '@opra/url';
4
- import { BaseOperationTester } from './base-operation-tester.js';
5
- import type { OpraEntityTesterParams } from './entity-tester.js';
6
- export declare type OpraEntityUpdateTesterParams = OpraEntityTesterParams & {
7
- keyValue: ResourceKey;
8
- data: {};
9
- options: UpdateInstanceQueryOptions;
10
- };
11
- export declare class OpraEntityUpdateTester extends BaseOperationTester {
12
- protected readonly _params: OpraEntityUpdateTesterParams;
13
- constructor(params: OpraEntityUpdateTesterParams);
14
- data(data: {}): this;
15
- omit(...fields: (string | string[])[]): this;
16
- pick(...fields: (string | string[])[]): this;
17
- include(...fields: (string | string[])[]): this;
18
- protected _send(): Promise<Response>;
19
- }
@@ -1,41 +0,0 @@
1
- import request from 'supertest';
2
- import { OpraURL } from '@opra/url';
3
- import { BaseOperationTester } from './base-operation-tester.js';
4
- export class OpraEntityUpdateTester extends BaseOperationTester {
5
- constructor(params) {
6
- super(params);
7
- if (!params.keyValue)
8
- throw new Error(`You must provide "keyValue"`);
9
- }
10
- data(data) {
11
- this._params.data = data;
12
- return this;
13
- }
14
- omit(...fields) {
15
- this._params.options.omit = fields.flat();
16
- return this;
17
- }
18
- pick(...fields) {
19
- this._params.options.pick = fields.flat();
20
- return this;
21
- }
22
- include(...fields) {
23
- this._params.options.include = fields.flat();
24
- return this;
25
- }
26
- async _send() {
27
- const url = new OpraURL(this._params.path);
28
- url.pathPrefix = this._params.prefix;
29
- url.path.get(url.path.size - 1).key = this._params.keyValue;
30
- if (this._params.options.include)
31
- url.searchParams.set('$include', this._params.options.include);
32
- if (this._params.options.pick)
33
- url.searchParams.set('$pick', this._params.options.pick);
34
- if (this._params.options.omit)
35
- url.searchParams.set('$omit', this._params.options.omit);
36
- const req = request(this._params.app);
37
- const test = req.patch(url.toString());
38
- this._prepare(test);
39
- return test.send(this._params.data);
40
- }
41
- }