@opra/testing 0.0.9 → 0.0.11

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 (35) hide show
  1. package/cjs/expect/api-expect-fail.js +15 -0
  2. package/cjs/expect/api-expect-list.js +104 -6
  3. package/cjs/expect/api-expect-resource.js +1 -1
  4. package/cjs/expect/api-expect.js +18 -18
  5. package/cjs/testers/base-operation-tester.js +16 -0
  6. package/cjs/testers/entity-create-tester.js +16 -16
  7. package/cjs/testers/entity-get-tester.js +17 -17
  8. package/cjs/testers/entity-search-tester.js +75 -0
  9. package/cjs/testers/entity-tester.js +20 -2
  10. package/cjs/testers/entity-update-tester.js +44 -0
  11. package/esm/expect/api-expect-fail.d.ts +6 -0
  12. package/esm/expect/api-expect-fail.js +11 -0
  13. package/esm/expect/api-expect-list.d.ts +9 -2
  14. package/esm/expect/api-expect-list.js +101 -5
  15. package/esm/expect/api-expect-resource.d.ts +1 -1
  16. package/esm/expect/api-expect-resource.js +1 -1
  17. package/esm/expect/api-expect.d.ts +5 -8
  18. package/esm/expect/api-expect.js +18 -18
  19. package/esm/testers/base-operation-tester.d.ts +12 -0
  20. package/esm/testers/base-operation-tester.js +12 -0
  21. package/esm/testers/base-tester.d.ts +1 -1
  22. package/esm/testers/entity-create-tester.d.ts +3 -3
  23. package/esm/testers/entity-create-tester.js +16 -16
  24. package/esm/testers/entity-get-tester.d.ts +3 -3
  25. package/esm/testers/entity-get-tester.js +17 -17
  26. package/esm/testers/entity-search-tester.d.ts +22 -0
  27. package/esm/testers/entity-search-tester.js +70 -0
  28. package/esm/testers/entity-tester.d.ts +6 -2
  29. package/esm/testers/entity-tester.js +20 -2
  30. package/esm/testers/entity-update-tester.d.ts +19 -0
  31. package/esm/testers/entity-update-tester.js +39 -0
  32. package/package.json +4 -3
  33. package/cjs/expect/api-expect-errors.js +0 -17
  34. package/esm/expect/api-expect-errors.d.ts +0 -6
  35. package/esm/expect/api-expect-errors.js +0 -13
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiExpectFail = void 0;
4
+ const api_expect_body_js_1 = require("./api-expect-body.js");
5
+ class ApiExpectFail extends api_expect_body_js_1.ApiExpectBody {
6
+ _errors;
7
+ constructor(_errors) {
8
+ super();
9
+ this._errors = _errors;
10
+ }
11
+ toContain(...issue) {
12
+ expect(this._errors).toEqual(expect.arrayContaining(issue.map(o => expect.objectContaining(o))));
13
+ }
14
+ }
15
+ exports.ApiExpectFail = ApiExpectFail;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExpectList = void 0;
3
+ exports.convertFilter = exports.ApiExpectList = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const rule_judgment_1 = tslib_1.__importDefault(require("rule-judgment"));
6
+ const url_1 = require("@opra/url");
4
7
  const api_expect_body_js_1 = require("./api-expect-body.js");
