Skip to content

Commit

Permalink
Add tests to cover the empty basePath change
Browse files Browse the repository at this point in the history
  • Loading branch information
ElnSorokina committed Nov 16, 2023
1 parent ec45028 commit 740eee9
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/emptyBasePath.test.js
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();
51 changes: 51 additions & 0 deletions tests/testObjects/emptyBasePath.yaml
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

0 comments on commit 740eee9

Please sign in to comment.