@opra/testing 0.0.9 → 0.0.12

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 (44) 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 → api-expect-object.js} +4 -4
  4. package/cjs/expect/api-expect.js +24 -19
  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-delete-many-tester.js +23 -0
  8. package/cjs/testers/entity-delete-tester.js +22 -0
  9. package/cjs/testers/entity-get-tester.js +17 -17
  10. package/cjs/testers/entity-search-tester.js +75 -0
  11. package/cjs/testers/entity-tester.js +46 -2
  12. package/cjs/testers/entity-update-many-tester.js +27 -0
  13. package/cjs/testers/entity-update-tester.js +44 -0
  14. package/esm/expect/api-expect-fail.d.ts +6 -0
  15. package/esm/expect/api-expect-fail.js +11 -0
  16. package/esm/expect/api-expect-list.d.ts +9 -2
  17. package/esm/expect/api-expect-list.js +101 -5
  18. package/esm/expect/{api-expect-resource.d.ts → api-expect-object.d.ts} +2 -2
  19. package/esm/expect/{api-expect-resource.js → api-expect-object.js} +2 -2
  20. package/esm/expect/api-expect.d.ts +6 -9
  21. package/esm/expect/api-expect.js +24 -19
  22. package/esm/testers/base-operation-tester.d.ts +12 -0
  23. package/esm/testers/base-operation-tester.js +12 -0
  24. package/esm/testers/base-tester.d.ts +1 -1
  25. package/esm/testers/entity-create-tester.d.ts +3 -3
  26. package/esm/testers/entity-create-tester.js +16 -16
  27. package/esm/testers/entity-delete-many-tester.d.ts +12 -0
  28. package/esm/testers/entity-delete-many-tester.js +18 -0
  29. package/esm/testers/entity-delete-tester.d.ts +14 -0
  30. package/esm/testers/entity-delete-tester.js +17 -0
  31. package/esm/testers/entity-get-tester.d.ts +3 -3
  32. package/esm/testers/entity-get-tester.js +17 -17
  33. package/esm/testers/entity-search-tester.d.ts +22 -0
  34. package/esm/testers/entity-search-tester.js +70 -0
  35. package/esm/testers/entity-tester.d.ts +12 -2
  36. package/esm/testers/entity-tester.js +46 -2
  37. package/esm/testers/entity-update-many-tester.d.ts +14 -0
  38. package/esm/testers/entity-update-many-tester.js +22 -0
  39. package/esm/testers/entity-update-tester.d.ts +19 -0
  40. package/esm/testers/entity-update-tester.js +39 -0
  41. package/package.json +4 -3
  42. package/cjs/expect/api-expect-errors.js +0 -17
  43. package/esm/expect/api-expect-errors.d.ts +0 -6
  44. 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;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiExpectResource = void 0;
3
+ exports.ApiExpectObject = void 0;
4
4
  const api_expect_body_js_1 = require("./api-expect-body.js");
5
- class ApiExpectResource extends api_expect_body_js_1.ApiExpectBody {
5
+ class ApiExpectObject extends api_expect_body_js_1.ApiExpectBody {
6
6
  _body;
7
7
  constructor(_body) {
8
8
  super();
@@ -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) {
@@ -28,4 +28,4 @@ class ApiExpectResource extends api_expect_body_js_1.ApiExpectBody {
28
28
  return this;
29
29
  }
30
30
  }
31
- exports.ApiExpectResource = ApiExpectResource;
31
+ exports.ApiExpectObject = ApiExpectObject;
@@ -1,37 +1,42 @@
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
- const api_expect_resource_js_1 = require("./api-expect-resource.js");
7
+ const api_expect_object_js_1 = require("./api-expect-object.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) {
14
+ expect(this.response.body.errors).toStrictEqual(undefined);
15
+ if (status)
16
+ expect(this.response.status).toEqual(status);
17
+ else {
18
+ expect(this.response.status).toBeGreaterThanOrEqual(200);
19
+ expect(this.response.status).toBeLessThan(300);
20
+ }
17
21
  return this;
18
22
  }
19
- get bodyAsResource() {
20
- return this._bodyResource =
21
- this._bodyResource || new api_expect_resource_js_1.ApiExpectResource(this.response.body);
23
+ toReturnObject(fn) {
24
+ expect(this.response.body).toBeDefined();
25
+ fn(new api_expect_object_js_1.ApiExpectObject(this.response.body));
26
+ return this;
22
27
  }
23
- get bodyAsList() {
24
- return this._bodyList =
25
- this._bodyList || new api_expect_list_js_1.ApiExpectList(this.response.body);
28
+ toReturnList(fn) {
29
+ expect(this.response.body).toBeDefined();
30
+ expect(this.response.body.items).toBeDefined();
31
+ fn(new api_expect_list_js_1.ApiExpectList(this.response.body));
32
+ return this;
26
33
  }
27
- toSuccess(status = 200) {
28
- expect(this.response.body.errors).toStrictEqual(undefined);
34
+ toFail(status = 400, fn) {
35
+ expect(this.response.body.errors).toBeDefined();
29
36
  expect(this.response.status).toEqual(status);
37
+ if (fn)
38
+ fn(new api_expect_fail_js_1.ApiExpectFail(this.response.body.errors));
30
39
  return this;
31
40
  }
32
- get errors() {
33
- return this._bodyErrors =
34
- this._bodyErrors || new api_expect_errors_js_1.ApiExpectErrors(this.response.body);
35
- }
36
41
  }
37
42
  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;
@@ -0,0 +1,23 @@
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
+ async _send() {
13
+ const url = new url_1.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 = (0, supertest_1.default)(this._params.app);
18
+ const test = req.delete(url.toString());
19
+ this._prepare(test);
20
+ return test.send();
21
+ }
22
+ }
23
+ exports.OpraEntityDeleteManyTester = OpraEntityDeleteManyTester;
@@ -0,0 +1,22 @@
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
+ }
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
+ const req = (0, supertest_1.default)(this._params.app);
17
+ const test = req.delete(url.toString());
18
+ this._prepare(test);
19
+ return test.send();
20
+ }
21
+ }
22
+ exports.OpraEntityDeleteTester = OpraEntityDeleteTester;
@@ -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;
@@ -3,11 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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
+ 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");
6
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");
7
12
  class OpraEntityTester extends base_tester_js_1.BaseTester {
8
13
  constructor(params) {
9
14
  super(params);
10
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
+ }
11
24
  get(keyValue, options = {}) {
12
25
  return new entity_get_tester_js_1.OpraEntityGetTester({
13
26
  ...this._params,
@@ -16,13 +29,44 @@ class OpraEntityTester extends base_tester_js_1.BaseTester {
16
29
  options
17
30
  });
18
31
  }
19
- create(data, options = {}) {
20
- return new entity_create_tester_js_1.OpraEntityCreateTester({
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({
21
41
  ...this._params,
42
+ keyValue,
22
43
  headers: { ...this._params.headers },
23
44
  data,
24
45
  options
25
46
  });
26
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
+ }
27
71
  }
28
72
  exports.OpraEntityTester = OpraEntityTester;
@@ -0,0 +1,27 @@
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
+ 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.patch(url.toString());
23
+ this._prepare(test);
24
+ return test.send(this._params.data);
25
+ }
26
+ }
27
+ exports.OpraEntityUpdateManyTester = OpraEntityUpdateManyTester;
@@ -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.patch(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;