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

Test loadtest API against our OpenAPI doc #245

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ paths:
responses:
200:
description: Write to runLoad/config.json successful
content:
application/json:
schema:
type: string
400:
description: Incorrect parameters given
404:
Expand Down
2 changes: 1 addition & 1 deletion src/pfe/portal/routes/projects/loadtest.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ router.post('/api/v1/projects/:id/loadtest/config', validateReq, async function
delete configOptions.body;
}
await project.writeNewLoadTestConfigFile(configOptions);
res.status(200).send(`load-test/config.json successfully written to project ${project.name}`);
res.status(200).json(`load-test/config.json successfully written to project ${project.name}`);
} catch (err) {
log.error(err.info || err);
res.status(500).send(err.info || err);
Expand Down
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"chai": "^4.1.2",
"chai-files": "^1.4.0",
"chai-http": "^4.0.0",
"chai-openapi-response-validator": "^0.2.3",
"chai-openapi-response-validator": "^0.2.4",
"child-process-promise": "^2.2.1",
"dateformat": "^3.0.3",
"dockerode": "^2.5.2",
Expand Down
22 changes: 12 additions & 10 deletions test/src/API/projects/loadtest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const chai = require('chai');

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

chai.use(chaiResValidator(pathToApiSpec));
chai.should();

describe('Load Runner Tests', function() {
Expand Down Expand Up @@ -42,7 +44,7 @@ describe('Load Runner Tests', function() {

// workspace_location = await projectService.findWorkspaceLocation();
// const projectPath = path.join(workspace_location, projectName);
//await fs.remove(projectPath);
// await fs.remove(projectPath);
});

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

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

it('returns status 200 to GET/loadtest/config with the correct decoded options', async function() {
Expand All @@ -67,7 +69,7 @@ describe('Load Runner Tests', function() {
delete configOptions.query;
expectedSavedConfig = modifyOptions(configOptions, { path: '/?a=1&b=2' });
const res = await readLoadTestConfig(projectID);
res.should.have.status(200);
res.should.have.status(200).and.satisfyApiSpec;
res.body.should.deep.equal(expectedSavedConfig);
});
});
Expand All @@ -77,13 +79,13 @@ describe('Load Runner Tests', function() {
configOptions.query = { a: '1', b: '2' };
configOptions.config = 'Not a valid option';
const res = await writeToLoadTestConfig(projectID, configOptions);
res.should.have.status(200);
res.should.have.status(200).and.satisfyApiSpec;
});

it('returns status 200 to GET/loadtest/config and not return these non-config fields in loadtest/config.json', async function() {
this.timeout(testTimeout.short);
const res = await readLoadTestConfig(projectID);
res.should.have.status(200);
res.should.have.status(200).and.satisfyApiSpec;
res.body.should.deep.equal(expectedSavedConfig);
});
});
Expand All @@ -92,14 +94,14 @@ describe('Load Runner Tests', function() {
this.timeout(testTimeout.short);
configOptions.query = {};
const res = await writeToLoadTestConfig(projectID, configOptions);
res.should.have.status(200);
res.should.have.status(200).and.satisfyApiSpec;
});

it('returns status 200 to GET/loadtest/config and not return these non-config fields in loadtest/config.json', async function() {
this.timeout(testTimeout.short);
expectedSavedConfig.path = '/';
const res = await readLoadTestConfig(projectID);
res.should.have.status(200);
res.should.have.status(200).and.satisfyApiSpec;
res.body.should.deep.equal(expectedSavedConfig);
});
});
Expand Down Expand Up @@ -142,7 +144,7 @@ describe('Load Runner Tests', function() {
it('returns status 200 to GET/loadtest/config from the load-test/config.json', async function() {
this.timeout(testTimeout.short);
const res = await readLoadTestConfig(projectID);
res.should.have.status(200);
res.should.have.status(200).and.satisfyApiSpec;
res.body.should.deep.equal(expectedSavedConfig);
});
});
Expand Down