@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/testing",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Opra testing package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,11 +25,13 @@
25
25
  "clean:cover": "rimraf ../../coverage/testing"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/schema": "^0.2.0",
29
- "@opra/url": "^0.2.0",
28
+ "@opra/schema": "^0.4.0",
29
+ "@opra/url": "^0.4.0",
30
+ "@opra/client": "^0.4.0",
31
+ "ansi-colors": "^4.1.3",
30
32
  "lodash": "^4.17.21",
31
33
  "rule-judgment": "^1.1.5",
32
- "supertest": "^6.2.4"
34
+ "supertest": "^6.3.0"
33
35
  },
34
36
  "devDependencies": {
35
37
  "@types/supertest": "^2.0.12"
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiResponse = void 0;
4
- const api_expect_js_1 = require("./expect/api-expect.js");
5
- class ApiResponse {
6
- status;
7
- body;
8
- rawBody;
9
- headers;
10
- contentType;
11
- charset;
12
- expect;
13
- constructor(args) {
14
- Object.assign(this, args);
15
- this.expect = new api_expect_js_1.ApiExpect(this);
16
- }
17
- get(header) {
18
- const key = Object.keys(this.headers).find(k => k.toLowerCase() === header.toLowerCase());
19
- return (key && this.headers[key]) || '';
20
- }
21
- }
22
- exports.ApiResponse = ApiResponse;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExpectObject = void 0;
4
- const tslib_1 = require("tslib");
5
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
- class ApiExpectObject {
7
- response;
8
- constructor(response) {
9
- this.response = response;
10
- }
11
- get body() {
12
- return this.response.body;
13
- }
14
- toMatch(expected) {
15
- try {
16
- const v = lodash_1.default.omitBy(expected, lodash_1.default.isNil);
17
- expect(this.response.body).toMatchObject(v);
18
- }
19
- catch (e) {
20
- Error.captureStackTrace(e, this.toMatch);
21
- throw e;
22
- }
23
- return this;
24
- }
25
- toContainAllKeys(keys) {
26
- try {
27
- expect(this.response.body).toContainAllKeys(keys);
28
- }
29
- catch (e) {
30
- Error.captureStackTrace(e, this.toContainAllKeys);
31
- throw e;
32
- }
33
- return this;
34
- }
35
- toContainKeys(keys) {
36
- try {
37
- expect(this.response.body).toContainKeys(keys);
38
- }
39
- catch (e) {
40
- Error.captureStackTrace(e, this.toContainKeys);
41
- throw e;
42
- }
43
- return this;
44
- }
45
- notToContainKeys(keys) {
46
- try {
47
- expect(this.response.body).not.toContainKeys(keys);
48
- }
49
- catch (e) {
50
- Error.captureStackTrace(e, this.notToContainKeys);
51
- throw e;
52
- }
53
- return this;
54
- }
55
- toHaveProperty(keyPath, value) {
56
- try {
57
- expect(this.response.body).toHaveProperty(keyPath, value);
58
- }
59
- catch (e) {
60
- Error.captureStackTrace(e, this.toContainKeys);
61
- throw e;
62
- }
63
- return this;
64
- }
65
- notToHaveProperty(keyPath, value) {
66
- try {
67
- expect(this.response.body).not.toHaveProperty(keyPath, value);
68
- }
69
- catch (e) {
70
- Error.captureStackTrace(e, this.toContainKeys);
71
- throw e;
72
- }
73
- return this;
74
- }
75
- }
76
- exports.ApiExpectObject = ApiExpectObject;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printErrors = void 0;
4
- const colorReset = "\u001B[0m";
5
- const colorFgYellow = "\u001B[33m";
6
- function printErrors(errors) {
7
- let i = 1;
8
- return errors.map((e) => {
9
- let j = 0;
10
- return ' ' + colorFgYellow + (i++) + '-' + colorReset +
11
- Object.keys(e).map(k => (j++ ? ' ' : ' ') +
12
- k + ': ' + e[k]).join('\n');
13
- }).join('\n');
14
- }
15
- exports.printErrors = printErrors;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseOperationTester = void 0;
4
- const api_response_js_1 = require("../api-response.js");
5
- const base_tester_js_1 = require("./base-tester.js");
6
- class BaseOperationTester extends base_tester_js_1.BaseTester {
7
- async send(fn) {
8
- const response = await this._send();
9
- const apiResponse = new api_response_js_1.ApiResponse({
10
- status: response.status,
11
- body: response.body,
12
- headers: response.headers,
13
- rawBody: response.text,
14
- contentType: response.type,
15
- charset: response.charset
16
- });
17
- if (fn) {
18
- fn(apiResponse);
19
- return;
20
- }
21
- return apiResponse;
22
- }
23
- }
24
- exports.BaseOperationTester = BaseOperationTester;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseTester = void 0;
4
- class BaseTester {
5
- _params;
6
- constructor(params) {
7
- this._params = params;
8
- }
9
- prefix(value) {
10
- this._params.prefix = value;
11
- return this;
12
- }
13
- header(name, value) {
14
- this._params.headers = this._params.headers || {};
15
- this._params.headers[name] = value;
16
- }
17
- _prepare(test) {
18
- const headers = this._params.headers;
19
- if (headers)
20
- Object.keys(headers).forEach(k => test.set(k, headers[k]));
21
- }
22
- }
23
- exports.BaseTester = BaseTester;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraEntityCreateTester = void 0;
4
- const tslib_1 = require("tslib");
5
- const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
- const url_1 = require("@opra/url");
7
- const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
- class OpraEntityCreateTester extends base_operation_tester_js_1.BaseOperationTester {
9
- constructor(params) {
10
- super(params);
11
- }
12
- data(data) {
13
- this._params.data = data;
14
- return this;
15
- }
16
- omit(...fields) {
17
- this._params.options.omit = fields.flat();
18
- return this;
19
- }
20
- pick(...fields) {
21
- this._params.options.pick = fields.flat();
22
- return this;
23
- }
24
- include(...fields) {
25
- this._params.options.include = fields.flat();
26
- return this;
27
- }
28
- async _send() {
29
- const url = new url_1.OpraURL(this._params.path);
30
- url.pathPrefix = this._params.prefix;
31
- if (this._params.options.include)
32
- url.searchParams.set('$include', this._params.options.include);
33
- if (this._params.options.pick)
34
- url.searchParams.set('$pick', this._params.options.pick);
35
- if (this._params.options.omit)
36
- url.searchParams.set('$omit', this._params.options.omit);
37
- const req = (0, supertest_1.default)(this._params.app);
38
- const test = req.post(url.toString());
39
- this._prepare(test);
40
- return test.send(this._params.data);
41
- }
42
- }
43
- exports.OpraEntityCreateTester = OpraEntityCreateTester;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraEntityDeleteManyTester = void 0;
4
- const tslib_1 = require("tslib");
5
- const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
- const url_1 = require("@opra/url");
7
- const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
- class OpraEntityDeleteManyTester extends base_operation_tester_js_1.BaseOperationTester {
9
- constructor(params) {
10
- super(params);
11
- }
12
- filter(value) {
13
- this._params.options.filter = value;
14
- return this;
15
- }
16
- async _send() {
17
- const url = new url_1.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 = (0, supertest_1.default)(this._params.app);
22
- const test = req.delete(url.toString());
23
- this._prepare(test);
24
- return test.send();
25
- }
26
- }
27
- exports.OpraEntityDeleteManyTester = OpraEntityDeleteManyTester;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraEntityDeleteTester = void 0;
4
- const tslib_1 = require("tslib");
5
- const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
- const url_1 = require("@opra/url");
7
- const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
- class OpraEntityDeleteTester extends base_operation_tester_js_1.BaseOperationTester {
9
- constructor(params) {
10
- super(params);
11
- if (!params.keyValue)
12
- throw new Error(`You must provide "keyValue"`);
13
- }
14
- async _send() {
15
- const url = new url_1.OpraURL(this._params.path);
16
- url.pathPrefix = this._params.prefix;
17
- url.path.get(url.path.size - 1).key = this._params.keyValue;
18
- const req = (0, supertest_1.default)(this._params.app);
19
- const test = req.delete(url.toString());
20
- this._prepare(test);
21
- return test.send();
22
- }
23
- }
24
- exports.OpraEntityDeleteTester = OpraEntityDeleteTester;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraEntityGetTester = void 0;
4
- const tslib_1 = require("tslib");
5
- const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
- const url_1 = require("@opra/url");
7
- const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
- class OpraEntityGetTester extends base_operation_tester_js_1.BaseOperationTester {
9
- constructor(params) {
10
- super(params);
11
- if (!params.keyValue)
12
- throw new Error(`You must provide "keyValue"`);
13
- }
14
- keyValue(value) {
15
- this._params.keyValue = value;
16
- return this;
17
- }
18
- omit(...fields) {
19
- this._params.options.omit = fields.flat();
20
- return this;
21
- }
22
- pick(...fields) {
23
- this._params.options.pick = fields.flat();
24
- return this;
25
- }
26
- include(...fields) {
27
- this._params.options.include = fields.flat();
28
- return this;
29
- }
30
- async _send() {
31
- const url = new url_1.OpraURL(this._params.path);
32
- url.pathPrefix = this._params.prefix;
33
- url.path.get(url.path.size - 1).key = this._params.keyValue;
34
- if (this._params.options.include)
35
- url.searchParams.set('$include', this._params.options.include);
36
- if (this._params.options.pick)
37
- url.searchParams.set('$pick', this._params.options.pick);
38
- if (this._params.options.omit)
39
- url.searchParams.set('$omit', this._params.options.omit);
40
- const req = (0, supertest_1.default)(this._params.app);
41
- const test = req.get(url.toString());
42
- this._prepare(test);
43
- return test.send();
44
- }
45
- }
46
- exports.OpraEntityGetTester = OpraEntityGetTester;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraEntitySearchTester = void 0;
4
- const tslib_1 = require("tslib");
5
- const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
- const url_1 = require("@opra/url");
7
- const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
- class OpraEntitySearchTester extends base_operation_tester_js_1.BaseOperationTester {
9
- constructor(params) {
10
- super(params);
11
- }
12
- limit(value) {
13
- this._params.options.limit = value;
14
- return this;
15
- }
16
- skip(value) {
17
- this._params.options.skip = value;
18
- return this;
19
- }
20
- count(value = true) {
21
- this._params.options.count = value;
22
- return this;
23
- }
24
- distinct(value) {
25
- this._params.options.distinct = value;
26
- return this;
27
- }
28
- sort(...fields) {
29
- this._params.options.sort = fields.flat();
30
- return this;
31
- }
32
- filter(value) {
33
- this._params.options.filter = value;
34
- return this;
35
- }
36
- omit(...fields) {
37
- this._params.options.omit = fields.flat();
38
- return this;
39
- }
40
- pick(...fields) {
41
- this._params.options.pick = fields.flat();
42
- return this;
43
- }
44
- include(...fields) {
45
- this._params.options.include = fields.flat();
46
- return this;
47
- }
48
- async _send() {
49
- const url = new url_1.OpraURL(this._params.path);
50
- url.pathPrefix = this._params.prefix;
51
- if (this._params.options.include)
52
- url.searchParams.set('$include', this._params.options.include);
53
- if (this._params.options.pick)
54
- url.searchParams.set('$pick', this._params.options.pick);
55
- if (this._params.options.omit)
56
- url.searchParams.set('$omit', this._params.options.omit);
57
- if (this._params.options.sort)
58
- url.searchParams.set('$sort', this._params.options.sort);
59
- if (this._params.options.filter)
60
- url.searchParams.set('$filter', this._params.options.filter);
61
- if (this._params.options.limit != null)
62
- url.searchParams.set('$limit', this._params.options.limit);
63
- if (this._params.options.skip != null)
64
- url.searchParams.set('$skip', this._params.options.skip);
65
- if (this._params.options.count != null)
66
- url.searchParams.set('$count', this._params.options.count);
67
- if (this._params.options.distinct != null)
68
- url.searchParams.set('$distinct', this._params.options.distinct);
69
- const req = (0, supertest_1.default)(this._params.app);
70
- const test = req.get(url.toString());
71
- this._prepare(test);
72
- return test.send();
73
- }
74
- }
75
- exports.OpraEntitySearchTester = OpraEntitySearchTester;
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraEntityTester = void 0;
4
- const base_tester_js_1 = require("./base-tester.js");
5
- const entity_create_tester_js_1 = require("./entity-create-tester.js");
6
- const entity_delete_many_tester_js_1 = require("./entity-delete-many-tester.js");
7
- const entity_delete_tester_js_1 = require("./entity-delete-tester.js");
8
- const entity_get_tester_js_1 = require("./entity-get-tester.js");
9
- const entity_search_tester_js_1 = require("./entity-search-tester.js");
10
- const entity_update_many_tester_js_1 = require("./entity-update-many-tester.js");
11
- const entity_update_tester_js_1 = require("./entity-update-tester.js");
12
- class OpraEntityTester extends base_tester_js_1.BaseTester {
13
- constructor(params) {
14
- super(params);
15
- }
16
- create(data, options = {}) {
17
- return new entity_create_tester_js_1.OpraEntityCreateTester({
18
- ...this._params,
19
- headers: { ...this._params.headers },
20
- data,
21
- options
22
- });
23
- }
24
- get(keyValue, options = {}) {
25
- return new entity_get_tester_js_1.OpraEntityGetTester({
26
- ...this._params,
27
- headers: { ...this._params.headers },
28
- keyValue,
29
- options
30
- });
31
- }
32
- search(options = {}) {
33
- return new entity_search_tester_js_1.OpraEntitySearchTester({
34
- ...this._params,
35
- headers: { ...this._params.headers },
36
- options
37
- });
38
- }
39
- update(keyValue, data, options = {}) {
40
- return new entity_update_tester_js_1.OpraEntityUpdateTester({
41
- ...this._params,
42
- keyValue,
43
- headers: { ...this._params.headers },
44
- data,
45
- options
46
- });
47
- }
48
- updateMany(data, options = {}) {
49
- return new entity_update_many_tester_js_1.OpraEntityUpdateManyTester({
50
- ...this._params,
51
- headers: { ...this._params.headers },
52
- data,
53
- options
54
- });
55
- }
56
- delete(keyValue, options = {}) {
57
- return new entity_delete_tester_js_1.OpraEntityDeleteTester({
58
- ...this._params,
59
- keyValue,
60
- headers: { ...this._params.headers },
61
- options
62
- });
63
- }
64
- deleteMany(options = {}) {
65
- return new entity_delete_many_tester_js_1.OpraEntityDeleteManyTester({
66
- ...this._params,
67
- headers: { ...this._params.headers },
68
- options
69
- });
70
- }
71
- }
72
- exports.OpraEntityTester = OpraEntityTester;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraEntityUpdateManyTester = void 0;
4
- const tslib_1 = require("tslib");
5
- const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
- const url_1 = require("@opra/url");
7
- const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
- class OpraEntityUpdateManyTester extends base_operation_tester_js_1.BaseOperationTester {
9
- constructor(params) {
10
- super(params);
11
- }
12
- data(data) {
13
- this._params.data = data;
14
- return this;
15
- }
16
- filter(value) {
17
- this._params.options.filter = value;
18
- return this;
19
- }
20
- async _send() {
21
- const url = new url_1.OpraURL(this._params.path);
22
- url.pathPrefix = this._params.prefix;
23
- if (this._params.options.filter)
24
- url.searchParams.set('$filter', this._params.options.filter);
25
- const req = (0, supertest_1.default)(this._params.app);
26
- const test = req.patch(url.toString());
27
- this._prepare(test);
28
- return test.send(this._params.data);
29
- }
30
- }
31
- exports.OpraEntityUpdateManyTester = OpraEntityUpdateManyTester;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraEntityUpdateTester = void 0;
4
- const tslib_1 = require("tslib");
5
- const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
- const url_1 = require("@opra/url");
7
- const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
- class OpraEntityUpdateTester extends base_operation_tester_js_1.BaseOperationTester {
9
- constructor(params) {
10
- super(params);
11
- if (!params.keyValue)
12
- throw new Error(`You must provide "keyValue"`);
13
- }
14
- data(data) {
15
- this._params.data = data;
16
- return this;
17
- }
18
- omit(...fields) {
19
- this._params.options.omit = fields.flat();
20
- return this;
21
- }
22
- pick(...fields) {
23
- this._params.options.pick = fields.flat();
24
- return this;
25
- }
26
- include(...fields) {
27
- this._params.options.include = fields.flat();
28
- return this;
29
- }
30
- async _send() {
31
- const url = new url_1.OpraURL(this._params.path);
32
- url.pathPrefix = this._params.prefix;
33
- url.path.get(url.path.size - 1).key = this._params.keyValue;
34
- if (this._params.options.include)
35
- url.searchParams.set('$include', this._params.options.include);
36
- if (this._params.options.pick)
37
- url.searchParams.set('$pick', this._params.options.pick);
38
- if (this._params.options.omit)
39
- url.searchParams.set('$omit', this._params.options.omit);
40
- const req = (0, supertest_1.default)(this._params.app);
41
- const test = req.patch(url.toString());
42
- this._prepare(test);
43
- return test.send(this._params.data);
44
- }
45
- }
46
- exports.OpraEntityUpdateTester = OpraEntityUpdateTester;
@@ -1,12 +0,0 @@
1
- import { ApiExpect } from './expect/api-expect.js';
2
- export declare class ApiResponse {
3
- status: number;
4
- body: any;
5
- rawBody: string;
6
- headers: Record<string, string>;
7
- contentType: string;
8
- charset: string;
9
- readonly expect: ApiExpect;
10
- constructor(args: Pick<ApiResponse, 'status' | 'body' | 'headers' | 'rawBody' | 'contentType' | 'charset'>);
11
- get(header: string): string;
12
- }
@@ -1,18 +0,0 @@
1
- import { ApiExpect } from './expect/api-expect.js';
2
- export class ApiResponse {
3
- status;
4
- body;
5
- rawBody;
6
- headers;
7
- contentType;
8
- charset;
9
- expect;
10
- constructor(args) {
11
- Object.assign(this, args);
12
- this.expect = new ApiExpect(this);
13
- }
14
- get(header) {
15
- const key = Object.keys(this.headers).find(k => k.toLowerCase() === header.toLowerCase());
16
- return (key && this.headers[key]) || '';
17
- }
18
- }
@@ -1,17 +0,0 @@
1
- import { Expression } from '@opra/url';
2
- import type { ApiResponse } from '../api-response';
3
- export declare class ApiExpectArray {
4
- readonly response: ApiResponse;
5
- constructor(response: ApiResponse);
6
- toMatch<T extends {}>(expected: T): this;
7
- toContainAllKeys(keys: string[]): this;
8
- toContainKeys(keys: string[]): this;
9
- notToContainKeys(keys: string[]): this;
10
- toHaveProperty(keyPath: any, value?: any): this;
11
- toBeSortedBy(...fields: string[]): this;
12
- toBeFilteredBy(filter: string | Expression): this;
13
- toHaveExactItems(expected: number): this;
14
- toHaveMaxItems(expected: number): this;
15
- toHaveMinItems(expected: number): this;
16
- }
17
- export declare function convertFilter(str: string | Expression | undefined): any;
@@ -1,12 +0,0 @@
1
- import type { ApiResponse } from '../api-response';
2
- export declare class ApiExpectObject {
3
- readonly response: ApiResponse;
4
- constructor(response: ApiResponse);
5
- get body(): any;
6
- toMatch<T extends {}>(expected: T): this;
7
- toContainAllKeys(keys: string[]): this;
8
- toContainKeys(keys: string[]): this;
9
- notToContainKeys(keys: string[]): this;
10
- toHaveProperty(keyPath: any, value?: any): this;
11
- notToHaveProperty(keyPath: any, value?: any): this;
12
- }