@opra/testing 0.29.0 → 0.30.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.
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiExpectBase = void 0;
4
+ require("../jest-extend/index.js");
5
+ class ApiExpectBase {
6
+ constructor(response, isNot) {
7
+ this.response = response;
8
+ this.isNot = isNot;
9
+ }
10
+ _expect(expected) {
11
+ const out = expect(expected);
12
+ if (this.isNot)
13
+ return out.not;
14
+ return out;
15
+ }
16
+ }
17
+ exports.ApiExpectBase = ApiExpectBase;
@@ -2,31 +2,64 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertFilter = exports.ApiExpectCollection = void 0;
4
4
  const tslib_1 = require("tslib");
5
- require("../jest-extend/index.js");
6
5
  const lodash_isnil_1 = tslib_1.__importDefault(require("lodash.isnil"));
7
6
  const lodash_omitby_1 = tslib_1.__importDefault(require("lodash.omitby"));
8
7
  const rule_judgment_1 = tslib_1.__importDefault(require("rule-judgment"));
9
8
  const common_1 = require("@opra/common");
9
+ const api_expect_base_js_1 = require("./api-expect-base.js");
10
10
  // @ts-ignore
11
11
  const ruleJudgment = typeof rule_judgment_1.default === 'object' ? rule_judgment_1.default.default : rule_judgment_1.default;