5
8
  class ApiExpectList extends api_expect_body_js_1.ApiExpectBody {
6
9
  _body;
@@ -8,12 +11,10 @@ class ApiExpectList extends api_expect_body_js_1.ApiExpectBody {
8
11
  super();
9
12
  this._body = _body;
10
13
  }
11
- toBeDefined() {
12
- expect(this._body).toBeDefined();
13
- expect(this._body.items).toBeDefined();
14
- return this;
14
+ get items() {
15
+ return this._body.items;
15
16
  }
16
- toMatchObject(value) {
17
+ toMatch(value) {
17
18
  return this._toMatchObject(this._body.items || [], value);
18
19
  }
19
20
  haveKeysOnly(keys) {
@@ -28,5 +29,102 @@ class ApiExpectList extends api_expect_body_js_1.ApiExpectBody {
28
29
  this._notHaveKeys(this._body.items || [], keys);
29
30
  return this;
30
31
  }
32
+ toBeSortedBy(...fields) {
33
+ const fieldsMap = fields.map(x => x.split('.'));
34
+ const getValue = (obj, fieldMap) => {
35
+ let v = obj;
36
+ let i = 0;
37
+ while (v && i < fieldMap.length) {
38
+ v = v[fieldMap[i++]];
39
+ }
40
+ return v;
41
+ };
42
+ expect(this._body.items).toBeSorted((a, b) => {
43
+ for (const sortField of fieldsMap) {
44
+ const l = getValue(a, sortField);
45
+ const r = getValue(b, sortField);
46
+ if (l < r)
47
+ return -1;
48
+ if (l > r)
49
+ return 1;
50
+ }
51
+ return 0;
52
+ });
53
+ return this;
54
+ }
55
+ toBeFilteredBy(filter) {
56
+ const f = convertFilter(filter);
57
+ if (f) {
58
+ const j = (0, rule_judgment_1.default)(f);
59
+ const filtered = this._body.items.filter(j);
60
+ expect(this._body.items).toStrictEqual(filtered);
61
+ }
62
+ return this;
63
+ }
64
+ toHaveExactItems(expected) {
65
+ return expect(this._body.items.length).toStrictEqual(expected);
66
+ }
67
+ toHaveMaxItems(expected) {
68
+ return expect(this._body.items.length).toBeLessThanOrEqual(expected);
69
+ }
70
+ toHaveMinItems(expected) {
71
+ return expect(this._body.items.length).toBeGreaterThanOrEqual(expected);
72
+ }
31
73
  }
32
74
  exports.ApiExpectList = ApiExpectList;
75
+ function convertFilter(str) {
76
+ const ast = typeof str === 'string' ? (0, url_1.$parse)(str) : str;
77
+ if (!ast)
78
+ return;
79
+ if (ast instanceof url_1.ComparisonExpression) {
80
+ const left = convertFilter(ast.left);
81
+ const right = convertFilter(ast.right);
82
+ switch (ast.op) {
83
+ case '=':
84
+ return { $eq: { [left]: right } };
85
+ case '!=':
86
+ return { $ne: { [left]: right } };
87
+ case '>':
88
+ return { $gt: { [left]: right } };
89
+ case '>=':
90
+ return { $gte: { [left]: right } };
91
+ case '<':
92
+ return { $lt: { [left]: right } };
93
+ case '<=':
94
+ return { $lte: { [left]: right } };
95
+ case 'in':
96
+ return { $in: { [left]: right } };
97
+ case '!in':
98
+ return { $nin: { [left]: right } };
99
+ default:
100
+ throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
101
+ }
102
+ }
103
+ if (ast instanceof url_1.QualifiedIdentifier) {
104
+ return ast.value;
105
+ }
106
+ if (ast instanceof url_1.NumberLiteral ||
107
+ ast instanceof url_1.StringLiteral ||
108
+ ast instanceof url_1.BooleanLiteral ||
109
+ ast instanceof url_1.NullLiteral ||
110
+ ast instanceof url_1.DateLiteral ||
111
+ ast instanceof url_1.TimeLiteral) {
112
+ return ast.value;
113
+ }
114
+ if (ast instanceof url_1.ArrayExpression) {
115
+ return ast.items.map(convertFilter);
116
+ }
117
+ if (ast instanceof url_1.LogicalExpression) {
118
+ if (ast.op === 'or')
119
+ return { $or: ast.items.map(convertFilter) };
120
+ return { $and: ast.items.map(convertFilter) };
121
+ }
122
+ if (ast instanceof url_1.ArrayExpression) {
123
+ return ast.items.map(convertFilter);
124
+ }
125
+ if (ast instanceof url_1.ParenthesesExpression) {
126
+ return convertFilter(ast.expression);
127
+ }
128
+ throw new Error(`${ast.type} is not implemented yet`);
129
+ }
130
+ exports.convertFilter = convertFilter;
@@ -12,7 +12,7 @@ class ApiExpectResource extends api_expect_body_js_1.ApiExpectBody {
12
12
  expect(this._body).toBeDefined();
13
13
  return this;
14
14
  }
15
- toMatchObject(value) {
15
+ toMatch(value) {
16
16
  return this._toMatchObject([this._body], value);
17
17
  }
18
18
  haveKeysOnly(keys) {
@@ -1,37 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiExpect = void 0;
4
- const api_expect_errors_js_1 = require("./api-expect-errors.js");
4
+ require("./jest-extend.js");
5
+ const api_expect_fail_js_1 = require("./api-expect-fail.js");
5
6
  const api_expect_list_js_1 = require("./api-expect-list.js");
6
7
  const api_expect_resource_js_1 = require("./api-expect-resource.js");
7
8
  class ApiExpect {
8
9
  response;
9
- _bodyResource;
10
- _bodyList;
11
- _bodyErrors;
12
10
  constructor(response) {
13
11
  this.response = response;
14
12
  }
15
- status(value) {
16
- expect(this.response.status).toEqual(value);
13
+ toSuccess(status = 200) {
14
+ expect(this.response.body.errors).toStrictEqual(undefined);
15
+ expect(this.response.status).toEqual(status);
17
16
  return this;
18
17
  }
19
- get bodyAsResource() {
20
- return this._bodyResource =
21
- this._bodyResource || new api_expect_resource_js_1.ApiExpectResource(this.response.body);
18
+ toReturnResource(fn) {
19
+ expect(this.response.body).toBeDefined();
20
+ fn(new api_expect_resource_js_1.ApiExpectResource(this.response.body));
21
+ return this;
22
22
  }
23
- get bodyAsList() {
24
- return this._bodyList =
25
- this._bodyList || new api_expect_list_js_1.ApiExpectList(this.response.body);
23
+ toReturnList(fn) {
24
+ expect(this.response.body).toBeDefined();
25
+ expect(this.response.body.items).toBeDefined();
26
+ fn(new api_expect_list_js_1.ApiExpectList(this.response.body));
27
+ return this;
26
28
  }
27
- toSuccess(status = 200) {
28
- expect(this.response.body.errors).toStrictEqual(undefined);
29
+ toFail(status = 400, fn) {
30
+ expect(this.response.body.errors).toBeDefined();
29
31
  expect(this.response.status).toEqual(status);
32
+ if (fn)
33
+ fn(new api_expect_fail_js_1.ApiExpectFail(this.response.body.errors));
30
34
  return this;
31
35
  }
32
- get errors() {
33
- return this._bodyErrors =
34
- this._bodyErrors || new api_expect_errors_js_1.ApiExpectErrors(this.response.body);
35
- }
36
36
  }
37
37
  exports.ApiExpect = ApiExpect;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseOperationTester = void 0;
4
+ const api_expect_js_1 = require("../expect/api-expect.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 resp = await this._send();
9
+ if (fn) {
10
+ fn(new api_expect_js_1.ApiExpect(resp));
11
+ return;
12
+ }
13
+ return resp;
14
+ }
15
+ }
16
+ exports.BaseOperationTester = BaseOperationTester;
@@ -4,25 +4,11 @@ exports.OpraEntityCreateTester = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
6
  const url_1 = require("@opra/url");
7
- const base_tester_js_1 = require("./base-tester.js");
8
- class OpraEntityCreateTester extends base_tester_js_1.BaseTester {
7
+ const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
+ class OpraEntityCreateTester extends base_operation_tester_js_1.BaseOperationTester {
9
9
  constructor(params) {
10
10
  super(params);
11
11
  }
12
- async send() {
13
- const url = new url_1.OpraURL(this._params.path);
14
- url.pathPrefix = this._params.prefix;
15
- if (this._params.options.include)
16
- url.searchParams.set('$include', this._params.options.include);
17
- if (this._params.options.pick)
18
- url.searchParams.set('$pick', this._params.options.pick);
19
- if (this._params.options.omit)
20
- url.searchParams.set('$omit', this._params.options.omit);
21
- const req = (0, supertest_1.default)(this._params.app);
22
- const test = req.post(url.toString());
23
- this._prepare(test);
24
- return test.send(this._params.data);
25
- }
26
12
  data(data) {
27
13
  this._params.data = data;
28
14
  return this;
@@ -39,5 +25,19 @@ class OpraEntityCreateTester extends base_tester_js_1.BaseTester {
39
25
  this._params.options.include = fields.flat();
40
26
  return this;
41
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
42
  }
43
43
  exports.OpraEntityCreateTester = OpraEntityCreateTester;
@@ -4,26 +4,11 @@ exports.OpraEntityGetTester = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const supertest_1 = tslib_1.__importDefault(require("supertest"));
6
6
  const url_1 = require("@opra/url");
7
- const base_tester_js_1 = require("./base-tester.js");
8
- class OpraEntityGetTester extends base_tester_js_1.BaseTester {
7
+ const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
+ class OpraEntityGetTester extends base_operation_tester_js_1.BaseOperationTester {
9
9
  constructor(params) {
10
10
  super(params);
11
11
  }
12
- async send() {
13
- const url = new url_1.OpraURL(this._params.path);
14
- url.pathPrefix = this._params.prefix;
15
- url.path.get(url.path.size - 1).key = this._params.keyValue;
16
- if (this._params.options.include)
17
- url.searchParams.set('$include', this._params.options.include);
18
- if (this._params.options.pick)
19
- url.searchParams.set('$pick', this._params.options.pick);
20
- if (this._params.options.omit)
21
- url.searchParams.set('$omit', this._params.options.omit);
22
- const req = (0, supertest_1.default)(this._params.app);
23
- const test = req.get(url.toString());
24
- this._prepare(test);
25
- return test.send();
26
- }
27
12
  keyValue(value) {
28
13
  this._params.keyValue = value;
29
14
  return this;
@@ -40,5 +25,20 @@ class OpraEntityGetTester extends base_tester_js_1.BaseTester {
40
25
  this._params.options.include = fields.flat();
41
26
  return this;
42
27
  }
28
+ async _send() {
29
+ const url = new url_1.OpraURL(this._params.path);
30
+ url.pathPrefix = this._params.prefix;
31
+ url.path.get(url.path.size - 1).key = this._params.keyValue;
32
+ if (this._params.options.include)
33
+ url.searchParams.set('$include', this._params.options.include);
34
+ if (this._params.options.pick)
35
+ url.searchParams.set('$pick', this._params.options.pick);
36
+ if (this._params.options.omit)
37
+ url.searchParams.set('$omit', this._params.options.omit);
38
+ const req = (0, supertest_1.default)(this._params.app);
39
+ const test = req.get(url.toString());
40
+ this._prepare(test);
41
+ return test.send();
42
+ }
43
43
  }
44
44
  exports.OpraEntityGetTester = OpraEntityGetTester;
@@ -0,0 +1,75 @@
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) {
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;
@@ -4,10 +4,20 @@ exports.OpraEntityTester = void 0;
4
4
  const base_tester_js_1 = require("./base-tester.js");
5
5
  const entity_create_tester_js_1 = require("./entity-create-tester.js");
6
6
  const entity_get_tester_js_1 = require("./entity-get-tester.js");
7
+ const entity_search_tester_js_1 = require("./entity-search-tester.js");
8
+ const entity_update_tester_js_1 = require("./entity-update-tester.js");
7
9
  class OpraEntityTester extends base_tester_js_1.BaseTester {
8
10
  constructor(params) {
9
11
  super(params);
10
12
  }
13
+ create(data, options = {}) {
14
+ return new entity_create_tester_js_1.OpraEntityCreateTester({
15
+ ...this._params,
16
+ headers: { ...this._params.headers },
17
+ data,
18
+ options
19
+ });
20
+ }
11
21
  get(keyValue, options = {}) {
12
22
  return new entity_get_tester_js_1.OpraEntityGetTester({
13
23
  ...this._params,
@@ -16,9 +26,17 @@ class OpraEntityTester extends base_tester_js_1.BaseTester {
16
26
  options
17
27
  });
18
28
  }
19
- create(data, options = {}) {
20
- return new entity_create_tester_js_1.OpraEntityCreateTester({
29
+ search(options = {}) {
30
+ return new entity_search_tester_js_1.OpraEntitySearchTester({
31
+ ...this._params,
32
+ headers: { ...this._params.headers },
33
+ options
34
+ });
35
+ }
36
+ update(keyValue, data, options = {}) {
37
+ return new entity_update_tester_js_1.OpraEntityUpdateTester({
21
38
  ...this._params,
39
+ keyValue,
22
40
  headers: { ...this._params.headers },
23
41
  data,
24
42
  options
@@ -0,0 +1,44 @@
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
+ }
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
+ url.path.get(url.path.size - 1).key = this._params.keyValue;
32
+ if (this._params.options.include)
33
+ url.searchParams.set('$include', this._params.options.include);
34
+ if (this._params.options.pick)
35
+ url.searchParams.set('$pick', this._params.options.pick);
36
+ if (this._params.options.omit)
37
+ url.searchParams.set('$omit', this._params.options.omit);
38
+ const req = (0, supertest_1.default)(this._params.app);
39
+ const test = req.post(url.toString());
40
+ this._prepare(test);
41
+ return test.send(this._params.data);
42
+ }
43
+ }
44
+ exports.OpraEntityUpdateTester = OpraEntityUpdateTester;
@@ -0,0 +1,6 @@
1
+ import { ApiExpectBody } from './api-expect-body.js';
2
+ export declare class ApiExpectFail extends ApiExpectBody {
3
+ protected _errors: any;
4
+ constructor(_errors: any);
5
+ toContain(...issue: any[]): void;
6
+ }
@@ -0,0 +1,11 @@
1
+ import { ApiExpectBody } from './api-expect-body.js';
2
+ export class ApiExpectFail extends ApiExpectBody {
3
+ _errors;
4
+ constructor(_errors) {
5
+ super();
6
+ this._errors = _errors;
7
+ }
8
+ toContain(...issue) {
9
+ expect(this._errors).toEqual(expect.arrayContaining(issue.map(o => expect.objectContaining(o))));
10
+ }
11
+ }
@@ -1,10 +1,17 @@
1
+ import { Expression } from '@opra/url';
1
2
  import { ApiExpectBody } from './api-expect-body.js';
2
3
  export declare class ApiExpectList extends ApiExpectBody {
3
4
  protected _body: any;
4
5
  constructor(_body: any);
5
- toBeDefined(): this;
6
- toMatchObject<T extends {}>(value: T): this;
6
+ get items(): any;
7
+ toMatch<T extends {}>(value: T): this;
7
8
  haveKeysOnly(keys: string[]): this;
8
9
  haveKeys(keys: string[]): this;
9
10
  notHaveKeys(keys: string[]): this;
11
+ toBeSortedBy(...fields: string[]): this;
12
+ toBeFilteredBy(filter: string | Expression): this;
13
+ toHaveExactItems(expected: number): void;
14
+ toHaveMaxItems(expected: number): void;
15
+ toHaveMinItems(expected: number): void;
10
16
  }
17
+ export declare function convertFilter(str: string | Expression | undefined): any;
@@ -1,3 +1,5 @@
1
+ import ruleJudgment from 'rule-judgment';
2
+ import { $parse, ArrayExpression, BooleanLiteral, ComparisonExpression, DateLiteral, LogicalExpression, NullLiteral, NumberLiteral, ParenthesesExpression, QualifiedIdentifier, StringLiteral, TimeLiteral } from '@opra/url';
1
3
  import { ApiExpectBody } from './api-expect-body.js';
2
4
  export class ApiExpectList extends ApiExpectBody {
3
5
  _body;
@@ -5,12 +7,10 @@ export class ApiExpectList extends ApiExpectBody {
5
7
  super();
6
8
  this._body = _body;
7
9
  }
8
- toBeDefined() {
9
- expect(this._body).toBeDefined();
10
- expect(this._body.items).toBeDefined();
11
- return this;
10
+ get items() {
11
+ return this._body.items;
12
12
  }
13
- toMatchObject(value) {
13
+ toMatch(value) {
14
14
  return this._toMatchObject(this._body.items || [], value);
15
15
  }
16
16
  haveKeysOnly(keys) {
@@ -25,4 +25,100 @@ export class ApiExpectList extends ApiExpectBody {
25
25
  this._notHaveKeys(this._body.items || [], keys);
26
26
  return this;
27
27
  }
28
+ toBeSortedBy(...fields) {
29
+ const fieldsMap = fields.map(x => x.split('.'));
30
+ const getValue = (obj, fieldMap) => {
31
+ let v = obj;
32
+ let i = 0;
33
+ while (v && i < fieldMap.length) {
34
+ v = v[fieldMap[i++]];
35
+ }
36
+ return v;
37
+ };
38
+ expect(this._body.items).toBeSorted((a, b) => {
39
+ for (const sortField of fieldsMap) {
40
+ const l = getValue(a, sortField);
41
+ const r = getValue(b, sortField);
42
+ if (l < r)
43
+ return -1;
44
+ if (l > r)
45
+ return 1;
46
+ }
47
+ return 0;
48
+ });
49
+ return this;
50
+ }
51
+ toBeFilteredBy(filter) {
52
+ const f = convertFilter(filter);
53
+ if (f) {
54
+ const j = ruleJudgment(f);
55
+ const filtered = this._body.items.filter(j);
56
+ expect(this._body.items).toStrictEqual(filtered);
57
+ }
58
+ return this;
59
+ }
60
+ toHaveExactItems(expected) {
61
+ return expect(this._body.items.length).toStrictEqual(expected);
62
+ }
63
+ toHaveMaxItems(expected) {
64
+ return expect(this._body.items.length).toBeLessThanOrEqual(expected);
65
+ }
66
+ toHaveMinItems(expected) {
67
+ return expect(this._body.items.length).toBeGreaterThanOrEqual(expected);
68
+ }
69
+ }
70
+ export function convertFilter(str) {
71
+ const ast = typeof str === 'string' ? $parse(str) : str;
72
+ if (!ast)
73
+ return;
74
+ if (ast instanceof ComparisonExpression) {
75
+ const left = convertFilter(ast.left);
76
+ const right = convertFilter(ast.right);
77
+ switch (ast.op) {
78
+ case '=':
79
+ return { $eq: { [left]: right } };
80
+ case '!=':
81
+ return { $ne: { [left]: right } };
82
+ case '>':
83
+ return { $gt: { [left]: right } };
84
+ case '>=':
85
+ return { $gte: { [left]: right } };
86
+ case '<':
87
+ return { $lt: { [left]: right } };
88
+ case '<=':
89
+ return { $lte: { [left]: right } };
90
+ case 'in':
91
+ return { $in: { [left]: right } };
92
+ case '!in':
93
+ return { $nin: { [left]: right } };
94
+ default:
95
+ throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
96
+ }
97
+ }
98
+ if (ast instanceof QualifiedIdentifier) {
99
+ return ast.value;
100
+ }
101
+ if (ast instanceof NumberLiteral ||
102
+ ast instanceof StringLiteral ||
103
+ ast instanceof BooleanLiteral ||
104
+ ast instanceof NullLiteral ||
105
+ ast instanceof DateLiteral ||
106
+ ast instanceof TimeLiteral) {
107
+ return ast.value;
108
+ }
109
+ if (ast instanceof ArrayExpression) {
110
+ return ast.items.map(convertFilter);
111
+ }
112
+ if (ast instanceof LogicalExpression) {
113
+ if (ast.op === 'or')
114
+ return { $or: ast.items.map(convertFilter) };
115
+ return { $and: ast.items.map(convertFilter) };
116
+ }
117
+ if (ast instanceof ArrayExpression) {
118
+ return ast.items.map(convertFilter);
119
+ }
120
+ if (ast instanceof ParenthesesExpression) {
121
+ return convertFilter(ast.expression);
122
+ }
123
+ throw new Error(`${ast.type} is not implemented yet`);
28
124
  }
@@ -3,7 +3,7 @@ export declare class ApiExpectResource extends ApiExpectBody {
3
3
  protected _body: any;
4
4
  constructor(_body: any);
5
5
  toBeDefined(): this;
6
- toMatchObject<T extends {}>(value: T): this;
6
+ toMatch<T extends {}>(value: T): this;
7
7
  haveKeysOnly(keys: string[]): this;
8
8
  haveKeys(keys: string[]): this;
9
9
  notHaveKeys(keys: string[]): this;
@@ -9,7 +9,7 @@ export class ApiExpectResource extends ApiExpectBody {
9
9
  expect(this._body).toBeDefined();
10
10
  return this;
11
11
  }
12
- toMatchObject(value) {
12
+ toMatch(value) {
13
13
  return this._toMatchObject([this._body], value);
14
14
  }
15
15
  haveKeysOnly(keys) {
@@ -1,16 +1,13 @@
1
+ import './jest-extend.js';
1
2
  import { Response } from 'supertest';
2
- import { ApiExpectErrors } from './api-expect-errors.js';
3
+ import { ApiExpectFail } from './api-expect-fail.js';
3
4
  import { ApiExpectList } from './api-expect-list.js';
4
5
  import { ApiExpectResource } from './api-expect-resource.js';
5
6
  export declare class ApiExpect {
6
7
  readonly response: Response;
7
- protected _bodyResource?: ApiExpectResource;
8
- protected _bodyList?: ApiExpectList;
9
- protected _bodyErrors?: ApiExpectErrors;
10
8
  constructor(response: Response);
11
- status(value: number): this;
12
- get bodyAsResource(): ApiExpectResource;
13
- get bodyAsList(): ApiExpectList;
14
9
  toSuccess(status?: number): this;
15
- get errors(): ApiExpectErrors;
10
+ toReturnResource(fn: (body: ApiExpectResource) => void): this;
11
+ toReturnList(fn: (body: ApiExpectList) => void): this;
12
+ toFail(status?: number, fn?: (errors: ApiExpectFail) => void): this;
16
13
  }
@@ -1,33 +1,33 @@
1
- import { ApiExpectErrors } from './api-expect-errors.js';
1
+ import './jest-extend.js';
2
+ import { ApiExpectFail } from './api-expect-fail.js';
2
3
  import { ApiExpectList } from './api-expect-list.js';
3
4
  import { ApiExpectResource } from './api-expect-resource.js';
4
5
  export class ApiExpect {
5
6
  response;
6
- _bodyResource;
7
- _bodyList;
8
- _bodyErrors;
9
7
  constructor(response) {
10
8
  this.response = response;
11
9
  }
12
- status(value) {
13
- expect(this.response.status).toEqual(value);
10
+ toSuccess(status = 200) {
11
+ expect(this.response.body.errors).toStrictEqual(undefined);
12
+ expect(this.response.status).toEqual(status);
14
13
  return this;
15
14
  }
16
- get bodyAsResource() {
17
- return this._bodyResource =
18
- this._bodyResource || new ApiExpectResource(this.response.body);
15
+ toReturnResource(fn) {
16
+ expect(this.response.body).toBeDefined();
17
+ fn(new ApiExpectResource(this.response.body));
18
+ return this;
19
19
  }
20
- get bodyAsList() {
21
- return this._bodyList =
22
- this._bodyList || new ApiExpectList(this.response.body);
20
+ toReturnList(fn) {
21
+ expect(this.response.body).toBeDefined();
22
+ expect(this.response.body.items).toBeDefined();
23
+ fn(new ApiExpectList(this.response.body));
24
+ return this;
23
25
  }
24
- toSuccess(status = 200) {
25
- expect(this.response.body.errors).toStrictEqual(undefined);
26
+ toFail(status = 400, fn) {
27
+ expect(this.response.body.errors).toBeDefined();
26
28
  expect(this.response.status).toEqual(status);
29
+ if (fn)
30
+ fn(new ApiExpectFail(this.response.body.errors));
27
31
  return this;
28
32
  }
29
- get errors() {
30
- return this._bodyErrors =
31
- this._bodyErrors || new ApiExpectErrors(this.response.body);
32
- }
33
33
  }
@@ -0,0 +1,12 @@
1
+ import { Response } from 'supertest';
2
+ import { BaseTester } from './base-tester.js';
3
+ export interface OpraTesterParams {
4
+ app: any;
5
+ prefix: string;
6
+ headers: Record<string, string>;
7
+ }
8
+ export declare abstract class BaseOperationTester extends BaseTester {
9
+ send(): Promise<Response>;
10
+ send(fn: (expect: any) => void): Promise<void>;
11
+ protected abstract _send(): Promise<Response>;
12
+ }
@@ -0,0 +1,12 @@
1
+ import { ApiExpect } from '../expect/api-expect.js';
2
+ import { BaseTester } from './base-tester.js';
3
+ export class BaseOperationTester extends BaseTester {
4
+ async send(fn) {
5
+ const resp = await this._send();
6
+ if (fn) {
7
+ fn(new ApiExpect(resp));
8
+ return;
9
+ }
10
+ return resp;
11
+ }
12
+ }
@@ -4,7 +4,7 @@ export interface OpraTesterParams {
4
4
  prefix: string;
5
5
  headers: Record<string, string>;
6
6
  }
7
- export declare class BaseTester {
7
+ export declare abstract class BaseTester {
8
8
  protected readonly _params: OpraTesterParams;
9
9
  constructor(params: OpraTesterParams);
10
10
  prefix(value: string): this;
@@ -1,17 +1,17 @@
1
1
  import { Response } from 'supertest';
2
2
  import { CreateQueryOptions } from '@opra/core';
3
- import { BaseTester } from './base-tester.js';
3
+ import { BaseOperationTester } from './base-operation-tester.js';
4
4
  import type { OpraEntityTesterParams } from './entity-tester.js';
5
5
  export declare type OpraEntityCreateTesterParams = OpraEntityTesterParams & {
6
6
  data: {};
7
7
  options: CreateQueryOptions;
8
8
  };
9
- export declare class OpraEntityCreateTester extends BaseTester {
9
+ export declare class OpraEntityCreateTester extends BaseOperationTester {
10
10
  protected readonly _params: OpraEntityCreateTesterParams;
11
11
  constructor(params: OpraEntityCreateTesterParams);
12
- send(): Promise<Response>;
13
12
  data(data: {}): this;
14
13
  omit(...fields: (string | string[])[]): this;
15
14
  pick(...fields: (string | string[])[]): this;
16
15
  include(...fields: (string | string[])[]): this;
16
+ protected _send(): Promise<Response>;
17
17
  }
@@ -1,24 +1,10 @@
1
1
  import request from 'supertest';
2
2
  import { OpraURL } from '@opra/url';
3
- import { BaseTester } from './base-tester.js';
4
- export class OpraEntityCreateTester extends BaseTester {
3
+ import { BaseOperationTester } from './base-operation-tester.js';
4
+ export class OpraEntityCreateTester extends BaseOperationTester {
5
5
  constructor(params) {
6
6
  super(params);
7
7
  }
8
- async send() {
9
- const url = new OpraURL(this._params.path);
10
- url.pathPrefix = this._params.prefix;
11
- if (this._params.options.include)
12
- url.searchParams.set('$include', this._params.options.include);
13
- if (this._params.options.pick)
14
- url.searchParams.set('$pick', this._params.options.pick);
15
- if (this._params.options.omit)
16
- url.searchParams.set('$omit', this._params.options.omit);
17
- const req = request(this._params.app);
18
- const test = req.post(url.toString());
19
- this._prepare(test);
20
- return test.send(this._params.data);
21
- }
22
8
  data(data) {
23
9
  this._params.data = data;
24
10
  return this;
@@ -35,4 +21,18 @@ export class OpraEntityCreateTester extends BaseTester {
35
21
  this._params.options.include = fields.flat();
36
22
  return this;
37
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
38
  }
@@ -1,18 +1,18 @@
1
1
  import { Response } from 'supertest';
2
2
  import { GetQueryOptions } from '@opra/core';
3
3
  import { ResourceKey } from '@opra/url';
4
- import { BaseTester } from './base-tester.js';
4
+ import { BaseOperationTester } from './base-operation-tester.js';
5
5
  import type { OpraEntityTesterParams } from './entity-tester';
6
6
  export declare type OpraEntityGetTesterParams = OpraEntityTesterParams & {
7
7
  keyValue: ResourceKey;
8
8
  options: GetQueryOptions;
9
9
  };
10
- export declare class OpraEntityGetTester extends BaseTester {
10
+ export declare class OpraEntityGetTester extends BaseOperationTester {
11
11
  protected readonly _params: OpraEntityGetTesterParams;
12
12
  constructor(params: OpraEntityGetTesterParams);
13
- send(): Promise<Response>;
14
13
  keyValue(value: ResourceKey): this;
15
14
  omit(...fields: (string | string[])[]): this;
16
15
  pick(...fields: (string | string[])[]): this;
17
16
  include(...fields: (string | string[])[]): this;
17
+ protected _send(): Promise<Response>;
18
18
  }
@@ -1,25 +1,10 @@
1
1
  import request from 'supertest';
2
2
  import { OpraURL } from '@opra/url';
3
- import { BaseTester } from './base-tester.js';
4
- export class OpraEntityGetTester extends BaseTester {
3
+ import { BaseOperationTester } from './base-operation-tester.js';
4
+ export class OpraEntityGetTester extends BaseOperationTester {
5
5
  constructor(params) {
6
6
  super(params);
7
7
  }
8
- async send() {
9
- const url = new OpraURL(this._params.path);
10
- url.pathPrefix = this._params.prefix;
11
- url.path.get(url.path.size - 1).key = this._params.keyValue;
12
- if (this._params.options.include)
13
- url.searchParams.set('$include', this._params.options.include);
14
- if (this._params.options.pick)
15
- url.searchParams.set('$pick', this._params.options.pick);
16
- if (this._params.options.omit)
17
- url.searchParams.set('$omit', this._params.options.omit);
18
- const req = request(this._params.app);
19
- const test = req.get(url.toString());
20
- this._prepare(test);
21
- return test.send();
22
- }
23
8
  keyValue(value) {
24
9
  this._params.keyValue = value;
25
10
  return this;
@@ -36,4 +21,19 @@ export class OpraEntityGetTester extends BaseTester {
36
21
  this._params.options.include = fields.flat();
37
22
  return this;
38
23
  }
24
+ async _send() {
25
+ const url = new OpraURL(this._params.path);
26
+ url.pathPrefix = this._params.prefix;
27
+ url.path.get(url.path.size - 1).key = this._params.keyValue;
28
+ if (this._params.options.include)
29
+ url.searchParams.set('$include', this._params.options.include);
30
+ if (this._params.options.pick)
31
+ url.searchParams.set('$pick', this._params.options.pick);
32
+ if (this._params.options.omit)
33
+ url.searchParams.set('$omit', this._params.options.omit);
34
+ const req = request(this._params.app);
35
+ const test = req.get(url.toString());
36
+ this._prepare(test);
37
+ return test.send();
38
+ }
39
39
  }
@@ -0,0 +1,22 @@
1
+ import { Response } from 'supertest';
2
+ import { SearchQueryOptions } from '@opra/core';
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: SearchQueryOptions;
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
+ }
@@ -0,0 +1,70 @@
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) {
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,14 +1,18 @@
1
- import { CreateQueryOptions, GetQueryOptions } from '@opra/core';
1
+ import { CreateQueryOptions, GetQueryOptions, UpdateQueryOptions } from '@opra/core';
2
2
  import { ResourceKey } from '@opra/url';
3
3
  import { BaseTester, OpraTesterParams } from './base-tester.js';
4
4
  import { OpraEntityCreateTester } from './entity-create-tester.js';
5
5
  import { OpraEntityGetTester } from './entity-get-tester.js';
6
+ import { OpraEntitySearchTester } from './entity-search-tester.js';
7
+ import { OpraEntityUpdateTester } from './entity-update-tester.js';
6
8
  export declare type OpraEntityTesterParams = OpraTesterParams & {
7
9
  path: string;
8
10
  };
9
11
  export declare class OpraEntityTester extends BaseTester {
10
12
  protected readonly _params: OpraEntityTesterParams;
11
13
  constructor(params: OpraEntityTesterParams);
12
- get(keyValue: ResourceKey, options?: GetQueryOptions): OpraEntityGetTester;
13
14
  create(data: {}, options?: CreateQueryOptions): OpraEntityCreateTester;
15
+ get(keyValue: ResourceKey, options?: GetQueryOptions): OpraEntityGetTester;
16
+ search(options?: GetQueryOptions): OpraEntitySearchTester;
17
+ update(keyValue: ResourceKey, data: {}, options?: UpdateQueryOptions): OpraEntityUpdateTester;
14
18
  }
@@ -1,10 +1,20 @@
1
1
  import { BaseTester } from './base-tester.js';
2
2
  import { OpraEntityCreateTester } from './entity-create-tester.js';
3
3
  import { OpraEntityGetTester } from './entity-get-tester.js';
4
+ import { OpraEntitySearchTester } from './entity-search-tester.js';
5
+ import { OpraEntityUpdateTester } from './entity-update-tester.js';
4
6
  export class OpraEntityTester extends BaseTester {
5
7
  constructor(params) {
6
8
  super(params);
7
9
  }
10
+ create(data, options = {}) {
11
+ return new OpraEntityCreateTester({
12
+ ...this._params,
13
+ headers: { ...this._params.headers },
14
+ data,
15
+ options
16
+ });
17
+ }
8
18
  get(keyValue, options = {}) {
9
19
  return new OpraEntityGetTester({
10
20
  ...this._params,
@@ -13,9 +23,17 @@ export class OpraEntityTester extends BaseTester {
13
23
  options
14
24
  });
15
25
  }
16
- create(data, options = {}) {
17
- return new OpraEntityCreateTester({
26
+ search(options = {}) {
27
+ return new OpraEntitySearchTester({
28
+ ...this._params,
29
+ headers: { ...this._params.headers },
30
+ options
31
+ });
32
+ }
33
+ update(keyValue, data, options = {}) {
34
+ return new OpraEntityUpdateTester({
18
35
  ...this._params,
36
+ keyValue,
19
37
  headers: { ...this._params.headers },
20
38
  data,
21
39
  options
@@ -0,0 +1,19 @@
1
+ import { Response } from 'supertest';
2
+ import { CreateQueryOptions } from '@opra/core';
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 OpraEntityCreateTesterParams = OpraEntityTesterParams & {
7
+ data: {};
8
+ keyValue: ResourceKey;
9
+ options: CreateQueryOptions;
10
+ };
11
+ export declare class OpraEntityUpdateTester extends BaseOperationTester {
12
+ protected readonly _params: OpraEntityCreateTesterParams;
13
+ constructor(params: OpraEntityCreateTesterParams);
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
+ }
@@ -0,0 +1,39 @@
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
+ }
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
+ url.path.get(url.path.size - 1).key = this._params.keyValue;
28
+ if (this._params.options.include)
29
+ url.searchParams.set('$include', this._params.options.include);
30
+ if (this._params.options.pick)
31
+ url.searchParams.set('$pick', this._params.options.pick);
32
+ if (this._params.options.omit)
33
+ url.searchParams.set('$omit', this._params.options.omit);
34
+ const req = request(this._params.app);
35
+ const test = req.post(url.toString());
36
+ this._prepare(test);
37
+ return test.send(this._params.data);
38
+ }
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/testing",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Opra testing package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,9 +25,10 @@
25
25
  "clean:cover": "rimraf ../../coverage/testing"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/core": "^0.0.9",
29
- "@opra/url": "^0.0.9",
28
+ "@opra/core": "^0.0.11",
29
+ "@opra/url": "^0.0.11",
30
30
  "lodash": "^4.17.21",
31
+ "rule-judgment": "^1.1.5",
31
32
  "supertest": "^6.2.4"
32
33
  },
33
34
  "devDependencies": {
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExpectErrors = void 0;
4
- const api_expect_body_js_1 = require("./api-expect-body.js");
5
- class ApiExpectErrors extends api_expect_body_js_1.ApiExpectBody {
6
- _body;
7
- constructor(_body) {
8
- super();
9
- this._body = _body;
10
- }
11
- toBeDefined() {
12
- expect(this._body.errors).toBeDefined();
13
- expect(this._body.errors.length).toBeGreaterThan(0);
14
- return this;
15
- }
16
- }
17
- exports.ApiExpectErrors = ApiExpectErrors;
@@ -1,6 +0,0 @@
1
- import { ApiExpectBody } from './api-expect-body.js';
2
- export declare class ApiExpectErrors extends ApiExpectBody {
3
- protected _body: any;
4
- constructor(_body: any);
5
- toBeDefined(): this;
6
- }
@@ -1,13 +0,0 @@
1
- import { ApiExpectBody } from './api-expect-body.js';
2
- export class ApiExpectErrors extends ApiExpectBody {
3
- _body;
4
- constructor(_body) {
5
- super();
6
- this._body = _body;
7
- }
8
- toBeDefined() {
9
- expect(this._body.errors).toBeDefined();
10
- expect(this._body.errors.length).toBeGreaterThan(0);
11
- return this;
12
- }
13
- }