@opra/testing 0.1.1 → 0.3.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 (63) hide show
  1. package/cjs/api-response.js +22 -0
  2. package/cjs/expect/api-expect-array.js +186 -0
  3. package/cjs/expect/api-expect-error.js +62 -0
  4. package/cjs/expect/api-expect-object.js +62 -17
  5. package/cjs/expect/api-expect-operation-result.js +43 -0
  6. package/cjs/expect/api-expect.js +84 -25
  7. package/cjs/expect/{jest-extend.js → jest-extend/common.extend.js} +60 -21
  8. package/cjs/expect/utils/object-matches.util.js +32 -0
  9. package/cjs/expect/utils/print-errors.util.js +15 -0
  10. package/cjs/index.js +3 -8
  11. package/cjs/testers/base-operation-tester.js +12 -4
  12. package/cjs/testers/entity-delete-many-tester.js +4 -0
  13. package/cjs/testers/entity-delete-tester.js +2 -0
  14. package/cjs/testers/entity-get-tester.js +2 -0
  15. package/cjs/testers/entity-search-tester.js +1 -1
  16. package/cjs/testers/entity-update-many-tester.js +4 -0
  17. package/cjs/testers/entity-update-tester.js +2 -0
  18. package/esm/api-response.d.ts +12 -0
  19. package/esm/api-response.js +18 -0
  20. package/esm/expect/api-expect-array.d.ts +17 -0
  21. package/esm/expect/api-expect-array.js +180 -0
  22. package/esm/expect/api-expect-error.d.ts +14 -0
  23. package/esm/expect/api-expect-error.js +57 -0
  24. package/esm/expect/api-expect-object.d.ts +11 -9
  25. package/esm/expect/api-expect-object.js +61 -17
  26. package/esm/expect/api-expect-operation-result.d.ts +9 -0
  27. package/esm/expect/api-expect-operation-result.js +39 -0
  28. package/esm/expect/api-expect.d.ts +12 -9
  29. package/esm/expect/api-expect.js +84 -25
  30. package/esm/expect/{jest-extend.d.ts → jest-extend/common.extend.d.ts} +7 -6
  31. package/esm/expect/{jest-extend.js → jest-extend/common.extend.js} +60 -21
  32. package/esm/expect/utils/object-matches.util.d.ts +1 -0
  33. package/esm/expect/utils/object-matches.util.js +28 -0
  34. package/esm/expect/utils/print-errors.util.d.ts +1 -0
  35. package/esm/expect/utils/print-errors.util.js +11 -0
  36. package/esm/index.d.ts +1 -4
  37. package/esm/index.js +1 -5
  38. package/esm/testers/base-operation-tester.d.ts +3 -7
  39. package/esm/testers/base-operation-tester.js +12 -4
  40. package/esm/testers/entity-create-tester.d.ts +2 -2
  41. package/esm/testers/entity-delete-many-tester.d.ts +4 -2
  42. package/esm/testers/entity-delete-many-tester.js +4 -0
  43. package/esm/testers/entity-delete-tester.d.ts +2 -2
  44. package/esm/testers/entity-delete-tester.js +2 -0
  45. package/esm/testers/entity-get-tester.d.ts +2 -2
  46. package/esm/testers/entity-get-tester.js +2 -0
  47. package/esm/testers/entity-search-tester.d.ts +3 -3
  48. package/esm/testers/entity-search-tester.js +1 -1
  49. package/esm/testers/entity-tester.d.ts +8 -8
  50. package/esm/testers/entity-update-many-tester.d.ts +4 -2
  51. package/esm/testers/entity-update-many-tester.js +4 -0
  52. package/esm/testers/entity-update-tester.d.ts +2 -2
  53. package/esm/testers/entity-update-tester.js +2 -0
  54. package/package.json +3 -3
  55. package/cjs/expect/api-expect-body.js +0 -37
  56. package/cjs/expect/api-expect-fail.js +0 -15
  57. package/cjs/expect/api-expect-list.js +0 -130
  58. package/esm/expect/api-expect-body.d.ts +0 -6
  59. package/esm/expect/api-expect-body.js +0 -32
  60. package/esm/expect/api-expect-fail.d.ts +0 -6
  61. package/esm/expect/api-expect-fail.js +0 -11
  62. package/esm/expect/api-expect-list.d.ts +0 -17
  63. package/esm/expect/api-expect-list.js +0 -124
