Skip to content

Commit e691140

Browse files
authored
test: renable mutation tests (#83)
1 parent 654774e commit e691140

File tree

15 files changed

+133
-30
lines changed

15 files changed

+133
-30
lines changed

commonTestResources/exampleOpenApiFiles/valid/openapi2.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,46 @@
190190
}
191191
}
192192
},
193+
"/test/responseBody/object/depthOver2": {
194+
"get": {
195+
"produces": [
196+
"application/json"
197+
],
198+
"parameters": [],
199+
"responses": {
200+
"200": {
201+
"description": "Response body should be nested object",
202+
"schema": {
203+
"type": "object",
204+
"required": [
205+
"a"
206+
],
207+
"properties": {
208+
"a": {
209+
"type": "object",
210+
"required": [
211+
"b"
212+
],
213+
"properties": {
214+
"b": {
215+
"type": "object",
216+
"required": [
217+
"c"
218+
],
219+
"properties": {
220+
"c": {
221+
"type": "string"
222+
}
223+
}
224+
}
225+
}
226+
}
227+
}
228+
}
229+
}
230+
}
231+
}
232+
},
193233
"/test/responseBody/object/withMultipleProperties": {
194234
"get": {
195235
"produces": [

commonTestResources/exampleOpenApiFiles/valid/openapi3.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ paths:
2222
application/json:
2323
schema:
2424
type: boolean
25+
/test/responseBody/object/depthOver2:
26+
get:
27+
responses:
28+
200:
29+
description: Response body should be a nested object
30+
content:
31+
application/json:
32+
schema:
33+
type: object
34+
required:
35+
- a
36+
properties:
37+
a:
38+
type: object
39+
required:
40+
- b
41+
properties:
42+
b:
43+
type: object
44+
required:
45+
- c
46+
properties:
47+
c:
48+
type: string
2549
/test/responseBody/object/withMultipleProperties:
2650
get:
2751
responses:

packages/chai-openapi-response-validator/lib/openapi-validator/lib/classes/AbstractResponse.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ class AbstractResponse {
55
this.res = res;
66
}
77

8-
hasNoBody() {
9-
const hasNoContentTypeHeader = Object.prototype.hasOwnProperty.call(this.res, 'headers')
10-
&& !Object.prototype.hasOwnProperty.call(this.res.headers, 'content-type');
11-
return (hasNoContentTypeHeader && this.bodyHasNoContent);
12-
}
13-
148
summary() {
159
return {
1610
body: this.body,

packages/chai-openapi-response-validator/lib/openapi-validator/lib/classes/AxiosResponse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AxiosResponse extends AbstractResponse {
1010
}
1111

1212
getBodyForValidation() {
13-
if (this.hasNoBody()) {
13+
if (this.bodyHasNoContent) {
1414
return null;
1515
}
1616
return this.body;

packages/chai-openapi-response-validator/lib/openapi-validator/lib/classes/RequestPromiseResponse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class RequestPromiseResponse extends AbstractResponse {
1010
}
1111

1212
getBodyForValidation() {
13-
if (this.hasNoBody()) {
13+
if (this.bodyHasNoContent) {
1414
return null;
1515
}
1616
try {

packages/chai-openapi-response-validator/lib/openapi-validator/lib/classes/SuperAgentResponse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SuperAgentResponse extends AbstractResponse {
1313
}
1414

1515
getBodyForValidation() {
16-
if (this.hasNoBody()) {
16+
if (this.bodyHasNoContent) {
1717
return null;
1818
}
1919
if (this.isResTextPopulatedInsteadOfResBody) {

packages/chai-openapi-response-validator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"test:coverage:browse": "npm run test:coverage; open coverage/lcov-report/index.html",
1111
"test:mutation": "stryker run",
1212
"posttest:mutation": "rimraf commonTestResources",
13-
"test:precommit": "npm run lint && npm run test:coverage",
13+
"test:precommit": "npm run lint && npm run test:coverage && npm run test:mutation",
1414
"test:ci": "npm run test:precommit",
1515
"lint": "eslint {lib,test}/**/*.js",
1616
"lint:fix": "npm run lint -- --fix"

packages/chai-openapi-response-validator/stryker.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = function (config) {
3333
transpilers: [],
3434
testFramework: 'mocha',
3535
coverageAnalysis: 'perTest',
36-
thresholds: { high: 100, low: 99, break: 96 },
36+
thresholds: { high: 100, low: 99, break: 98 },
3737
packageManager: 'yarn',
3838
});
3939
};

packages/chai-openapi-response-validator/test/assertions/satisfyApiSpec/satisfyApiSpec.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,35 @@ openApiSpecs.forEach((spec) => {
186186
);
187187
});
188188
});
189+
190+
describe('be a object with depth of over 2', function () {
191+
const nestedObject = {
192+
a: {
193+
b: {
194+
c: 'valid string',
195+
},
196+
},
197+
};
198+
const res = {
199+
status: 200,
200+
req: {
201+
method: 'GET',
202+
path: '/test/responseBody/object/depthOver2',
203+
},
204+
body: nestedObject,
205+
};
206+
207+
it('passes', function () {
208+
expect(res).to.satisfyApiSpec;
209+
});
210+
211+
it('fails when using .not', function () {
212+
const assertion = () => expect(res).to.not.satisfyApiSpec;
213+
expect(assertion).to.throw(
214+
`res contained: ${str({ body: nestedObject })}`,
215+
);
216+
});
217+
});
189218
});
190219

191220
describe('res.req.path matches a response referencing a response definition', function () {

packages/jest-openapi/__test__/matchers/toSatisfyApiSpec/toSatisfyApiSpec.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,35 @@ openApiSpecs.forEach((spec) => {
175175
);
176176
});
177177
});
178+
179+
describe('be a object with depth of over 2', () => {
180+
const nestedObject = {
181+
a: {
182+
b: {
183+
c: 'valid string',
184+
},
185+
},
186+
};
187+
const res = {
188+
status: 200,
189+
req: {
190+
method: 'GET',
191+
path: '/test/responseBody/object/depthOver2',
192+
},
193+
body: nestedObject,
194+
};
195+
196+
it('passes', () => {
197+
expect(res).toSatisfyApiSpec();
198+
});
199+
200+
it('fails when using .not', () => {
201+
const assertion = () => expect(res).not.toSatisfyApiSpec();
202+
expect(assertion).toThrow(
203+
`${red('received')} contained: ${red(str({ body: nestedObject }))}`,
204+
);
205+
});
206+
});
178207
});
179208

180209
describe('res.req.path matches a response referencing a response definition', () => {

packages/jest-openapi/src/openapi-validator/lib/classes/AbstractResponse.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ class AbstractResponse {
55
this.res = res;
66
}
77

8-
hasNoBody() {
9-
const hasNoContentTypeHeader = Object.prototype.hasOwnProperty.call(this.res, 'headers')
10-
&& !Object.prototype.hasOwnProperty.call(this.res.headers, 'content-type');
11-
return (hasNoContentTypeHeader && this.bodyHasNoContent);
12-
}
13-
148
summary() {
159
return {
1610
body: this.body,

packages/jest-openapi/src/openapi-validator/lib/classes/AxiosResponse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AxiosResponse extends AbstractResponse {
1010
}
1111

1212
getBodyForValidation() {
13-
if (this.hasNoBody()) {
13+
if (this.bodyHasNoContent) {
1414
return null;
1515
}
1616
return this.body;

packages/jest-openapi/src/openapi-validator/lib/classes/RequestPromiseResponse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class RequestPromiseResponse extends AbstractResponse {
1010
}
1111

1212
getBodyForValidation() {
13-
if (this.hasNoBody()) {
13+
if (this.bodyHasNoContent) {
1414
return null;
1515
}
1616
try {

packages/jest-openapi/src/openapi-validator/lib/classes/SuperAgentResponse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SuperAgentResponse extends AbstractResponse {
1313
}
1414

1515
getBodyForValidation() {
16-
if (this.hasNoBody()) {
16+
if (this.bodyHasNoContent) {
1717
return null;
1818
}
1919
if (this.isResTextPopulatedInsteadOfResBody) {

yarn.lock

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,11 +2832,6 @@ is-plain-object@^2.0.3, is-plain-object@^2.0.4:
28322832
dependencies:
28332833
isobject "^3.0.1"
28342834

2835-
is-promise@^2.1.0:
2836-
version "2.2.0"
2837-
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.2.0.tgz#3ebfc546cee7064c314686279cc9df7bc2724715"
2838-
integrity sha512-N/4ZxZGjDLAWJQNtcq1/5AOiWTAAhDwnjlaGPaC2+p3pQ+Ka2Dl/EL29DppuoiZ8Xr1/p/9ywBGGzHRPoWKfGA==
2839-
28402835
is-regex@^1.0.5:
28412836
version "1.0.5"
28422837
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.5.tgz#39d589a358bf18967f726967120b8fc1aed74eae"
@@ -4674,11 +4669,9 @@ rsvp@^4.8.4:
46744669
integrity sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==
46754670

46764671
run-async@^2.4.0:
4677-
version "2.4.0"
4678-
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.0.tgz#e59054a5b86876cfae07f431d18cbaddc594f1e8"
4679-
integrity sha512-xJTbh/d7Lm7SBhc1tNvTpeCHaEzoyxPrqNlvSdMfBTYwaY++UJFyXUOxAtsRUXjlqOfj8luNaR9vjCh4KeV+pg==
4680-
dependencies:
4681-
is-promise "^2.1.0"
4672+
version "2.4.1"
4673+
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
4674+
integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==
46824675

46834676
rxjs@^6.5.3, rxjs@~6.5.1:
46844677
version "6.5.5"

0 commit comments

Comments
 (0)