@opra/testing 0.1.1 → 0.2.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.
- package/cjs/api-response.js +22 -0
- package/cjs/expect/api-expect-array.js +188 -0
- package/cjs/expect/api-expect-error.js +62 -0
- package/cjs/expect/api-expect-object.js +62 -17
- package/cjs/expect/api-expect-operation-result.js +43 -0
- package/cjs/expect/api-expect.js +84 -25
- package/cjs/expect/{jest-extend.js → jest-extend/common.extend.js} +58 -19
- package/cjs/expect/utils/object-matches.util.js +32 -0
- package/cjs/expect/utils/print-errors.util.js +15 -0
- package/cjs/index.js +1 -6
- package/cjs/testers/base-operation-tester.js +12 -4
- package/cjs/testers/entity-delete-many-tester.js +4 -0
- package/cjs/testers/entity-delete-tester.js +2 -0
- package/cjs/testers/entity-get-tester.js +2 -0
- package/cjs/testers/entity-search-tester.js +1 -1
- package/cjs/testers/entity-update-many-tester.js +4 -0
- package/cjs/testers/entity-update-tester.js +2 -0
- package/esm/api-response.d.ts +12 -0
- package/esm/api-response.js +18 -0
- package/esm/expect/api-expect-array.d.ts +17 -0
- package/esm/expect/api-expect-array.js +182 -0
- package/esm/expect/api-expect-error.d.ts +14 -0
- package/esm/expect/api-expect-error.js +57 -0
- package/esm/expect/api-expect-object.d.ts +11 -9
- package/esm/expect/api-expect-object.js +61 -17
- package/esm/expect/api-expect-operation-result.d.ts +9 -0
- package/esm/expect/api-expect-operation-result.js +39 -0
- package/esm/expect/api-expect.d.ts +12 -9
- package/esm/expect/api-expect.js +84 -25
- package/esm/expect/{jest-extend.d.ts → jest-extend/common.extend.d.ts} +7 -6
- package/esm/expect/{jest-extend.js → jest-extend/common.extend.js} +58 -19
- package/esm/expect/utils/object-matches.util.d.ts +1 -0
- package/esm/expect/utils/object-matches.util.js +28 -0
- package/esm/expect/utils/print-errors.util.d.ts +1 -0
- package/esm/expect/utils/print-errors.util.js +11 -0
- package/esm/index.d.ts +0 -3
- package/esm/index.js +0 -4
- package/esm/testers/base-operation-tester.d.ts +3 -7
- package/esm/testers/base-operation-tester.js +12 -4
- package/esm/testers/entity-create-tester.d.ts +2 -2
- package/esm/testers/entity-delete-many-tester.d.ts +4 -2
- package/esm/testers/entity-delete-many-tester.js +4 -0
- package/esm/testers/entity-delete-tester.d.ts +2 -2
- package/esm/testers/entity-delete-tester.js +2 -0
- package/esm/testers/entity-get-tester.d.ts +2 -2
- package/esm/testers/entity-get-tester.js +2 -0
- package/esm/testers/entity-search-tester.d.ts +3 -3
- package/esm/testers/entity-search-tester.js +1 -1
- package/esm/testers/entity-tester.d.ts +8 -8
- package/esm/testers/entity-update-many-tester.d.ts +4 -2
- package/esm/testers/entity-update-many-tester.js +4 -0
- package/esm/testers/entity-update-tester.d.ts +2 -2
- package/esm/testers/entity-update-tester.js +2 -0
- package/package.json +3 -3
- package/cjs/expect/api-expect-body.js +0 -37
- package/cjs/expect/api-expect-fail.js +0 -15
- package/cjs/expect/api-expect-list.js +0 -130
- package/esm/expect/api-expect-body.d.ts +0 -6
- package/esm/expect/api-expect-body.js +0 -32
- package/esm/expect/api-expect-fail.d.ts +0 -6
- package/esm/expect/api-expect-fail.js +0 -11
- package/esm/expect/api-expect-list.d.ts +0 -17
- package/esm/expect/api-expect-list.js +0 -124
package/cjs/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraTester = exports.
|
|
4
|
-
const api_expect_js_1 = require("./expect/api-expect.js");
|
|
3
|
+
exports.OpraTester = exports.opraTest = 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
6
|
function opraTest(app, options) {
|
|
@@ -13,10 +12,6 @@ function opraTest(app, options) {
|
|
|
13
12
|
});
|
|
14
13
|
}
|
|
15
14
|
exports.opraTest = opraTest;
|
|
16
|
-
function apiExpect(response) {
|
|
17
|
-
return new api_expect_js_1.ApiExpect(response);
|
|
18
|
-
}
|
|
19
|
-
exports.apiExpect = apiExpect;
|
|
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
|
|
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
|
|
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(
|
|
18
|
+
fn(apiResponse);
|
|
11
19
|
return;
|
|
12
20
|
}
|
|
13
|
-
return
|
|
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;
|
|
@@ -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,182 @@
|
|
|
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
|
+
for (const item of this.response.body) {
|
|
73
|
+
expect(item).toBeSortedBy(fields);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
Error.captureStackTrace(e, this.toBeSortedBy);
|
|
78
|
+
throw e;
|
|
79
|
+
}
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
toBeFilteredBy(filter) {
|
|
83
|
+
const f = convertFilter(filter);
|
|
84
|
+
if (f) {
|
|
85
|
+
const j = ruleJudgment(f);
|
|
86
|
+
const filtered = this.response.body.filter(j);
|
|
87
|
+
try {
|
|
88
|
+
expect(this.response.body).toStrictEqual(filtered);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
Error.captureStackTrace(e, this.toBeFilteredBy);
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
toHaveExactItems(expected) {
|
|
98
|
+
try {
|
|
99
|
+
expect(this.response.body).toHaveLength(expected);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
Error.captureStackTrace(e, this.toHaveExactItems);
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
toHaveMaxItems(expected) {
|
|
108
|
+
try {
|
|
109
|
+
expect(this.response.body.length).toBeLessThanOrEqual(expected);
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
Error.captureStackTrace(e, this.toHaveMaxItems);
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
toHaveMinItems(expected) {
|
|
118
|
+
try {
|
|
119
|
+
expect(this.response.body.length).toBeGreaterThanOrEqual(expected);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
Error.captureStackTrace(e, this.toHaveMinItems);
|
|
123
|
+
throw e;
|
|
124
|
+
}
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export function convertFilter(str) {
|
|
129
|
+
const ast = typeof str === 'string' ? $parse(str) : str;
|
|
130
|
+
if (!ast)
|
|
131
|
+
return;
|
|
132
|
+
if (ast instanceof ComparisonExpression) {
|
|
133
|
+
const left = convertFilter(ast.left);
|
|
134
|
+
const right = convertFilter(ast.right);
|
|
135
|
+
switch (ast.op) {
|
|
136
|
+
case '=':
|
|
137
|
+
return { $eq: { [left]: right } };
|
|
138
|
+
case '!=':
|
|
139
|
+
return { $ne: { [left]: right } };
|
|
140
|
+
case '>':
|
|
141
|
+
return { $gt: { [left]: right } };
|
|
142
|
+
case '>=':
|
|
143
|
+
return { $gte: { [left]: right } };
|
|
144
|
+
case '<':
|
|
145
|
+
return { $lt: { [left]: right } };
|
|
146
|
+
case '<=':
|
|
147
|
+
return { $lte: { [left]: right } };
|
|
148
|
+
case 'in':
|
|
149
|
+
return { $in: { [left]: right } };
|
|
150
|
+
case '!in':
|
|
151
|
+
return { $nin: { [left]: right } };
|
|
152
|
+
default:
|
|
153
|
+
throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (ast instanceof QualifiedIdentifier) {
|
|
157
|
+
return ast.value;
|
|
158
|
+
}
|
|
159
|
+
if (ast instanceof NumberLiteral ||
|
|
160
|
+
ast instanceof StringLiteral ||
|
|
161
|
+
ast instanceof BooleanLiteral ||
|
|
162
|
+
ast instanceof NullLiteral ||
|
|
163
|
+
ast instanceof DateLiteral ||
|
|
164
|
+
ast instanceof TimeLiteral) {
|
|
165
|
+
return ast.value;
|
|
166
|
+
}
|
|
167
|
+
if (ast instanceof ArrayExpression) {
|
|
168
|
+
return ast.items.map(convertFilter);
|
|
169
|
+
}
|
|
170
|
+
if (ast instanceof LogicalExpression) {
|
|
171
|
+
if (ast.op === 'or')
|
|
172
|
+
return { $or: ast.items.map(convertFilter) };
|
|
173
|
+
return { $and: ast.items.map(convertFilter) };
|
|
174
|
+
}
|
|
175
|
+
if (ast instanceof ArrayExpression) {
|
|
176
|
+
return ast.items.map(convertFilter);
|
|
177
|
+
}
|
|
178
|
+
if (ast instanceof ParenthesesExpression) {
|
|
179
|
+
return convertFilter(ast.expression);
|
|
180
|
+
}
|
|
181
|
+
throw new Error(`${ast.kind} is not implemented yet`);
|
|
182
|
+
}
|
|
@@ -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 {
|
|
2
|
-
export declare class ApiExpectObject
|
|
3
|
-
|
|
4
|
-
constructor(
|
|
5
|
-
|
|
6
|
-
toMatch<T extends {}>(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
2
|
-
export class ApiExpectObject
|
|
3
|
-
|
|
4
|
-
constructor(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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 {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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:
|
|
8
|
-
constructor(response:
|
|
8
|
+
readonly response: ApiResponse;
|
|
9
|
+
constructor(response: ApiResponse);
|
|
10
|
+
get body(): any;
|
|
9
11
|
toSuccess(status?: number): this;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
toFail(status?: number): ApiExpectError;
|
|
13
|
+
toReturnOperationResult(): ApiExpectOperationResult;
|
|
14
|
+
toReturnObject(): ApiExpectObject;
|
|
15
|
+
toReturnArray(): ApiExpectArray;
|
|
13
16
|
}
|