Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 82bcfde

Browse files
authored
Merge pull request #245 from rwalle61/test-loadtest-api-against-doc
Test loadtest API against our OpenAPI doc
2 parents e6e5bb4 + 1a82f89 commit 82bcfde

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

docs/openapi.yml

+4
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ paths:
413413
responses:
414414
200:
415415
description: Write to runLoad/config.json successful
416+
content:
417+
application/json:
418+
schema:
419+
type: string
416420
400:
417421
description: Incorrect parameters given
418422
404:

src/pfe/portal/routes/projects/loadtest.route.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ router.post('/api/v1/projects/:id/loadtest/config', validateReq, async function
163163
delete configOptions.body;
164164
}
165165
await project.writeNewLoadTestConfigFile(configOptions);
166-
res.status(200).send(`load-test/config.json successfully written to project ${project.name}`);
166+
res.status(200).json(`load-test/config.json successfully written to project ${project.name}`);
167167
} catch (err) {
168168
log.error(err.info || err);
169169
res.status(500).send(err.info || err);

test/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"chai": "^4.1.2",
2525
"chai-files": "^1.4.0",
2626
"chai-http": "^4.0.0",
27-
"chai-openapi-response-validator": "^0.2.3",
27+
"chai-openapi-response-validator": "^0.2.4",
2828
"child-process-promise": "^2.2.1",
2929
"dateformat": "^3.0.3",
3030
"dockerode": "^2.5.2",

test/src/API/projects/loadtest.test.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ const chai = require('chai');
1313

1414
const projectService = require('../../../modules/project.service');
1515
const reqService = require('../../../modules/request.service');
16-
const { testTimeout, ADMIN_COOKIE } = require('../../../config');
16+
const { testTimeout, ADMIN_COOKIE, pathToApiSpec } = require('../../../config');
17+
const chaiResValidator = require('chai-openapi-response-validator');
1718

19+
chai.use(chaiResValidator(pathToApiSpec));
1820
chai.should();
1921

2022
describe('Load Runner Tests', function() {
@@ -42,7 +44,7 @@ describe('Load Runner Tests', function() {
4244

4345
// workspace_location = await projectService.findWorkspaceLocation();
4446
// const projectPath = path.join(workspace_location, projectName);
45-
//await fs.remove(projectPath);
47+
// await fs.remove(projectPath);
4648
});
4749

4850
describe('POST loadtest/config', function() {
@@ -51,14 +53,14 @@ describe('Load Runner Tests', function() {
5153
it('returns status 200 to POST/loadtest/config to the load-test/config.json', async function() {
5254
this.timeout(testTimeout.short);
5355
const res = await writeToLoadTestConfig(projectID, configOptions);
54-
res.should.have.status(200);
56+
res.should.have.status(200).and.satisfyApiSpec;
5557
});
5658

5759
it('returns status 200 to POST/loadtest/config when query parameters are included', async function() {
5860
this.timeout(testTimeout.short);
5961
configOptions.query = { a: '1', b: '2' };
6062
const res = await writeToLoadTestConfig(projectID, configOptions);
61-
res.should.have.status(200);
63+
res.should.have.status(200).and.satisfyApiSpec;
6264
});
6365

6466
it('returns status 200 to GET/loadtest/config with the correct decoded options', async function() {
@@ -67,7 +69,7 @@ describe('Load Runner Tests', function() {
6769
delete configOptions.query;
6870
expectedSavedConfig = modifyOptions(configOptions, { path: '/?a=1&b=2' });
6971
const res = await readLoadTestConfig(projectID);
70-
res.should.have.status(200);
72+
res.should.have.status(200).and.satisfyApiSpec;
7173
res.body.should.deep.equal(expectedSavedConfig);
7274
});
7375
});
@@ -77,13 +79,13 @@ describe('Load Runner Tests', function() {
7779
configOptions.query = { a: '1', b: '2' };
7880
configOptions.config = 'Not a valid option';
7981
const res = await writeToLoadTestConfig(projectID, configOptions);
80-
res.should.have.status(200);
82+
res.should.have.status(200).and.satisfyApiSpec;
8183
});
8284

8385
it('returns status 200 to GET/loadtest/config and not return these non-config fields in loadtest/config.json', async function() {
8486
this.timeout(testTimeout.short);
8587
const res = await readLoadTestConfig(projectID);
86-
res.should.have.status(200);
88+
res.should.have.status(200).and.satisfyApiSpec;
8789
res.body.should.deep.equal(expectedSavedConfig);
8890
});
8991
});
@@ -92,14 +94,14 @@ describe('Load Runner Tests', function() {
9294
this.timeout(testTimeout.short);
9395
configOptions.query = {};
9496
const res = await writeToLoadTestConfig(projectID, configOptions);
95-
res.should.have.status(200);
97+
res.should.have.status(200).and.satisfyApiSpec;
9698
});
9799

98100
it('returns status 200 to GET/loadtest/config and not return these non-config fields in loadtest/config.json', async function() {
99101
this.timeout(testTimeout.short);
100102
expectedSavedConfig.path = '/';
101103
const res = await readLoadTestConfig(projectID);
102-
res.should.have.status(200);
104+
res.should.have.status(200).and.satisfyApiSpec;
103105
res.body.should.deep.equal(expectedSavedConfig);
104106
});
105107
});
@@ -142,7 +144,7 @@ describe('Load Runner Tests', function() {
142144
it('returns status 200 to GET/loadtest/config from the load-test/config.json', async function() {
143145
this.timeout(testTimeout.short);
144146
const res = await readLoadTestConfig(projectID);
145-
res.should.have.status(200);
147+
res.should.have.status(200).and.satisfyApiSpec;
146148
res.body.should.deep.equal(expectedSavedConfig);
147149
});
148150
});

0 commit comments

Comments
 (0)