Skip to content

Commit

Permalink
fix(issues 79 82): issues 79 82 (#181)
Browse files Browse the repository at this point in the history
* fix(issues 79 82): issues 79 82

closes #79 #82
  • Loading branch information
manorlh authored and enudler committed Aug 4, 2019
1 parent 7005be5 commit e53c76f
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 4 deletions.
32 changes: 32 additions & 0 deletions src/tests/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const get = require('lodash.get');

module.exports = {
addDefaultsToTest,
addDefaultsToStep
};

function addDefaultsToTest(artilleryTest) {
const scenarios = get(artilleryTest, 'scenarios', []);
for (let scenario of scenarios){
const flow = get(scenario, 'flow', []);
for (let step of flow){
addDefaultsToStep(step);
}
}

const before = get(artilleryTest, 'before.flow', []);
for (let step of before){
addDefaultsToStep(step);
}
return artilleryTest;
}

function addDefaultsToStep(step) {
if (step){
const method = Object.keys(step)[0];
if (method){
step[method].url = step[method].url || '/';
}
}
return step;
}
3 changes: 3 additions & 0 deletions src/tests/models/dsl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

const database = require('./database'),
logger = require('../../common/logger'),
utils = require('../helpers/utils'),
{ ERROR_MESSAGES } = require('../../common/consts');

module.exports = {
Expand Down Expand Up @@ -34,6 +35,7 @@ async function getDefinition(dslName, definitionName) {
}

async function createDefinition(dslName, body) {
utils.addDefaultsToStep(body.request);
const result = await database.insertDslDefinition(dslName, body.name, body.request);
if (result){
logger.info(body, 'Definition created successfully and saved to Cassandra');
Expand All @@ -49,6 +51,7 @@ async function createDefinition(dslName, body) {
}

async function updateDefinition(dslName, definitionName, body) {
utils.addDefaultsToStep(body.request);
const result = await database.updateDslDefinition(dslName, definitionName, body.request);
if (result){
logger.info(body, 'Definition updated successfully and saved to Cassandra');
Expand Down
3 changes: 2 additions & 1 deletion src/tests/models/testGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
let _ = require('lodash');
let consts = require('./../../common/consts');
const database = require('./database');
const utils = require('../helpers/utils');
const { get, cloneDeep } = require('lodash');

module.exports.createTest = async function(testDetails) {
if (testDetails.type === consts.TEST_TYPE_BASIC) {
let artillery = testDetails.artillery_test;
let artillery = utils.addDefaultsToTest(testDetails.artillery_test);
delete testDetails.artillery_test;
return artillery;
} else {
Expand Down
27 changes: 26 additions & 1 deletion tests/integration-tests/tests/dsl-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ describe('Testing dsl tests api', function () {
should(getResponse.statusCode).eql(200, JSON.stringify(getResponse.body));
should(getResponse.body).eql(expectedCreatePaymentBody);
});
it('succeed post dsl definition without step url - should add default /', async function () {
const request = generateCreatePaymentRequest();
delete request.post.url;
const createDslResponse = await requestSender.createDsl(dslName, 'create_payment', request);
should(createDslResponse.statusCode).eql(201, JSON.stringify(request.body));
const expected = {...expectedCreatePaymentBody,request:{post:{...expectedCreatePaymentBody.request.post,url:'/'}}};
should(createDslResponse.body).eql(expected);
const getResponse = await requestSender.getDsl(dslName, 'create_payment');
should(getResponse.statusCode).eql(200, JSON.stringify(getResponse.body));
should(getResponse.body).eql(expected);
});

it('create dsl which already exist - should return 400', async function () {
let createDslResponse = await requestSender.createDsl(dslName, 'create_payment', createPaymentRequest);
Expand Down Expand Up @@ -61,6 +72,20 @@ describe('Testing dsl tests api', function () {
should(getResponse.body.request).eql(registerRequest);
});

it('succeed update definition - without step url - should add default /', async function () {
const createDslResponse = await requestSender.createDsl(dslName, 'create_payment', createPaymentRequest);
should(createDslResponse.statusCode).eql(201, JSON.stringify(createDslResponse.body));
const request = {post:{...registerRequest.post,url: undefined}};

const updateResponse = await requestSender.updateDsl(dslName, 'create_payment', request);
should(updateResponse.statusCode).eql(200, JSON.stringify(updateResponse.body));

const getResponse = await requestSender.getDsl(dslName, 'create_payment');
should(getResponse.statusCode).eql(200, JSON.stringify(getResponse.body));
const expected = {post:{...registerRequest.post,url: '/'}};
should(getResponse.body.request).eql(expected);
});

it('succeed delete existing definition', async function () {
const createDslResponse = await requestSender.createDsl(dslName, 'create_payment', createPaymentRequest);
should(createDslResponse.statusCode).eql(201, JSON.stringify(createDslResponse.body));
Expand Down Expand Up @@ -300,4 +325,4 @@ const expectedGetDefinitionsResponse = [
}
}
}
];
];
33 changes: 33 additions & 0 deletions tests/integration-tests/tests/tests-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let should = require('should');
let validHeaders = { 'x-zooz-request-id': 'value', 'Content-Type': 'application/json' };
let uuid = require('uuid');
let JSCK = require('jsck');
const { cloneDeep } = require('lodash');
JSCK.Draft4 = JSCK.draft4;
let artilleryCheck = new JSCK.Draft4(require('artillery/core/lib/schemas/artillery_test_script'));
const requestSender = require('./helpers/requestCreator');
Expand Down Expand Up @@ -138,6 +139,38 @@ describe('the tests api', function() {
getTestResponse = await requestSender.getTest(createTestResponse.body.id, validHeaders);
getTestResponse.statusCode.should.eql(404);
});
it('Create basic test without step url - should add default /', async () => {
let requestBody = cloneDeep(require('../../testExamples/Basic_test.json'));
requestBody.artillery_test.scenarios[0].flow[0].post.url = undefined;

let createTestResponse = await requestSender.createTest(requestBody, validHeaders);
createTestResponse.statusCode.should.eql(201);
createTestResponse.body.should.have.only.keys('id', 'revision_id');

let getTestResponse = await requestSender.getTest(createTestResponse.body.id, validHeaders);
let expectedResult = cloneDeep(require('../../testResults/Basic_test.json'));
expectedResult.scenarios[0].flow[0].post.url = '/';
should(getTestResponse.statusCode).eql(200, JSON.stringify(getTestResponse.body));
getTestResponse.body.artillery_test.should.eql(expectedResult);
});
it('update basic test without step url - should add default /', async () => {
let requestBody = cloneDeep(require('../../testExamples/Basic_test.json'));

let createTestResponse = await requestSender.createTest(requestBody, validHeaders);
createTestResponse.statusCode.should.eql(201);
createTestResponse.body.should.have.only.keys('id', 'revision_id');

requestBody.artillery_test.scenarios[0].flow[0].post.url = undefined;

let updatedTestResponse = await requestSender.updateTest(requestBody, validHeaders, createTestResponse.body.id);
updatedTestResponse.statusCode.should.eql(201);

let getTestResponse = await requestSender.getTest(createTestResponse.body.id, validHeaders);
let expectedResult = cloneDeep(require('../../testResults/Basic_test.json'));
expectedResult.scenarios[0].flow[0].post.url = '/';
should(getTestResponse.statusCode).eql(200, JSON.stringify(getTestResponse.body));
getTestResponse.body.artillery_test.should.eql(expectedResult);
});

it('creates two simple tests, get a specific test, and than get list of all tests', async function(){
let requestBody = require('../../testExamples/Simple_test')(dslName).test;
Expand Down
8 changes: 6 additions & 2 deletions ui/src/features/components/TestForm/StepForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export default (props) => {
onChangeValue(step);
};

const { step, editMode } = props;
const { step } = props;
const disableSampleBody = step.method === 'GET';
const jsonObjectKey = step.method === 'GET' ? 'get' : 'not-get';

return (
<div style={{ display: 'flex', flexDirection: 'column', width: '100%' }}>
<div className={style['http-methods-request-options-wrapper']}>
Expand All @@ -85,8 +88,9 @@ export default (props) => {
<DynamicKeyValueInput value={step.captures} onAdd={onAddCapture} onChange={onCaptureChange} keyHintText={'$.id'} valueHintText={'id'} />
Body:
<JSONInput
key={jsonObjectKey}
id='a_unique_id'
placeholder={step.body || (editMode ? {} : sampleObject)}
placeholder={step.body || (disableSampleBody ? undefined : sampleObject)}
colors={{
default: 'black',
background: 'white',
Expand Down

0 comments on commit e53c76f

Please sign in to comment.