-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: increase jest-openapi test coverage to 100% (#91)
* chore: update bug recreation template * test: tidy existing tests * test: sync tests for chai and jest plugins * tidy: sync chai and jest plugins * test: fix jest config
- Loading branch information
Showing
17 changed files
with
897 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 6 additions & 12 deletions
18
commonTestResources/exampleOpenApiFiles/valid/bugRecreationTemplate/openapi.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Example OpenApi 3 spec | ||
description: Has various paths with responses to use in testing | ||
description: Use to recreate a bug | ||
version: 0.1.0 | ||
paths: | ||
/test: | ||
/recreate/bug: | ||
get: | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
allOf: | ||
- type: object | ||
properties: | ||
expectedProperty1: | ||
type: string | ||
- type: object | ||
properties: | ||
expectedProperty2: | ||
type: string | ||
# additionalProperties: false # Uncommenting this line exposes the bug | ||
type: object | ||
properties: | ||
expectedProperty1: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
packages/chai-openapi-response-validator/test/bug-recreation-template.test.js
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
packages/chai-openapi-response-validator/test/bugRecreationTemplate.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const chai = require('chai'); | ||
const path = require('path'); | ||
|
||
const chaiResponseValidator = require('..'); | ||
|
||
const dirContainingApiSpec = path.resolve('../../commonTestResources/exampleOpenApiFiles/valid/bugRecreationTemplate'); | ||
const { expect } = chai; | ||
|
||
describe('Recreate bug (issue #XX)', function () { | ||
before(function () { | ||
const pathToApiSpec = path.join(dirContainingApiSpec, 'openapi.yml'); | ||
chai.use(chaiResponseValidator(pathToApiSpec)); | ||
}); | ||
|
||
const res = { | ||
status: 200, | ||
req: { | ||
method: 'GET', | ||
path: '/recreate/bug', | ||
}, | ||
body: { | ||
expectedProperty1: 'foo', | ||
}, | ||
}; | ||
|
||
it('passes', function () { | ||
expect(res).to.satisfyApiSpec; | ||
}); | ||
|
||
it('fails when using .not', function () { | ||
const assertion = () => expect(res).to.not.satisfyApiSpec; | ||
expect(assertion).to.throw(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/jest-openapi/__test__/bugRecreationTemplate.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const path = require('path'); | ||
const { inspect } = require('util'); | ||
|
||
const jestOpenAPI = require('..'); | ||
|
||
const dirContainingApiSpec = path.resolve('../../commonTestResources/exampleOpenApiFiles/valid/bugRecreationTemplate'); | ||
|
||
describe('Recreate bug (issue #XX)', () => { | ||
beforeAll(() => { | ||
const pathToApiSpec = path.join(dirContainingApiSpec, 'openapi.yml'); | ||
jestOpenAPI(pathToApiSpec); | ||
}); | ||
|
||
const res = { | ||
status: 200, | ||
req: { | ||
method: 'GET', | ||
path: '/recreate/bug', | ||
}, | ||
body: { | ||
expectedProperty1: 'foo', | ||
}, | ||
}; | ||
|
||
it('passes', () => { | ||
expect(res).toSatisfyApiSpec(); | ||
}); | ||
|
||
it('fails when using .not', () => { | ||
const assertion = () => expect(res).not.toSatisfyApiSpec(); | ||
expect(assertion).toThrow( | ||
inspect({ | ||
body: { | ||
expectedProperty1: 'foo', | ||
}, | ||
}), | ||
); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.