@@ -0,0 +1,15 @@
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;
package/cjs/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraTester = exports.apiExpect = exports.opraTest = void 0;
4
- const api_expect_js_1 = require("./expect/api-expect.js");
3
+ exports.OpraTester = exports.opraTestClient = void 0;
5
4
  const base_tester_js_1 = require("./testers/base-tester.js");
6
5
  const entity_tester_js_1 = require("./testers/entity-tester.js");
7
- function opraTest(app, options) {
6
+ function opraTestClient(app, options) {
8
7
  return new OpraTester({
9
8
  app,
10
9
  ...options,
@@ -12,11 +11,7 @@ function opraTest(app, options) {
12
11
  headers: options?.headers || {}
13
12
  });
14
13
  }
15
- exports.opraTest = opraTest;
16
- function apiExpect(response) {
17
- return new api_expect_js_1.ApiExpect(response);
18
- }
19
- exports.apiExpect = apiExpect;
14
+ exports.opraTestClient = opraTestClient;
20
15
  class OpraTester extends base_tester_js_1.BaseTester {
21
16
  entity(path) {
22
17
  return new entity_tester_js_1.OpraEntityTester({
@@ -1,16 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseOperationTester = void 0;
4
- const api_expect_js_1 = require("../expect/api-expect.js");
4
+ const api_response_js_1 = require("../api-response.js");
5
5
  const base_tester_js_1 = require("./base-tester.js");
6
6
  class BaseOperationTester extends base_tester_js_1.BaseTester {
7
7
  async send(fn) {
8
- const resp = await this._send();
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
+ });
9
17
  if (fn) {
10
- fn(new api_expect_js_1.ApiExpect(resp));
18
+ fn(apiResponse);
11
19
  return;
12
20
  }
13
- return resp;
21
+ return apiResponse;
14
22
  }
15
23
  }
16
24
  exports.BaseOperationTester = BaseOperationTester;
@@ -9,6 +9,10 @@ class OpraEntityDeleteManyTester extends base_operation_tester_js_1.BaseOperatio
9
9
  constructor(params) {
10
10
  super(params);
11
11
  }
12
+ filter(value) {
13
+ this._params.options.filter = value;
14
+ return this;
15
+ }
12
16
  async _send() {
13
17
  const url = new url_1.OpraURL(this._params.path);
14
18
  url.pathPrefix = this._params.prefix;
@@ -8,6 +8,8 @@ const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
8
  class OpraEntityDeleteTester extends base_operation_tester_js_1.BaseOperationTester {
9
9
  constructor(params) {
10
10
  super(params);
11
+ if (!params.keyValue)
12
+ throw new Error(`You must provide "keyValue"`);
11
13
  }
12
14
  async _send() {
13
15
  const url = new url_1.OpraURL(this._params.path);
@@ -8,6 +8,8 @@ const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
8
  class OpraEntityGetTester extends base_operation_tester_js_1.BaseOperationTester {
9
9
  constructor(params) {
10
10
  super(params);
11
+ if (!params.keyValue)
12
+ throw new Error(`You must provide "keyValue"`);
11
13
  }
12
14
  keyValue(value) {
13
15
  this._params.keyValue = value;
@@ -17,7 +17,7 @@ class OpraEntitySearchTester extends base_operation_tester_js_1.BaseOperationTes
17
17
  this._params.options.skip = value;
18
18
  return this;
19
19
  }
20
- count(value) {
20
+ count(value = true) {
21
21
  this._params.options.count = value;
22
22
  return this;
23
23
  }
@@ -13,6 +13,10 @@ class OpraEntityUpdateManyTester extends base_operation_tester_js_1.BaseOperatio
13
13
  this._params.data = data;
14
14
  return this;
15
15
  }
16
+ filter(value) {
17
+ this._params.options.filter = value;
18
+ return this;
19
+ }
16
20
  async _send() {
17
21
  const url = new url_1.OpraURL(this._params.path);
18
22
  url.pathPrefix = this._params.prefix;
@@ -8,6 +8,8 @@ const base_operation_tester_js_1 = require("./base-operation-tester.js");
8
8
  class OpraEntityUpdateTester extends base_operation_tester_js_1.BaseOperationTester {
9
9
  constructor(params) {
10
10
  super(params);
11
+ if (!params.keyValue)
12
+ throw new Error(`You must provide "keyValue"`);
11
13
  }
12
14
  data(data) {
13
15
  this._params.data = data;
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,17 @@
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;
@@ -0,0 +1,180 @@
1
+ import _ from 'lodash';
2
+ import ruleJudgment from 'rule-judgment';
3
+ import { $parse, ArrayExpression, BooleanLiteral, ComparisonExpression, DateLiteral, LogicalExpression, NullLiteral, NumberLiteral, ParenthesesExpression, QualifiedIdentifier, StringLiteral, TimeLiteral } from '@opra/url';
4
+ export class ApiExpectArray {
5
+ response;
6
+ constructor(response) {
7
+ this.response = response;
8
+ }
9
+ toMatch(expected) {
10
+ try {
11
+ const v = _.omitBy(expected, _.isNil);
12
+ for (const item of this.response.body) {
13
+ expect(item).toMatchObject(v);
14
+ }
15
+ }
16
+ catch (e) {
17
+ Error.captureStackTrace(e, this.toMatch);
18
+ throw e;
19
+ }
20
+ return this;
21
+ }
22
+ toContainAllKeys(keys) {
23
+ try {
24
+ for (const item of this.response.body) {
25
+ expect(item).toContainAllKeys(keys);
26
+ }
27
+ }
28
+ catch (e) {
29
+ Error.captureStackTrace(e, this.toContainAllKeys);
30
+ throw e;
31
+ }
32
+ return this;
33
+ }
34
+ toContainKeys(keys) {
35
+ try {
36
+ for (const item of this.response.body) {
37
+ expect(item).toContainKeys(keys);
38
+ }
39
+ }
40
+ catch (e) {
41
+ Error.captureStackTrace(e, this.toContainKeys);
42
+ throw e;
43
+ }
44
+ return this;
45
+ }
46
+ notToContainKeys(keys) {
47
+ try {
48
+ for (const item of this.response.body) {
49
+ expect(item).not.toContainKeys(keys);
50
+ }
51
+ }
52
+ catch (e) {
53
+ Error.captureStackTrace(e, this.notToContainKeys);
54
+ throw e;
55
+ }
56
+ return this;
57
+ }
58
+ toHaveProperty(keyPath, value) {
59
+ try {
60
+ for (const item of this.response.body) {
61
+ expect(item).toHaveProperty(keyPath, value);
62
+ }
63
+ }
64
+ catch (e) {
65
+ Error.captureStackTrace(e, this.toHaveProperty);
66
+ throw e;
67
+ }
68
+ return this;
69
+ }
70
+ toBeSortedBy(...fields) {
71
+ try {
72
+ expect(this.response.body).toBeSortedBy(fields);
73
+ }
74
+ catch (e) {
75
+ Error.captureStackTrace(e, this.toBeSortedBy);
76
+ throw e;
77
+ }
78
+ return this;
79
+ }
80
+ toBeFilteredBy(filter) {
81
+ const f = convertFilter(filter);
82
+ if (f) {
83
+ const j = ruleJudgment(f);
84
+ const filtered = this.response.body.filter(j);
85
+ try {
86
+ expect(this.response.body).toStrictEqual(filtered);
87
+ }
88
+ catch (e) {
89
+ Error.captureStackTrace(e, this.toBeFilteredBy);
90
+ throw e;
91
+ }
92
+ }
93
+ return this;
94
+ }
95
+ toHaveExactItems(expected) {
96
+ try {
97
+ expect(this.response.body).toHaveLength(expected);
98
+ }
99
+ catch (e) {
100
+ Error.captureStackTrace(e, this.toHaveExactItems);
101
+ throw e;
102
+ }
103
+ return this;
104
+ }
105
+ toHaveMaxItems(expected) {
106
+ try {
107
+ expect(this.response.body.length).toBeLessThanOrEqual(expected);
108
+ }
109
+ catch (e) {
110
+ Error.captureStackTrace(e, this.toHaveMaxItems);
111
+ throw e;
112
+ }
113
+ return this;
114
+ }
115
+ toHaveMinItems(expected) {
116
+ try {
117
+ expect(this.response.body.length).toBeGreaterThanOrEqual(expected);
118
+ }
119
+ catch (e) {
120
+ Error.captureStackTrace(e, this.toHaveMinItems);
121
+ throw e;
122
+ }
123
+ return this;
124
+ }
125
+ }
126
+ export function convertFilter(str) {
127
+ const ast = typeof str === 'string' ? $parse(str) : str;
128
+ if (!ast)
129
+ return;
130
+ if (ast instanceof ComparisonExpression) {
131
+ const left = convertFilter(ast.left);
132
+ const right = convertFilter(ast.right);
133
+ switch (ast.op) {
134
+ case '=':
135
+ return { $eq: { [left]: right } };
136
+ case '!=':
137
+ return { $ne: { [left]: right } };
138
+ case '>':
139
+ return { $gt: { [left]: right } };
140
+ case '>=':
141
+ return { $gte: { [left]: right } };
142
+ case '<':
143
+ return { $lt: { [left]: right } };
144
+ case '<=':
145
+ return { $lte: { [left]: right } };
146
+ case 'in':
147
+ return { $in: { [left]: right } };
148
+ case '!in':
149
+ return { $nin: { [left]: right } };
150
+ default:
151
+ throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
152
+ }
153
+ }
154
+ if (ast instanceof QualifiedIdentifier) {
155
+ return ast.value;
156
+ }
157
+ if (ast instanceof NumberLiteral ||
158
+ ast instanceof StringLiteral ||
159
+ ast instanceof BooleanLiteral ||
160
+ ast instanceof NullLiteral ||
161
+ ast instanceof DateLiteral ||
162
+ ast instanceof TimeLiteral) {
163
+ return ast.value;
164
+ }
165
+ if (ast instanceof ArrayExpression) {
166
+ return ast.items.map(convertFilter);
167
+ }
168
+ if (ast instanceof LogicalExpression) {
169
+ if (ast.op === 'or')
170
+ return { $or: ast.items.map(convertFilter) };
171
+ return { $and: ast.items.map(convertFilter) };
172
+ }
173
+ if (ast instanceof ArrayExpression) {
174
+ return ast.items.map(convertFilter);
175
+ }
176
+ if (ast instanceof ParenthesesExpression) {
177
+ return convertFilter(ast.expression);
178
+ }
179
+ throw new Error(`${ast.kind} is not implemented yet`);
180
+ }
@@ -0,0 +1,14 @@
1
+ import type { ApiResponse } from '../api-response';
2
+ import { ApiExpectObject } from './api-expect-object.js';
3
+ export declare class ApiExpectError extends ApiExpectObject {
4
+ readonly response: ApiResponse;
5
+ constructor(response: ApiResponse);
6
+ toContainDetail(...matching: any[]): void;
7
+ }
8
+ declare global {
9
+ namespace jest {
10
+ interface Matchers<R> {
11
+ apiErrorDetailToContain(...issue: any[]): any;
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,57 @@
1
+ import matcherUtils from 'jest-matcher-utils';
2
+ import { ApiExpectObject } from './api-expect-object.js';
3
+ import { objectMatches } from './utils/object-matches.util.js';
4
+ export class ApiExpectError extends ApiExpectObject {
5
+ response;
6
+ constructor(response) {
7
+ super(response);
8
+ this.response = response;
9
+ }
10
+ toContainDetail(...matching) {
11
+ try {
12
+ expect(this.response.body['@@Schema']).toStrictEqual('Opra:Exception');
13
+ expect(this.response.body.issues).toBeDefined();
14
+ expect(this.response.body.issues).apiErrorDetailToContain(matching);
15
+ }
16
+ catch (e) {
17
+ Error.captureStackTrace(e, this.toContainDetail);
18
+ throw e;
19
+ }
20
+ }
21
+ }
22
+ expect.extend({
23
+ apiErrorDetailToContain(received, issues) {
24
+ try {
25
+ expect(typeof received).toStrictEqual('object');
26
+ expect(Array.isArray(received)).toStrictEqual(true);
27
+ }
28
+ catch (e) {
29
+ return {
30
+ pass: false,
31
+ message: () => e.message
32
+ };
33
+ }
34
+ for (const m of issues) {
35
+ let matched = false;
36
+ for (const detail of received) {
37
+ if (typeof m === 'object') {
38
+ try {
39
+ objectMatches(detail, m);
40
+ matched = true;
41
+ break;
42
+ }
43
+ catch {
44
+ //
45
+ }
46
+ }
47
+ }
48
+ if (!matched) {
49
+ return {
50
+ pass: false,
51
+ message: () => `Object does not match: \n` + matcherUtils.stringify(m)
52
+ };
53
+ }
54
+ }
55
+ return { actual: true, pass: true, message: () => '' };
56
+ },
57
+ });
@@ -1,10 +1,12 @@
1
- import { ApiExpectBody } from './api-expect-body.js';
2
- export declare class ApiExpectObject extends ApiExpectBody {
3
- protected _body: any;
4
- constructor(_body: any);
5
- toBeDefined(): this;
6
- toMatch<T extends {}>(value: T): this;
7
- haveKeysOnly(keys: string[]): this;
8
- haveKeys(keys: string[]): this;
9
- notHaveKeys(keys: string[]): this;
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;
10
12
  }
@@ -1,27 +1,71 @@
1
- import { ApiExpectBody } from './api-expect-body.js';
2
- export class ApiExpectObject extends ApiExpectBody {
3
- _body;
4
- constructor(_body) {
5
- super();
6
- this._body = _body;
7
- }
8
- toBeDefined() {
9
- expect(this._body).toBeDefined();
1
+ import _ from 'lodash';
2
+ export class ApiExpectObject {
3
+ response;
4
+ constructor(response) {
5
+ this.response = response;
6
+ }
7
+ get body() {
8
+ return this.response.body;
9
+ }
10
+ toMatch(expected) {
11
+ try {
12
+ const v = _.omitBy(expected, _.isNil);
13
+ expect(this.response.body).toMatchObject(v);
14
+ }
15
+ catch (e) {
16
+ Error.captureStackTrace(e, this.toMatch);
17
+ throw e;
18
+ }
10
19
  return this;
11
20
  }
12
- toMatch(value) {
13
- return this._toMatchObject([this._body], value);
21
+ toContainAllKeys(keys) {
22
+ try {
23
+ expect(this.response.body).toContainAllKeys(keys);
24
+ }
25
+ catch (e) {
26
+ Error.captureStackTrace(e, this.toContainAllKeys);
27
+ throw e;
28
+ }
29
+ return this;
30
+ }
31
+ toContainKeys(keys) {
32
+ try {
33
+ expect(this.response.body).toContainKeys(keys);
34
+ }
35
+ catch (e) {
36
+ Error.captureStackTrace(e, this.toContainKeys);
37
+ throw e;
38
+ }
39
+ return this;
14
40
  }
15
- haveKeysOnly(keys) {
16
- this._haveKeysOnly([this._body], keys);
41
+ notToContainKeys(keys) {
42
+ try {
43
+ expect(this.response.body).not.toContainKeys(keys);
44
+ }
45
+ catch (e) {
46
+ Error.captureStackTrace(e, this.notToContainKeys);
47
+ throw e;
48
+ }
17
49
  return this;
18
50
  }
19
- haveKeys(keys) {
20
- this._haveKeys([this._body], keys);
51
+ toHaveProperty(keyPath, value) {
52
+ try {
53
+ expect(this.response.body).toHaveProperty(keyPath, value);
54
+ }
55
+ catch (e) {
56
+ Error.captureStackTrace(e, this.toContainKeys);
57
+ throw e;
58
+ }
21
59
  return this;
22
60
  }
23
- notHaveKeys(keys) {
24
- this._notHaveKeys([this._body], keys);
61
+ notToHaveProperty(keyPath, value) {
62
+ try {
63
+ expect(this.response.body).not.toHaveProperty(keyPath, value);
64
+ }
65
+ catch (e) {
66
+ Error.captureStackTrace(e, this.toContainKeys);
67
+ throw e;
68
+ }
25
69
  return this;
26
70
  }
27
71
  }
@@ -0,0 +1,9 @@
1
+ import type { ApiResponse } from '../api-response';
2
+ export declare class ApiExpectOperationResult {
3
+ readonly response: ApiResponse;
4
+ constructor(response: ApiResponse);
5
+ get body(): any;
6
+ toBeAffectedExact(expected: number): this;
7
+ toBeAffectedMin(expected: number): this;
8
+ toBeAffectedMax(expected: number): this;
9
+ }
@@ -0,0 +1,39 @@
1
+ export class ApiExpectOperationResult {
2
+ response;
3
+ constructor(response) {
4
+ this.response = response;
5
+ }
6
+ get body() {
7
+ return this.response.body;
8
+ }
9
+ toBeAffectedExact(expected) {
10
+ try {
11
+ expect(this.response.body.affected).toStrictEqual(expected);
12
+ }
13
+ catch (e) {
14
+ Error.captureStackTrace(e, this.toBeAffectedExact);
15
+ throw e;
16
+ }
17
+ return this;
18
+ }
19
+ toBeAffectedMin(expected) {
20
+ try {
21
+ expect(this.response.body.affected).toBeGreaterThanOrEqual(expected);
22
+ }
23
+ catch (e) {
24
+ Error.captureStackTrace(e, this.toBeAffectedMin);
25
+ throw e;
26
+ }
27
+ return this;
28
+ }
29
+ toBeAffectedMax(expected) {
30
+ try {
31
+ expect(this.response.body.affected).toBeLessThanOrEqual(expected);
32
+ }
33
+ catch (e) {
34
+ Error.captureStackTrace(e, this.toBeAffectedMax);
35
+ throw e;
36
+ }
37
+ return this;
38
+ }
39
+ }
@@ -1,13 +1,16 @@
1
- import './jest-extend.js';
2
- import { Response } from 'supertest';
3
- import { ApiExpectFail } from './api-expect-fail.js';
4
- import { ApiExpectList } from './api-expect-list.js';
1
+ import './jest-extend/common.extend.js';
2
+ import type { ApiResponse } from '../api-response';
3
+ import { ApiExpectArray } from './api-expect-array.js';
4
+ import { ApiExpectError } from './api-expect-error.js';
5
5
  import { ApiExpectObject } from './api-expect-object.js';
6
+ import { ApiExpectOperationResult } from './api-expect-operation-result.js';
6
7
  export declare class ApiExpect {
7
- readonly response: Response;
8
- constructor(response: Response);
8
+ readonly response: ApiResponse;
9
+ constructor(response: ApiResponse);
10
+ get body(): any;
9
11
  toSuccess(status?: number): this;
10
- toReturnObject(fn: (body: ApiExpectObject) => void): this;
11
- toReturnList(fn: (body: ApiExpectList) => void): this;
12
- toFail(status?: number, fn?: (errors: ApiExpectFail) => void): this;
12
+ toFail(status?: number): ApiExpectError;
13
+ toReturnOperationResult(): ApiExpectOperationResult;
14
+ toReturnObject(): ApiExpectObject;
15
+ toReturnArray(): ApiExpectArray;
13
16
  }