-
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.
Add tests to cover the empty basePath change
- Loading branch information
1 parent
ec45028
commit 740eee9
Showing
2 changed files
with
116 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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/emptyBasePath.yaml'; | ||
psc.reportFile = 'emptyBasePath.json' | ||
reporter.add(psc); | ||
request.setBaseUrl('http://localhost:9393'); | ||
handler.addInteractionHandler('get all ninjas', () => { | ||
return { | ||
request: { | ||
method: 'GET', | ||
path: '/getallninjas' | ||
}, | ||
response: { | ||
status: 200 | ||
} | ||
} | ||
}); | ||
return mock.start(); | ||
}); | ||
|
||
test.after(() => { | ||
return mock.stop(); | ||
}); | ||
|
||
test('spec passed', async () => { | ||
await pactum.spec() | ||
.useInteraction('get all ninjas') | ||
.get('/getallninjas') | ||
.expectStatus(200); | ||
}); | ||
|
||
test('run reporter', async () => { | ||
await reporter.end(); | ||
}); | ||
|
||
test('validate json reporter', async () => { | ||
const report = require('../reports/emptyBasePath.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.5); | ||
assert.equal(report.coveredApiCount, 1); | ||
assert.equal(report.missedApiCount, 1); | ||
assert.equal(report.totalApiCount, 2); | ||
assert.equal(report.coveredApiList.length, 1); | ||
assert.equal(report.missedApiList.length, 1); | ||
assert.equal(report.basePath, ''); // should return config basePath if not specified | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Test API server | ||
version: 1.0.0 | ||
servers: | ||
- url: / | ||
paths: | ||
/health: | ||
get: | ||
tags: | ||
- HealthCheck | ||
description: Health check | ||
operationId: getHealth | ||
responses: | ||
200: | ||
description: Success | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Health' | ||
text/html: | ||
schema: | ||
$ref: '#/components/schemas/Health' | ||
x-swagger-router-controller: health.controller | ||
/getallninjas: | ||
get: | ||
tags: | ||
- Ninjas | ||
description: Get All Ninjas | ||
operationId: getAllNinjas | ||
responses: | ||
200: | ||
description: Success | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Health' | ||
text/html: | ||
schema: | ||
$ref: '#/components/schemas/Health' | ||
x-swagger-router-controller: test.controller | ||
components: | ||
schemas: | ||
Health: | ||
type: object | ||
properties: | ||
message: | ||
type: string | ||
description: Health Response | ||
example: | ||
message: OK |