-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from pactumjs/feat/openapi3-support
Feat: openapi3 support
- Loading branch information
Showing
10 changed files
with
364 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ reports/ | |
*.tgz | ||
/.idea/ | ||
/package-lock.json | ||
coverage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const config = { | ||
name: 'SwaggerCovReporter', | ||
path: './reports', | ||
file: 'swagger-cov-report.json', | ||
reportPath: './reports', | ||
reportFile: 'swagger-cov-report.json', | ||
swaggerJsonUrl: "", | ||
swaggerYamlPath: "" | ||
swaggerYamlPath: "", | ||
basePath: "", | ||
oasTag: "swagger" | ||
} | ||
|
||
module.exports = config; |
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
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,130 @@ | ||
const test = require('uvu').test; | ||
const assert = require('uvu/assert'); | ||
const pactum = require('pactum'); | ||
const reporter = pactum.reporter; | ||
const mock = pactum.mock; | ||
const request = pactum.request; | ||
const handler = pactum.handler; | ||
|
||
const psc = require('../src/index'); | ||
|
||
test.before(() => { | ||
psc.swaggerYamlPath = './tests/testObjects/openapi3.yaml'; | ||
psc.basePath = '/api/server/v2' | ||
psc.reportFile = 'report-openapi3.json' | ||
reporter.add(psc); | ||
request.setBaseUrl('http://localhost:9393'); | ||
handler.addInteractionHandler('get all ninjas', () => { | ||
return { | ||
request: { | ||
method: 'GET', | ||
path: '/api/server/v2/getallninjas' | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
} | ||
}); | ||
handler.addInteractionHandler('get ninjas by rank', (ctx) => { | ||
return { | ||
request: { | ||
method: 'GET', | ||
path: `/api/server/v2/getninjas/${ctx.data}` | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
} | ||
}); | ||
handler.addInteractionHandler('get ninja by rank and name', (ctx) => { | ||
return { | ||
request: { | ||
method: 'GET', | ||
path: `/api/server/v2/getninja/${ctx.data.rank}/${ctx.data.name}` | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
} | ||
}); | ||
|
||
handler.addInteractionHandler('get health', () => { | ||
return { | ||
request: { | ||
method: 'GET', | ||
path: `/api/server/v2/health` | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
} | ||
}); | ||
return mock.start(); | ||
}); | ||
|
||
test.after(() => { | ||
return mock.stop(); | ||
}); | ||
|
||
test('spec passed', async () => { | ||
await pactum.spec() | ||
.useInteraction('get all ninjas') | ||
.get('/api/server/v2/getallninjas') | ||
.expectStatus(200); | ||
}); | ||
|
||
test('spec passed - additional path params', async () => { | ||
await pactum.spec() | ||
.useInteraction('get ninjas by rank', "jounin") | ||
.get('/api/server/v2/getninjas/jounin') | ||
.expectStatus(200); | ||
}); | ||
|
||
test('spec passed - no path params', async () => { | ||
await pactum.spec() | ||
.useInteraction('get health') | ||
.get('/api/server/v2/health') | ||
.expectStatus(200); | ||
}); | ||
|
||
test('spec passed - different api path with path params', async () => { | ||
await pactum.spec() | ||
.useInteraction('get ninja by rank and name', {rank: "jounin", name: "kakashi"}) | ||
.get('/api/server/v2/getninja/jounin/kakashi') | ||
.expectStatus(200); | ||
}); | ||
|
||
test('spec failed', async () => { | ||
try { | ||
await pactum.spec() | ||
.get('/api/server/v2/getallninjas') | ||
.expectStatus(200); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}); | ||
|
||
test('run reporter', async () => { | ||
await reporter.end(); | ||
}); | ||
|
||
test('validate json reporter', async () => { | ||
const report = require('../reports/report-openapi3.json'); | ||
console.log(JSON.stringify(report, null, 2)); | ||
assert.equal(Object.keys(report).length, 7); | ||
assert.equal(report.hasOwnProperty("basePath"), true) | ||
assert.equal(report.hasOwnProperty("coverage"), true) | ||
assert.equal(report.hasOwnProperty("coveredApiCount"), true) | ||
assert.equal(report.hasOwnProperty("missedApiCount"), true) | ||
assert.equal(report.hasOwnProperty("totalApiCount"), true) | ||
assert.equal(report.hasOwnProperty("coveredApiList"), true) | ||
assert.equal(report.hasOwnProperty("missedApiList"), true) | ||
assert.equal(report.coverage, 0.57); | ||
assert.equal(report.coveredApiCount, 4); | ||
assert.equal(report.missedApiCount, 3); | ||
assert.equal(report.totalApiCount, 7); | ||
assert.equal(report.coveredApiList.length, 4); | ||
assert.equal(report.missedApiList.length, 3); | ||
}); | ||
|
||
test.run(); |
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
Oops, something went wrong.