12
- class ApiExpectCollection {
13
- constructor(response, _isNot = false) {
14
- this.response = response;
15
- this._isNot = _isNot;
16
- }
12
+ class ApiExpectCollection extends api_expect_base_js_1.ApiExpectBase {
17
13
  get not() {
18
- return new ApiExpectCollection(this.response, !this._isNot);
14
+ return new ApiExpectCollection(this.response, !this.isNot);
15
+ }
16
+ /**
17
+ * Tests if Collection have number of items in payload
18
+ * @param min Minimum number of items. Default 1
19
+ * @param max Maximum number of items
20
+ */
21
+ toReturnItems(min, max) {
22
+ let msg = '';
23
+ try {
24
+ msg += `The length of payload array do not match. `;
25
+ const l = this.response.body.payload.length;
26
+ this._expect(l).toBeGreaterThanOrEqual(min || 1);
27
+ if (max)
28
+ this._expect(l).toBeLessThanOrEqual(max);
29
+ }
30
+ catch (e) {
31
+ if (msg)
32
+ e.message = msg + '\n\n' + e.message;
33
+ Error.captureStackTrace(e, this.toReturnItems);
34
+ throw e;
35
+ }
36
+ return this;
19
37
  }
20
- forEach(callbackfn) {
21
- this.response.body.forEach(callbackfn);
38
+ toContainTotalMatches(min, max) {
39
+ let msg = '';
40
+ try {
41
+ msg += `The value of "totalMatches" do not match. `;
42
+ const l = this.response.body.totalMatches;
43
+ this._expect(l).toBeGreaterThanOrEqual(min || 1);
44
+ if (max)
45
+ this._expect(l).toBeLessThanOrEqual(max);
46
+ }
47
+ catch (e) {
48
+ if (msg)
49
+ e.message = msg + '\n\n' + e.message;
50
+ Error.captureStackTrace(e, this.toReturnItems);
51
+ throw e;
52
+ }
22
53
  return this;
23
54
  }
55
+ /**
56
+ * Tests if Collection items matches given object
57
+ * @param expected
58
+ */
24
59
  toMatch(expected) {
25
60
  try {
26
- const v = (0, lodash_omitby_1.default)(expected, lodash_isnil_1.default);
27
- for (const item of this.response.body.payload) {
28
- this._expect(item).toMatchObject(v);
29
- }
61
+ expected = (0, lodash_omitby_1.default)(expected, lodash_isnil_1.default);
62
+ this._expect(this.response.body.payload).toEqual(expect.arrayContaining([expect.objectContaining(expected)]));
30
63
  }
31
64
  catch (e) {
32
65
  Error.captureStackTrace(e, this.toMatch);
@@ -34,46 +67,49 @@ class ApiExpectCollection {
34
67
  }
35
68
  return this;
36
69
  }
37
- toHaveFields(keys) {
70
+ /**
71
+ * Tests if Collection items has all of provided fields.
72
+ * @param fields
73
+ */
74
+ toContainFields(fields) {
38
75
  try {
76
+ fields = Array.isArray(fields) ? fields : [fields];
39
77
  for (const item of this.response.body.payload) {
40
- this._expect(item).toHaveFields(keys);
78
+ this._expect(Object.keys(item)).toEqual(expect.arrayContaining(fields));
41
79
  }
42
80
  }
43
81
  catch (e) {
44
- Error.captureStackTrace(e, this.toHaveFields);
82
+ Error.captureStackTrace(e, this.toContainFields);
45
83
  throw e;
46
84
  }
47
85
  return this;
48
86
  }
49
- toHaveFieldsOnly(keys) {
87
+ /**
88
+ * Tests if Collection items only contains all of provided fields.
89
+ * @param fields
90
+ */
91
+ toContainAllFields(fields) {
50
92
  try {
93
+ fields = Array.isArray(fields) ? fields : [fields];
51
94
  for (const item of this.response.body.payload) {
52
- this._expect(item).toHaveFieldsOnly(keys);
95
+ this._expect(Object.keys(item)).toEqual(fields);
53
96
  }
54
97
  }
55
98
  catch (e) {
56
- Error.captureStackTrace(e, this.toHaveFieldsOnly);
99
+ Error.captureStackTrace(e, this.toContainAllFields);
57
100
  throw e;
58
101
  }
59
102
  return this;
60
103
  }
61
- //
62
- // toHaveProperty(keyPath, value?): this {
63
- // try {
64
- // for (const item of this.response.payload) {
65
- // this._expect(item).toHaveProperty(keyPath, value);
66
- // }
67
- //
68
- // } catch (e: any) {
69
- // Error.captureStackTrace(e, this.toHaveProperty);
70
- // throw e;
71
- // }
72
- // return this;
73
- // }
74
- toBeSortedBy(...fields) {
104
+ /**
105
+ * Tests if Collection is sorted by given field(s).
106
+ * @param fields
107
+ */
108
+ toBeSortedBy(fields) {
75
109
  try {
76
- this._expect(this.response.body.payload).toBeSortedBy(fields);
110
+ fields = Array.isArray(fields) ? fields : [fields];
111
+ this._expect(this.response.body.payload)
112
+ .opraCollectionToBeSortedBy(fields);
77
113
  }
78
114
  catch (e) {
79
115
  Error.captureStackTrace(e, this.toBeSortedBy);
@@ -81,6 +117,10 @@ class ApiExpectCollection {
81
117
  }
82
118
  return this;
83
119
  }
120
+ /**
121
+ * Tests if Collection is filtered by given condition.
122
+ * @param filter
123
+ */
84
124
  toBeFilteredBy(filter) {
85
125
  const f = convertFilter(filter);
86
126
  if (f) {
@@ -96,44 +136,49 @@ class ApiExpectCollection {
96
136
  }
97
137
  return this;
98
138
  }
99
- toHaveExactItems(expected) {
100
- try {
101
- this._expect(this.response.body.dapayloadta).toHaveLength(expected);
102
- }
103
- catch (e) {
104
- Error.captureStackTrace(e, this.toHaveExactItems);
105
- throw e;
106
- }
107
- return this;
108
- }
109
- toHaveMaxItems(expected) {
110
- try {
111
- this._expect(this.response.body.payload.length).toBeLessThanOrEqual(expected);
112
- }
113
- catch (e) {
114
- Error.captureStackTrace(e, this.toHaveMaxItems);
115
- throw e;
116
- }
117
- return this;
118
- }
119
- toHaveMinItems(expected) {
120
- try {
121
- this._expect(this.response.body.payload.length).toBeGreaterThanOrEqual(expected);
122
- }
123
- catch (e) {
124
- Error.captureStackTrace(e, this.toHaveMinItems);
125
- throw e;
126
- }
127
- return this;
128
- }
129
- _expect(expected) {
130
- const out = expect(expected);
131
- if (this._isNot)
132
- return out.not;
133
- return out;
134
- }
135
139
  }
136
140
  exports.ApiExpectCollection = ApiExpectCollection;
141
+ expect.extend({
142
+ opraCollectionToBeSortedBy(received, properties) {
143
+ const fieldsMap = properties.map(x => x.split('.'));
144
+ const getValue = (obj, fieldMap) => {
145
+ let v = obj;
146
+ let i = 0;
147
+ while (v && i < fieldMap.length) {
148
+ v = v[fieldMap[i++]];
149
+ }
150
+ return v;
151
+ };
152
+ let pass = true;
153
+ let message;
154
+ if (pass) {
155
+ const sorted = [...(received || [])];
156
+ sorted.sort((a, b) => {
157
+ for (const sortField of fieldsMap) {
158
+ const l = getValue(a, sortField);
159
+ const r = getValue(b, sortField);
160
+ if (l < r)
161
+ return -1;
162
+ if (l > r)
163
+ return 1;
164
+ }
165
+ return 0;
166
+ });
167
+ try {
168
+ expect(received).toEqual(sorted);
169
+ }
170
+ catch (e) {
171
+ pass = false;
172
+ message = () => 'Items are not sorted as expected';
173
+ }
174
+ }
175
+ return {
176
+ actual: received,
177
+ message,
178
+ pass
179
+ };
180
+ },
181
+ });
137
182
  function convertFilter(str) {
138
183
  const ast = typeof str === 'string' ? common_1.OpraFilter.parse(str) : str;
139
184
  if (!ast)
@@ -3,60 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiExpectError = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  require("../jest-extend/index.js");
6
- const jest_matcher_utils_1 = tslib_1.__importDefault(require("jest-matcher-utils"));
7
- const object_matches_util_js_1 = require("../utils/object-matches.util.js");
8
- const api_expect_object_js_1 = require("./api-expect-object.js");
9
- class ApiExpectError extends api_expect_object_js_1.ApiExpectObject {
10
- constructor(response) {
11
- super(response);
12
- this.response = response;
13
- }
14
- toContainDetail(...matching) {
6
+ const lodash_isnil_1 = tslib_1.__importDefault(require("lodash.isnil"));
7
+ const lodash_omitby_1 = tslib_1.__importDefault(require("lodash.omitby"));
8
+ const api_expect_base_js_1 = require("./api-expect-base.js");
9
+ class ApiExpectError extends api_expect_base_js_1.ApiExpectBase {
10
+ toMatch(expected) {
15
11
  try {
16
- expect(this.response.body).toBeDefined();
17
- expect(this.response.body.issues).toBeDefined();
18
- expect(this.response.body.issues).apiErrorDetailToContain(matching);
12
+ if (typeof expected === 'string')
13
+ expected = { message: expected };
14
+ else if (expected instanceof RegExp)
15
+ expected = { message: expect.stringMatching(expected) };
16
+ expected = (0, lodash_omitby_1.default)(expected, lodash_isnil_1.default);
17
+ this._expect(this.response.body.errors).toEqual(expect.arrayContaining([expect.objectContaining(expected)]));
19
18
  }
20
19
  catch (e) {
21
- Error.captureStackTrace(e, this.toContainDetail);
20
+ Error.captureStackTrace(e, this.toMatch);
22
21
  throw e;
23
22
  }
23
+ return this;
24
24
  }
25
25
  }
26
26
  exports.ApiExpectError = ApiExpectError;
27
- expect.extend({
28
- apiErrorDetailToContain(received, issues) {
29
- try {
30
- expect(typeof received).toStrictEqual('object');
31
- expect(Array.isArray(received)).toStrictEqual(true);
32
- }
33
- catch (e) {
34
- return {
35
- pass: false,
36
- message: () => e.message
37
- };
38
- }
39
- for (const m of issues) {
40
- let matched = false;
41
- for (const detail of received) {
42
- if (typeof m === 'object') {
43
- try {
44
- (0, object_matches_util_js_1.objectMatches)(detail, m);
45
- matched = true;
46
- break;
47
- }
48
- catch {
49
- //
50
- }
51
- }
52
- }
53
- if (!matched) {
54
- return {
55
- pass: false,
56
- message: () => `Object does not match: \n` + jest_matcher_utils_1.default.stringify(m)
57
- };
58
- }
59
- }
60
- return { actual: true, pass: true, message: () => '' };
61
- },
62
- });
@@ -2,21 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiExpectObject = void 0;
4
4
  const tslib_1 = require("tslib");
5
- require("../jest-extend/index.js");
6
5
  const lodash_isnil_1 = tslib_1.__importDefault(require("lodash.isnil"));
7
6
  const lodash_omitby_1 = tslib_1.__importDefault(require("lodash.omitby"));
8
- class ApiExpectObject {
9
- constructor(response, _isNot = false) {
10
- this.response = response;
11
- this._isNot = _isNot;
12
- }
7
+ const api_expect_base_js_1 = require("./api-expect-base.js");
8
+ class ApiExpectObject extends api_expect_base_js_1.ApiExpectBase {
13
9
  get not() {
14
- return new ApiExpectObject(this.response, !this._isNot);
10
+ return new ApiExpectObject(this.response, !this.isNot);
15
11
  }
12
+ /**
13
+ * Tests if Response payload matches given object
14
+ * @param expected
15
+ */
16
16
  toMatch(expected) {
17
17
  try {
18
- const v = (0, lodash_omitby_1.default)(expected, lodash_isnil_1.default);
19
- this._expect(this.response.body.payload).toMatchObject(v);
18
+ expected = (0, lodash_omitby_1.default)(expected, lodash_isnil_1.default);
19
+ this._expect(this.response.body.payload).toEqual(expect.objectContaining(expected));
20
20
  }
21
21
  catch (e) {
22
22
  Error.captureStackTrace(e, this.toMatch);
@@ -24,31 +24,37 @@ class ApiExpectObject {
24
24
  }
25
25
  return this;
26
26
  }
27
- toHaveFields(fields) {
27
+ /**
28
+ * Tests if Response payload has all of provided fields.
29
+ * @param fields
30
+ */
31
+ toContainFields(fields) {
28
32
  try {
29
- this._expect(this.response.body.payload).toHaveFields(fields);
33
+ fields = Array.isArray(fields) ? fields : [fields];
34
+ this._expect(Object.keys(this.response.body.payload))
35
+ .toEqual(expect.arrayContaining(fields));
30
36
  }
31
37
  catch (e) {
32
- Error.captureStackTrace(e, this.toHaveFields);
38
+ Error.captureStackTrace(e, this.toContainFields);
33
39
  throw e;
34
40
  }
35
41
  return this;
36
42
  }
37
- toHaveFieldsOnly(fields) {
43
+ /**
44
+ * Tests if Response payload only contains all of provided fields.
45
+ * @param fields
46
+ */
47
+ toContainAllFields(fields) {
38
48
  try {
39
- this._expect(this.response.body.payload).toHaveFieldsOnly(fields);
49
+ fields = Array.isArray(fields) ? fields : [fields];
50
+ this._expect(Object.keys(this.response.body.payload))
51
+ .toEqual(fields);
40
52
  }
41
53
  catch (e) {
42
- Error.captureStackTrace(e, this.toHaveFieldsOnly);
54
+ Error.captureStackTrace(e, this.toContainAllFields);
43
55
  throw e;
44
56
  }
45
57
  return this;
46
58
  }
47
- _expect(expected) {
48
- const out = expect(expected);
49
- if (this._isNot)
50
- return out.not;
51
- return out;
52
- }
53
59
  }
54
60
  exports.ApiExpectObject = ApiExpectObject;
@@ -2,49 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiExpectOperationResult = void 0;
4
4
  require("../jest-extend/index.js");
5
- class ApiExpectOperationResult {
6
- constructor(response, _isNot = false) {
7
- this.response = response;
8
- this._isNot = _isNot;
9
- }
5
+ const api_expect_base_js_1 = require("./api-expect-base.js");
6
+ class ApiExpectOperationResult extends api_expect_base_js_1.ApiExpectBase {
10
7
  get not() {
11
- return new ApiExpectOperationResult(this.response, !this._isNot);
12
- }
13
- toBeAffectedExact(expected) {
14
- try {
15
- this._expect(this.response.body.affected).toStrictEqual(expected);
16
- }
17
- catch (e) {
18
- Error.captureStackTrace(e, this.toBeAffectedExact);
19
- throw e;
20
- }
21
- return this;
8
+ return new ApiExpectOperationResult(this.response, !this.isNot);
22
9
  }
23
- toBeAffectedMin(expected) {
10
+ toBeAffected(min, max) {
11
+ let msg = '';
24
12
  try {
25
- this._expect(this.response.body.affected).toBeGreaterThanOrEqual(expected);
13
+ msg += `The value of "affected" do not match. `;
14
+ const l = this.response.body.affected;
15
+ this._expect(l).toBeGreaterThanOrEqual(min || 1);
16
+ if (max)
17
+ this._expect(l).toBeLessThanOrEqual(max);
26
18
  }
27
19
  catch (e) {
28
- Error.captureStackTrace(e, this.toBeAffectedMin);
20
+ if (msg)
21
+ e.message = msg + '\n\n' + e.message;
22
+ Error.captureStackTrace(e, this.toBeAffected);
29
23
  throw e;
30
24
  }
31
25
  return this;
32
26
  }
33
- toBeAffectedMax(expected) {
34
- try {
35
- this._expect(this.response.body.affected).toBeLessThanOrEqual(expected);
36
- }
37
- catch (e) {
38
- Error.captureStackTrace(e, this.toBeAffectedMax);
39
- throw e;
40
- }
41
- return this;
42
- }
43
- _expect(expected) {
44
- const out = expect(expected);
45
- if (this._isNot)
46
- return out.not;
47
- return out;
48
- }
49
27
  }
50
28
  exports.ApiExpectOperationResult = ApiExpectOperationResult;
@@ -1,113 +1,134 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiExpect = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  require("../jest-extend/index.js");
6
+ const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
7
+ const api_expect_base_js_1 = require("./api-expect-base.js");
5
8
  const api_expect_collection_js_1 = require("./api-expect-collection.js");
6
9
  const api_expect_error_js_1 = require("./api-expect-error.js");
7
10
  const api_expect_object_js_1 = require("./api-expect-object.js");
8
11
  const api_expect_operation_result_js_1 = require("./api-expect-operation-result.js");
9
- class ApiExpect {
10
- constructor(response, _isNot = false) {
11
- this.response = response;
12
- this._isNot = _isNot;
13
- }
14
- get not() {
15
- return new ApiExpect(this.response, !this._isNot);
16
- }
17
- toSuccess(status = 200) {
12
+ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
13
+ /**
14
+ * Tests if request succeeded
15
+ * @param status Status code number between 200-299
16
+ */
17
+ toSuccess(status) {
18
18
  let msg = '';
19
19
  try {
20
- msg = 'Unexpected "status" returned';
21
- this._expect(this.response.status).toStrictEqual(status);
20
+ msg += `The response status isn't as expected.`;
21
+ if (status) {
22
+ expect(this.response.status).toEqual(status);
23
+ }
24
+ else {
25
+ expect(this.response.status).toBeGreaterThanOrEqual(200);
26
+ expect(this.response.status).toBeLessThan(400);
27
+ }
22
28
  }
23
29
  catch (e) {
30
+ e.message = 'Request didn\'t succeeded. ' + msg + '\n\n' + e.message;
24
31
  const issues = this.response.body?.errors;
25
32
  const issue = issues?.[0]?.message;
26
- if (msg)
27
- e.message = msg + '\n\n' + (issue || e.message);
33
+ if (issue) {
34
+ e.message += '\n\n' + ansi_colors_1.default.yellow('Server message: ') + issue;
35
+ }
28
36
  Error.captureStackTrace(e, this.toSuccess);
29
37
  throw e;
30
38
  }
31
39
  return this;
32
40
  }
33
- toFail(status = 400) {
41
+ /**
42
+ * Tests if request failed
43
+ * @param status Status code number between 400-599
44
+ */
45
+ toFail(status) {
34
46
  let msg = '';
35
47
  try {
36
- msg = 'Response "status" does not match';
48
+ msg += `The response status isn't as expected. `;
37
49
  if (status) {
38
- expect(this.response.status).toStrictEqual(status);
50
+ expect(this.response.status).toEqual(status);
39
51
  }
40
52
  else {
41
53
  expect(this.response.status).toBeGreaterThanOrEqual(400);
42
54
  expect(this.response.status).toBeLessThanOrEqual(599);
43
55
  }
44
- msg = 'Api did not returned "errors"';
45
- expect(this.response.body.errors).toBeArray();
46
- expect(this.response.body.errors.length).toBeGreaterThan(0);
47
56
  }
48
57
  catch (e) {
49
- if (msg)
50
- e.message = msg + '\n\n' + e.message;
51
- Error.captureStackTrace(e, this.toFail);
58
+ e.message = 'Request didn\'t failed. ' + msg + '\n\n' + e.message;
59
+ Error.captureStackTrace(e, this.toSuccess);
52
60
  throw e;
53
61
  }
54
62
  return new api_expect_error_js_1.ApiExpectError(this.response);
55
63
  }
56
- toReturnOperationResult() {
64
+ /**
65
+ * Tests if API returns a Collection
66
+ */
67
+ toReturnCollection() {
57
68
  let msg = '';
58
69
  try {
59
- msg = '"body" is empty';
60
- expect(this.response.body).toBeDefined();
61
- msg = '"operation" property is empty';
62
- expect(this.response.body.context).toBeDefined();
70
+ msg = 'Content-Type header value is not valid. ';
71
+ expect(this.response.contentType).toEqual('application/opra+json');
72
+ msg = 'Type of response "body" is not valid. ';
73
+ expect(typeof this.response.body).toEqual('object');
74
+ msg = 'Type of "payload" is not an Array. ';
75
+ const payload = this.response.body.payload;
76
+ expect(Array.isArray(payload) ? 'array' : typeof payload).toEqual('array');
63
77
  }
64
78
  catch (e) {
79
+ e.message = 'Api didn\'t returned a Collection. ' + msg + '\n\n' + e.message;
65
80
  if (msg)
66
81
  e.message = msg + '\n\n' + e.message;
67
- Error.captureStackTrace(e, this.toReturnOperationResult);
82
+ Error.captureStackTrace(e, this.toReturnCollection);
68
83
  throw e;
69
84
  }
70
- return new api_expect_operation_result_js_1.ApiExpectOperationResult(this.response);
85
+ return new api_expect_collection_js_1.ApiExpectCollection(this.response);
71
86
  }
87
+ /**
88
+ * Tests if API returns an Object
89
+ */
72
90
  toReturnObject() {
73
91
  let msg = '';
74
92
  try {
75
- msg = '"body" is empty';
76
- expect(this.response.body).toBeDefined();
77
- expect(typeof this.response.body).toStrictEqual('object');
78
- msg = `"body.payload" is ${typeof typeof this.response.body.payload}`;
79
- expect(typeof this.response.body.payload).toStrictEqual('object');
93
+ msg = 'Content-Type header value is not valid. ';
94
+ expect(this.response.contentType).toEqual('application/opra+json');
95
+ msg = 'Type of response "body" is not valid. ';
96
+ expect(typeof this.response.body).toEqual('object');
97
+ msg = 'Type of "payload" is not an Object. ';
98
+ const payload = this.response.body.payload;
99
+ expect(typeof payload).toEqual('object');
80
100
  }
81
101
  catch (e) {
102
+ e.message = 'Api didn\'t returned an Object. ' + msg + '\n\n' + e.message;
82
103
  if (msg)
83
104
  e.message = msg + '\n\n' + e.message;
84
- Error.captureStackTrace(e, this.toReturnObject);
105
+ Error.captureStackTrace(e, this.toReturnCollection);
85
106
  throw e;
86
107
  }
87
108
  return new api_expect_object_js_1.ApiExpectObject(this.response);
88
109
  }
89
- toReturnCollection() {
110
+ /**
111
+ * Tests if API returns an OperationResult
112
+ */
113
+ toReturnOperationResult() {
90
114
  let msg = '';
91
115
  try {
92
- msg = '"body" is empty';
93
- expect(this.response.body).toBeDefined();
94
- expect(this.response.body.payload).toBeDefined();
95
- msg = '"body" is not an array';
96
- expect(this.response.body.payload).toBeArray();
116
+ msg = 'Content-Type header value is not valid. ';
117
+ expect(this.response.contentType).toEqual('application/opra+json');
118
+ msg = 'Type of response "body" is not valid. ';
119
+ expect(typeof this.response.body).toEqual('object');
120
+ msg = 'The response has payload. ';
121
+ const payload = this.response.body.payload;
122
+ expect(typeof payload).toEqual('undefined');
97
123
  }
98
124
  catch (e) {
125
+ e.message = 'Api didn\'t returned a OperationResult. ' + msg + '\n\n' + e.message;
99
126
  if (msg)
100
127
  e.message = msg + '\n\n' + e.message;
101
128
  Error.captureStackTrace(e, this.toReturnCollection);
102
129
  throw e;
103
130
  }
104
- return new api_expect_collection_js_1.ApiExpectCollection(this.response);
105
- }
106
- _expect(expected) {
107
- const out = expect(expected);
108
- if (this._isNot)
109
- return out.not;
110
- return out;
131
+ return new api_expect_operation_result_js_1.ApiExpectOperationResult(this.response);
111
132
  }
112
133
  }
113
134
  exports.ApiExpect = ApiExpect;