@opra/testing 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/{expect/api-expect-array.js → api-expect/api-expect-collection.js} +48 -46
- package/cjs/{expect → api-expect}/api-expect-error.js +3 -4
- package/cjs/api-expect/api-expect-object.js +54 -0
- package/cjs/{expect → api-expect}/api-expect-operation-result.js +14 -6
- package/cjs/{expect → api-expect}/api-expect.js +30 -23
- package/cjs/constants.js +4 -0
- package/cjs/index.js +3 -22
- package/cjs/{expect/jest-extend → jest-extend}/common.extend.js +27 -26
- package/cjs/test-client.js +32 -0
- package/cjs/{expect/utils → utils}/object-matches.util.js +0 -0
- package/esm/api-expect/api-expect-collection.d.ts +19 -0
- package/esm/{expect/api-expect-array.js → api-expect/api-expect-collection.js} +46 -44
- package/esm/{expect → api-expect}/api-expect-error.d.ts +3 -3
- package/esm/{expect → api-expect}/api-expect-error.js +3 -4
- package/esm/api-expect/api-expect-object.d.ts +11 -0
- package/esm/api-expect/api-expect-object.js +49 -0
- package/esm/api-expect/api-expect-operation-result.d.ts +11 -0
- package/esm/{expect → api-expect}/api-expect-operation-result.js +14 -6
- package/esm/{expect → api-expect}/api-expect.d.ts +8 -7
- package/esm/{expect → api-expect}/api-expect.js +30 -23
- package/esm/constants.d.ts +1 -0
- package/esm/constants.js +1 -0
- package/esm/index.d.ts +2 -6
- package/esm/index.js +2 -19
- package/esm/{expect/jest-extend → jest-extend}/common.extend.d.ts +2 -2
- package/esm/{expect/jest-extend → jest-extend}/common.extend.js +26 -26
- package/esm/test-client.d.ts +18 -0
- package/esm/test-client.js +27 -0
- package/esm/{expect/utils → utils}/object-matches.util.d.ts +0 -0
- package/esm/{expect/utils → utils}/object-matches.util.js +0 -0
- package/package.json +6 -4
- package/cjs/api-response.js +0 -22
- package/cjs/expect/api-expect-object.js +0 -76
- package/cjs/expect/utils/print-errors.util.js +0 -15
- package/cjs/testers/base-operation-tester.js +0 -24
- package/cjs/testers/base-tester.js +0 -23
- package/cjs/testers/entity-create-tester.js +0 -43
- package/cjs/testers/entity-delete-many-tester.js +0 -27
- package/cjs/testers/entity-delete-tester.js +0 -24
- package/cjs/testers/entity-get-tester.js +0 -46
- package/cjs/testers/entity-search-tester.js +0 -75
- package/cjs/testers/entity-tester.js +0 -72
- package/cjs/testers/entity-update-many-tester.js +0 -31
- package/cjs/testers/entity-update-tester.js +0 -46
- package/esm/api-response.d.ts +0 -12
- package/esm/api-response.js +0 -18
- package/esm/expect/api-expect-array.d.ts +0 -17
- package/esm/expect/api-expect-object.d.ts +0 -12
- package/esm/expect/api-expect-object.js +0 -71
- package/esm/expect/api-expect-operation-result.d.ts +0 -9
- package/esm/expect/utils/print-errors.util.d.ts +0 -1
- package/esm/expect/utils/print-errors.util.js +0 -11
- package/esm/testers/base-operation-tester.d.ts +0 -8
- package/esm/testers/base-operation-tester.js +0 -20
- package/esm/testers/base-tester.d.ts +0 -13
- package/esm/testers/base-tester.js +0 -19
- package/esm/testers/entity-create-tester.d.ts +0 -17
- package/esm/testers/entity-create-tester.js +0 -38
- package/esm/testers/entity-delete-many-tester.d.ts +0 -14
- package/esm/testers/entity-delete-many-tester.js +0 -22
- package/esm/testers/entity-delete-tester.d.ts +0 -14
- package/esm/testers/entity-delete-tester.js +0 -19
- package/esm/testers/entity-get-tester.d.ts +0 -18
- package/esm/testers/entity-get-tester.js +0 -41
- package/esm/testers/entity-search-tester.d.ts +0 -22
- package/esm/testers/entity-search-tester.js +0 -70
- package/esm/testers/entity-tester.d.ts +0 -24
- package/esm/testers/entity-tester.js +0 -68
- package/esm/testers/entity-update-many-tester.d.ts +0 -16
- package/esm/testers/entity-update-many-tester.js +0 -26
- package/esm/testers/entity-update-tester.d.ts +0 -19
- package/esm/testers/entity-update-tester.js +0 -41
|
@@ -1,81 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertFilter = exports.
|
|
3
|
+
exports.convertFilter = exports.ApiExpectCollection = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
6
|
const rule_judgment_1 = tslib_1.__importDefault(require("rule-judgment"));
|
|
7
7
|
const url_1 = require("@opra/url");
|
|
8
|
-
class
|
|
8
|
+
class ApiExpectCollection {
|
|
9
9
|
response;
|
|
10
|
-
|
|
10
|
+
_isNot;
|
|
11
|
+
constructor(response, _isNot = false) {
|
|
11
12
|
this.response = response;
|
|
13
|
+
this._isNot = _isNot;
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const v = lodash_1.default.omitBy(expected, lodash_1.default.isNil);
|
|
16
|
-
for (const item of this.response.body) {
|
|
17
|
-
expect(item).toMatchObject(v);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
Error.captureStackTrace(e, this.toMatch);
|
|
22
|
-
throw e;
|
|
23
|
-
}
|
|
24
|
-
return this;
|
|
15
|
+
get not() {
|
|
16
|
+
return new ApiExpectCollection(this.response, !this._isNot);
|
|
25
17
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (const item of this.response.body) {
|
|
29
|
-
expect(item).toContainAllKeys(keys);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
Error.captureStackTrace(e, this.toContainAllKeys);
|
|
34
|
-
throw e;
|
|
35
|
-
}
|
|
18
|
+
forEach(callbackfn) {
|
|
19
|
+
this.response.data.forEach(callbackfn);
|
|
36
20
|
return this;
|
|
37
21
|
}
|
|
38
|
-
|
|
22
|
+
toMatch(expected) {
|
|
39
23
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
const v = lodash_1.default.omitBy(expected, lodash_1.default.isNil);
|
|
25
|
+
for (const item of this.response.data) {
|
|
26
|
+
this._expect(item).toMatchObject(v);
|
|
42
27
|
}
|
|
43
28
|
}
|
|
44
29
|
catch (e) {
|
|
45
|
-
Error.captureStackTrace(e, this.
|
|
30
|
+
Error.captureStackTrace(e, this.toMatch);
|
|
46
31
|
throw e;
|
|
47
32
|
}
|
|
48
33
|
return this;
|
|
49
34
|
}
|
|
50
|
-
|
|
35
|
+
toHaveFields(keys) {
|
|
51
36
|
try {
|
|
52
|
-
for (const item of this.response.
|
|
53
|
-
|
|
37
|
+
for (const item of this.response.data) {
|
|
38
|
+
this._expect(item).toHaveFields(keys);
|
|
54
39
|
}
|
|
55
40
|
}
|
|
56
41
|
catch (e) {
|
|
57
|
-
Error.captureStackTrace(e, this.
|
|
42
|
+
Error.captureStackTrace(e, this.toHaveFields);
|
|
58
43
|
throw e;
|
|
59
44
|
}
|
|
60
45
|
return this;
|
|
61
46
|
}
|
|
62
|
-
|
|
47
|
+
toHaveFieldsOnly(keys) {
|
|
63
48
|
try {
|
|
64
|
-
for (const item of this.response.
|
|
65
|
-
|
|
49
|
+
for (const item of this.response.data) {
|
|
50
|
+
this._expect(item).toHaveFieldsOnly(keys);
|
|
66
51
|
}
|
|
67
52
|
}
|
|
68
53
|
catch (e) {
|
|
69
|
-
Error.captureStackTrace(e, this.
|
|
54
|
+
Error.captureStackTrace(e, this.toHaveFieldsOnly);
|
|
70
55
|
throw e;
|
|
71
56
|
}
|
|
72
57
|
return this;
|
|
73
58
|
}
|
|
59
|
+
//
|
|
60
|
+
// toHaveProperty(keyPath, value?): this {
|
|
61
|
+
// try {
|
|
62
|
+
// for (const item of this.response.data) {
|
|
63
|
+
// this._expect(item).toHaveProperty(keyPath, value);
|
|
64
|
+
// }
|
|
65
|
+
//
|
|
66
|
+
// } catch (e: any) {
|
|
67
|
+
// Error.captureStackTrace(e, this.toHaveProperty);
|
|
68
|
+
// throw e;
|
|
69
|
+
// }
|
|
70
|
+
// return this;
|
|
71
|
+
// }
|
|
74
72
|
toBeSortedBy(...fields) {
|
|
75
73
|
try {
|
|
76
|
-
|
|
77
|
-
expect(item).toBeSortedBy(fields);
|
|
78
|
-
}
|
|
74
|
+
this._expect(this.response.data).toBeSortedBy(fields);
|
|
79
75
|
}
|
|
80
76
|
catch (e) {
|
|
81
77
|
Error.captureStackTrace(e, this.toBeSortedBy);
|
|
@@ -87,9 +83,9 @@ class ApiExpectArray {
|
|
|
87
83
|
const f = convertFilter(filter);
|
|
88
84
|
if (f) {
|
|
89
85
|
const j = (0, rule_judgment_1.default)(f);
|
|
90
|
-
const filtered = this.response.
|
|
86
|
+
const filtered = this.response.data.filter(j);
|
|
91
87
|
try {
|
|
92
|
-
|
|
88
|
+
this._expect(this.response.data).toStrictEqual(filtered);
|
|
93
89
|
}
|
|
94
90
|
catch (e) {
|
|
95
91
|
Error.captureStackTrace(e, this.toBeFilteredBy);
|
|
@@ -100,7 +96,7 @@ class ApiExpectArray {
|
|
|
100
96
|
}
|
|
101
97
|
toHaveExactItems(expected) {
|
|
102
98
|
try {
|
|
103
|
-
|
|
99
|
+
this._expect(this.response.data).toHaveLength(expected);
|
|
104
100
|
}
|
|
105
101
|
catch (e) {
|
|
106
102
|
Error.captureStackTrace(e, this.toHaveExactItems);
|
|
@@ -110,7 +106,7 @@ class ApiExpectArray {
|
|
|
110
106
|
}
|
|
111
107
|
toHaveMaxItems(expected) {
|
|
112
108
|
try {
|
|
113
|
-
|
|
109
|
+
this._expect(this.response.data.length).toBeLessThanOrEqual(expected);
|
|
114
110
|
}
|
|
115
111
|
catch (e) {
|
|
116
112
|
Error.captureStackTrace(e, this.toHaveMaxItems);
|
|
@@ -120,7 +116,7 @@ class ApiExpectArray {
|
|
|
120
116
|
}
|
|
121
117
|
toHaveMinItems(expected) {
|
|
122
118
|
try {
|
|
123
|
-
|
|
119
|
+
this._expect(this.response.data.length).toBeGreaterThanOrEqual(expected);
|
|
124
120
|
}
|
|
125
121
|
catch (e) {
|
|
126
122
|
Error.captureStackTrace(e, this.toHaveMinItems);
|
|
@@ -128,8 +124,14 @@ class ApiExpectArray {
|
|
|
128
124
|
}
|
|
129
125
|
return this;
|
|
130
126
|
}
|
|
127
|
+
_expect(expected) {
|
|
128
|
+
const out = expect(expected);
|
|
129
|
+
if (this._isNot)
|
|
130
|
+
return out.not;
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
131
133
|
}
|
|
132
|
-
exports.
|
|
134
|
+
exports.ApiExpectCollection = ApiExpectCollection;
|
|
133
135
|
function convertFilter(str) {
|
|
134
136
|
const ast = typeof str === 'string' ? (0, url_1.$parse)(str) : str;
|
|
135
137
|
if (!ast)
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ApiExpectError = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const jest_matcher_utils_1 = tslib_1.__importDefault(require("jest-matcher-utils"));
|
|
6
|
+
const object_matches_util_js_1 = require("../utils/object-matches.util.js");
|
|
6
7
|
const api_expect_object_js_1 = require("./api-expect-object.js");
|
|
7
|
-
const object_matches_util_js_1 = require("./utils/object-matches.util.js");
|
|
8
8
|
class ApiExpectError extends api_expect_object_js_1.ApiExpectObject {
|
|
9
9
|
response;
|
|
10
10
|
constructor(response) {
|
|
@@ -13,9 +13,8 @@ class ApiExpectError extends api_expect_object_js_1.ApiExpectObject {
|
|
|
13
13
|
}
|
|
14
14
|
toContainDetail(...matching) {
|
|
15
15
|
try {
|
|
16
|
-
expect(this.response.
|
|
17
|
-
expect(this.response.
|
|
18
|
-
expect(this.response.body.issues).apiErrorDetailToContain(matching);
|
|
16
|
+
expect(this.response.data.issues).toBeDefined();
|
|
17
|
+
expect(this.response.data.issues).apiErrorDetailToContain(matching);
|
|
19
18
|
}
|
|
20
19
|
catch (e) {
|
|
21
20
|
Error.captureStackTrace(e, this.toContainDetail);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExpectObject = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
+
class ApiExpectObject {
|
|
7
|
+
response;
|
|
8
|
+
_isNot;
|
|
9
|
+
constructor(response, _isNot = false) {
|
|
10
|
+
this.response = response;
|
|
11
|
+
this._isNot = _isNot;
|
|
12
|
+
}
|
|
13
|
+
get not() {
|
|
14
|
+
return new ApiExpectObject(this.response, !this._isNot);
|
|
15
|
+
}
|
|
16
|
+
toMatch(expected) {
|
|
17
|
+
try {
|
|
18
|
+
const v = lodash_1.default.omitBy(expected, lodash_1.default.isNil);
|
|
19
|
+
this._expect(this.response.data).toMatchObject(v);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
Error.captureStackTrace(e, this.toMatch);
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
toHaveFields(fields) {
|
|
28
|
+
try {
|
|
29
|
+
this._expect(this.response.data).toHaveFields(fields);
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
Error.captureStackTrace(e, this.toHaveFields);
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
toHaveFieldsOnly(fields) {
|
|
38
|
+
try {
|
|
39
|
+
this._expect(this.response.data).toHaveFieldsOnly(fields);
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
Error.captureStackTrace(e, this.toHaveFieldsOnly);
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
_expect(expected) {
|
|
48
|
+
const out = expect(expected);
|
|
49
|
+
if (this._isNot)
|
|
50
|
+
return out.not;
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.ApiExpectObject = ApiExpectObject;
|
|
@@ -3,15 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ApiExpectOperationResult = void 0;
|
|
4
4
|
class ApiExpectOperationResult {
|
|
5
5
|
response;
|
|
6
|
-
|
|
6
|
+
_isNot;
|
|
7
|
+
constructor(response, _isNot = false) {
|
|
7
8
|
this.response = response;
|
|
9
|
+
this._isNot = _isNot;
|
|
8
10
|
}
|
|
9
|
-
get
|
|
10
|
-
return this.response.
|
|
11
|
+
get not() {
|
|
12
|
+
return new ApiExpectOperationResult(this.response, !this._isNot);
|
|
11
13
|
}
|
|
12
14
|
toBeAffectedExact(expected) {
|
|
13
15
|
try {
|
|
14
|
-
|
|
16
|
+
this._expect(this.response.data.affected).toStrictEqual(expected);
|
|
15
17
|
}
|
|
16
18
|
catch (e) {
|
|
17
19
|
Error.captureStackTrace(e, this.toBeAffectedExact);
|
|
@@ -21,7 +23,7 @@ class ApiExpectOperationResult {
|
|
|
21
23
|
}
|
|
22
24
|
toBeAffectedMin(expected) {
|
|
23
25
|
try {
|
|
24
|
-
|
|
26
|
+
this._expect(this.response.data.affected).toBeGreaterThanOrEqual(expected);
|
|
25
27
|
}
|
|
26
28
|
catch (e) {
|
|
27
29
|
Error.captureStackTrace(e, this.toBeAffectedMin);
|
|
@@ -31,7 +33,7 @@ class ApiExpectOperationResult {
|
|
|
31
33
|
}
|
|
32
34
|
toBeAffectedMax(expected) {
|
|
33
35
|
try {
|
|
34
|
-
|
|
36
|
+
this._expect(this.response.data.affected).toBeLessThanOrEqual(expected);
|
|
35
37
|
}
|
|
36
38
|
catch (e) {
|
|
37
39
|
Error.captureStackTrace(e, this.toBeAffectedMax);
|
|
@@ -39,5 +41,11 @@ class ApiExpectOperationResult {
|
|
|
39
41
|
}
|
|
40
42
|
return this;
|
|
41
43
|
}
|
|
44
|
+
_expect(expected) {
|
|
45
|
+
const out = expect(expected);
|
|
46
|
+
if (this._isNot)
|
|
47
|
+
return out.not;
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
42
50
|
}
|
|
43
51
|
exports.ApiExpectOperationResult = ApiExpectOperationResult;
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiExpect = void 0;
|
|
4
|
-
require("./
|
|
5
|
-
const api_expect_array_js_1 = require("./api-expect-array.js");
|
|
4
|
+
const api_expect_collection_js_1 = require("./api-expect-collection.js");
|
|
6
5
|
const api_expect_error_js_1 = require("./api-expect-error.js");
|
|
7
6
|
const api_expect_object_js_1 = require("./api-expect-object.js");
|
|
8
7
|
const api_expect_operation_result_js_1 = require("./api-expect-operation-result.js");
|
|
9
8
|
class ApiExpect {
|
|
10
9
|
response;
|
|
11
|
-
|
|
10
|
+
_isNot;
|
|
11
|
+
constructor(response, _isNot = false) {
|
|
12
12
|
this.response = response;
|
|
13
|
+
this._isNot = _isNot;
|
|
13
14
|
}
|
|
14
|
-
get
|
|
15
|
-
return this.response.
|
|
15
|
+
get not() {
|
|
16
|
+
return new ApiExpect(this.response, !this._isNot);
|
|
16
17
|
}
|
|
17
18
|
toSuccess(status = 200) {
|
|
18
|
-
let msg = '
|
|
19
|
+
let msg = '';
|
|
19
20
|
try {
|
|
20
|
-
msg = '
|
|
21
|
-
|
|
21
|
+
msg = 'Unexpected "status" returned';
|
|
22
|
+
this._expect(this.response.status).toStrictEqual(status);
|
|
22
23
|
}
|
|
23
24
|
catch (e) {
|
|
24
25
|
if (msg)
|
|
@@ -29,7 +30,7 @@ class ApiExpect {
|
|
|
29
30
|
return this;
|
|
30
31
|
}
|
|
31
32
|
toFail(status = 400) {
|
|
32
|
-
let msg = '
|
|
33
|
+
let msg = '';
|
|
33
34
|
try {
|
|
34
35
|
msg = 'Response "status" does not match';
|
|
35
36
|
if (status) {
|
|
@@ -40,8 +41,8 @@ class ApiExpect {
|
|
|
40
41
|
expect(this.response.status).toBeLessThanOrEqual(599);
|
|
41
42
|
}
|
|
42
43
|
msg = 'Api did not returned "errors"';
|
|
43
|
-
expect(this.response.
|
|
44
|
-
expect(this.response.
|
|
44
|
+
expect(this.response.data.errors).toBeArray();
|
|
45
|
+
expect(this.response.data.errors.length).toBeGreaterThan(0);
|
|
45
46
|
}
|
|
46
47
|
catch (e) {
|
|
47
48
|
if (msg)
|
|
@@ -52,26 +53,26 @@ class ApiExpect {
|
|
|
52
53
|
return new api_expect_error_js_1.ApiExpectError(this.response);
|
|
53
54
|
}
|
|
54
55
|
toReturnOperationResult() {
|
|
55
|
-
let msg = '
|
|
56
|
+
let msg = '';
|
|
56
57
|
try {
|
|
57
58
|
msg = '"body" is empty';
|
|
58
|
-
expect(this.response.
|
|
59
|
+
expect(this.response.data).toBeDefined();
|
|
59
60
|
msg = '"operation" property is empty';
|
|
60
|
-
expect(this.response.
|
|
61
|
+
expect(this.response.data.operation).toBeDefined();
|
|
61
62
|
}
|
|
62
63
|
catch (e) {
|
|
63
64
|
if (msg)
|
|
64
65
|
e.message = msg + '\n\n' + e.message;
|
|
65
|
-
Error.captureStackTrace(e, this.
|
|
66
|
+
Error.captureStackTrace(e, this.toReturnOperationResult);
|
|
66
67
|
throw e;
|
|
67
68
|
}
|
|
68
69
|
return new api_expect_operation_result_js_1.ApiExpectOperationResult(this.response);
|
|
69
70
|
}
|
|
70
71
|
toReturnObject() {
|
|
71
|
-
let msg = '
|
|
72
|
+
let msg = '';
|
|
72
73
|
try {
|
|
73
74
|
msg = '"body" is empty';
|
|
74
|
-
expect(this.response.
|
|
75
|
+
expect(this.response.data).toBeDefined();
|
|
75
76
|
}
|
|
76
77
|
catch (e) {
|
|
77
78
|
if (msg)
|
|
@@ -81,21 +82,27 @@ class ApiExpect {
|
|
|
81
82
|
}
|
|
82
83
|
return new api_expect_object_js_1.ApiExpectObject(this.response);
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
-
let msg = '
|
|
85
|
+
toReturnCollection() {
|
|
86
|
+
let msg = '';
|
|
86
87
|
try {
|
|
87
88
|
msg = '"body" is empty';
|
|
88
|
-
expect(this.response.
|
|
89
|
+
expect(this.response.data).toBeDefined();
|
|
89
90
|
msg = '"body" is not an array';
|
|
90
|
-
expect(this.response.
|
|
91
|
+
expect(this.response.data).toBeArray();
|
|
91
92
|
}
|
|
92
93
|
catch (e) {
|
|
93
94
|
if (msg)
|
|
94
95
|
e.message = msg + '\n\n' + e.message;
|
|
95
|
-
Error.captureStackTrace(e, this.
|
|
96
|
+
Error.captureStackTrace(e, this.toReturnCollection);
|
|
96
97
|
throw e;
|
|
97
98
|
}
|
|
98
|
-
return new
|
|
99
|
+
return new api_expect_collection_js_1.ApiExpectCollection(this.response);
|
|
100
|
+
}
|
|
101
|
+
_expect(expected) {
|
|
102
|
+
const out = expect(expected);
|
|
103
|
+
if (this._isNot)
|
|
104
|
+
return out.not;
|
|
105
|
+
return out;
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
exports.ApiExpect = ApiExpect;
|
package/cjs/constants.js
ADDED
package/cjs/index.js
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function opraTest(app, options) {
|
|
7
|
-
return new OpraTester({
|
|
8
|
-
app,
|
|
9
|
-
...options,
|
|
10
|
-
prefix: options?.prefix || '',
|
|
11
|
-
headers: options?.headers || {}
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
exports.opraTest = opraTest;
|
|
15
|
-
class OpraTester extends base_tester_js_1.BaseTester {
|
|
16
|
-
entity(path) {
|
|
17
|
-
return new entity_tester_js_1.OpraEntityTester({
|
|
18
|
-
...this._params,
|
|
19
|
-
headers: { ...this._params.headers },
|
|
20
|
-
path
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.OpraTester = OpraTester;
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
require("./jest-extend/common.extend.js");
|
|
5
|
+
tslib_1.__exportStar(require("./test-client.js"), exports);
|
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
|
|
3
5
|
const jest_matcher_utils_1 = require("jest-matcher-utils");
|
|
4
6
|
expect.extend({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
7
|
+
toHaveFields(received, expected) {
|
|
8
|
+
const expectedKeys = (Array.isArray(expected) ? expected : Object.keys(expected)).map(x => x.toLowerCase());
|
|
9
|
+
const objectKeys = Object.keys(received).map(x => x.toLowerCase());
|
|
10
|
+
const filteredKeys = expectedKeys.filter(x => !objectKeys.includes(x));
|
|
11
|
+
const pass = !filteredKeys.length === !this.isNot;
|
|
12
|
+
if (!pass) {
|
|
13
|
+
const message = () => `Expects keys to${this.isNot ? ' not' : ''} contain: ${ansi_colors_1.default.yellow('' + expectedKeys)}\n` +
|
|
14
|
+
`${this.isNot ? 'Unsolicited' : 'Missing'} fields: ${ansi_colors_1.default.yellow('' + filteredKeys)}\n`;
|
|
15
|
+
return { message, pass: !!this.isNot };
|
|
15
16
|
}
|
|
16
|
-
return { actual: received, pass:
|
|
17
|
+
return { actual: received, pass: !this.isNot, message: () => '' };
|
|
17
18
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
19
|
+
toHaveFieldsOnly(received, expected) {
|
|
20
|
+
const expectedKeys = (Array.isArray(expected) ? expected : Object.keys(expected)).map(x => x.toLowerCase());
|
|
21
|
+
const objectKeys = Object.keys(received).map(x => x.toLowerCase());
|
|
22
|
+
const filteredKeys = objectKeys.filter(x => !expectedKeys.includes(x));
|
|
23
|
+
const pass = !filteredKeys.length === !this.isNot;
|
|
24
|
+
if (!pass) {
|
|
25
|
+
const message = () => `${!this.isNot ? 'Do not expects' : 'Expects'} additional keys other than: ${ansi_colors_1.default.yellow('' + expectedKeys)}\n` +
|
|
26
|
+
(filteredKeys ? `Additional keys received: ${ansi_colors_1.default.yellow('' + filteredKeys)}\n` :
|
|
27
|
+
'No additional keys received\n');
|
|
28
|
+
return { message, pass };
|
|
28
29
|
}
|
|
29
|
-
return { actual: received, pass:
|
|
30
|
+
return { actual: received, pass: !this.isNot, message: () => '' };
|
|
30
31
|
},
|
|
31
32
|
toBeArray(received) {
|
|
32
33
|
if (Array.isArray(received)) {
|
|
@@ -38,10 +39,10 @@ expect.extend({
|
|
|
38
39
|
};
|
|
39
40
|
},
|
|
40
41
|
toBeSorted(received, compareFn) {
|
|
41
|
-
let pass =
|
|
42
|
+
let pass = true;
|
|
42
43
|
let message;
|
|
43
44
|
if (pass) {
|
|
44
|
-
const sorted = [...received];
|
|
45
|
+
const sorted = [...(received || [])];
|
|
45
46
|
sorted.sort(compareFn);
|
|
46
47
|
try {
|
|
47
48
|
expect(received).toEqual(sorted);
|
|
@@ -67,10 +68,10 @@ expect.extend({
|
|
|
67
68
|
}
|
|
68
69
|
return v;
|
|
69
70
|
};
|
|
70
|
-
let pass =
|
|
71
|
+
let pass = true;
|
|
71
72
|
let message;
|
|
72
73
|
if (pass) {
|
|
73
|
-
const sorted = [...received];
|
|
74
|
+
const sorted = [...(received || [])];
|
|
74
75
|
sorted.sort((a, b) => {
|
|
75
76
|
for (const sortField of fieldsMap) {
|
|
76
77
|
const l = getValue(a, sortField);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpraTestClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axiosist = tslib_1.__importStar(require("axiosist"));
|
|
6
|
+
const client_1 = require("@opra/client");
|
|
7
|
+
const api_expect_js_1 = require("./api-expect/api-expect.js");
|
|
8
|
+
class OpraTestClient extends client_1.OpraClient {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
collection(name) {
|
|
11
|
+
return super.collection(name);
|
|
12
|
+
}
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
singleton(name) {
|
|
15
|
+
return super.singleton(name);
|
|
16
|
+
}
|
|
17
|
+
async _send(req, options) {
|
|
18
|
+
const resp = (await super._send(req, options));
|
|
19
|
+
resp.expect = new api_expect_js_1.ApiExpect(resp);
|
|
20
|
+
return resp;
|
|
21
|
+
}
|
|
22
|
+
static async create(app, options) {
|
|
23
|
+
const instance = await super.create('/', {
|
|
24
|
+
validateStatus: false,
|
|
25
|
+
...options,
|
|
26
|
+
adapter: axiosist.createAdapter(app)
|
|
27
|
+
});
|
|
28
|
+
Object.setPrototypeOf(instance, OpraTestClient.prototype);
|
|
29
|
+
return instance;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.OpraTestClient = OpraTestClient;
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OpraResponse } from '@opra/client';
|
|
2
|
+
import { Expression } from '@opra/url';
|
|
3
|
+
export declare class ApiExpectCollection {
|
|
4
|
+
readonly response: OpraResponse;
|
|
5
|
+
protected _isNot: boolean;
|
|
6
|
+
constructor(response: OpraResponse, _isNot?: boolean);
|
|
7
|
+
get not(): ApiExpectCollection;
|
|
8
|
+
forEach(callbackfn: (v: any) => void): this;
|
|
9
|
+
toMatch<T extends {}>(expected: T): this;
|
|
10
|
+
toHaveFields(keys: string[]): this;
|
|
11
|
+
toHaveFieldsOnly(keys: string[]): this;
|
|
12
|
+
toBeSortedBy(...fields: string[]): this;
|
|
13
|
+
toBeFilteredBy(filter: string | Expression): this;
|
|
14
|
+
toHaveExactItems(expected: number): this;
|
|
15
|
+
toHaveMaxItems(expected: number): this;
|
|
16
|
+
toHaveMinItems(expected: number): this;
|
|
17
|
+
protected _expect(expected: any): jest.Matchers<any>;
|
|
18
|
+
}
|
|
19
|
+
export declare function convertFilter(str: string | Expression | undefined): any;
|