Skip to content

Commit

Permalink
feat(deployment-tool): tests covering new validation logic
Browse files Browse the repository at this point in the history
Closes #1709
  • Loading branch information
oguzeroglu committed Mar 10, 2020
1 parent dacd5d3 commit 88cb646
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,79 @@ describe('<DeploymentConfigModal>', () => {
done();
});
});


it('should hide username password fields if auth is not needed', (done) => {

// given
const configuration = {
deployment: {
tenantId: '',
name: 'diagram'
},
endpoint: {
url: 'http://localhost:8088/engine-rest',
authType: AuthTypes.basic
}
};

const validator = new MockValidator({
validateConnectionWithoutCredentials: () => new Promise((resolve, reject) => {
resolve(null);
})
});

const {
wrapper
} = createModal({
configuration,
validator
}, mount);

// then
setTimeout(() => {
wrapper.update();
expect(wrapper.find('[id="endpoint.username"]')).to.have.length(0);
expect(wrapper.find('[id="endpoint.password"]')).to.have.length(0);
done();
});
});


it('should hide token field if auth is not needed', (done) => {

// given
const configuration = {
deployment: {
tenantId: '',
name: 'diagram'
},
endpoint: {
url: 'http://localhost:8088/engine-rest',
authType: AuthTypes.bearer
}
};

const validator = new MockValidator({
validateConnectionWithoutCredentials: () => new Promise((resolve, reject) => {
resolve(null);
})
});

const {
wrapper
} = createModal({
configuration,
validator
}, mount);

// then
setTimeout(() => {
wrapper.update();
expect(wrapper.find('[id="endpoint.token"]')).to.have.length(0);
done();
});
});
});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* except in compliance with the MIT License.
*/

/* global sinon */

import DeploymentConfigValidator from '../DeploymentConfigValidator';
import AuthTypes from '../../shared/AuthTypes';

Expand All @@ -17,7 +19,11 @@ const EMPTY_USERNAME_ERROR = 'Username must not be empty.';
const EMPTY_PASSWORD_ERROR = 'Password must not be empty.';
const EMPTY_TOKEN_ERROR = 'Token must not be empty.';
const INVALID_URL_ERROR = 'Endpoint URL must start with "http://" or "https://".';
const NON_COMPLETE_ERROR = 'Should point to a running Camunda Engine REST API.';

const ENDPOINT_URL_FIELDNAME = 'endpoint.url';

const noop = () => {};

describe('<DeploymentConfigValidator>', () => {

Expand Down Expand Up @@ -105,4 +111,123 @@ describe('<DeploymentConfigValidator>', () => {
expect(validate('').token).to.eql(EMPTY_TOKEN_ERROR);
expect(validate('token').token).to.not.exist;
});


it('should validate endpoint URL completeness delayed if not submitting', (done) => {

// given
const setFieldErrorSpy = sinon.spy();
const onAuthDetection = noop;
const isOnBeforeSubmit = false;

const nonCompleteURL = 'https://';

// when
const result = validator.validateEndpointURL(
nonCompleteURL, setFieldErrorSpy, isOnBeforeSubmit, onAuthDetection
);

// then
expect(result).to.be.null;
expect(setFieldErrorSpy).to.not.have.been.called;
setTimeout(() => {
expect(setFieldErrorSpy).to.have.been.calledWith(ENDPOINT_URL_FIELDNAME, NON_COMPLETE_ERROR);
done();
}, 1100);
});


it('should validate endpoint URL completeness non delayed if submitting', () => {

// given
const setFieldErrorSpy = noop;
const onAuthDetection = noop;
const isOnBeforeSubmit = true;

const nonCompleteURL = 'https://';

// when
const result = validator.validateEndpointURL(
nonCompleteURL, setFieldErrorSpy, isOnBeforeSubmit, onAuthDetection
);

// then
expect(result).to.be.eql(NON_COMPLETE_ERROR);
});


it('should not validate username if password is validated when not submitting', () => {

// given
const validateField = noop;
const isOnBeforeSubmit = false;
const username = '';
const password = 'passsword';

// when
validator.validatePassword('', validateField, isOnBeforeSubmit); // first time
validator.validateUsername(username, isOnBeforeSubmit); // username validation fails
validator.validatePassword(password, validateField, isOnBeforeSubmit); // password is changed

// then
const result = validator.validateUsername(username, isOnBeforeSubmit);
expect(result).to.be.null;
});


it('should validate username if password is validated when submitting', () => {

// given
const validateField = noop;
const isOnBeforeSubmit = false;
const username = '';
const password = 'passsword';

// when
validator.validatePassword('', validateField, isOnBeforeSubmit); // first time
validator.validateUsername(username, isOnBeforeSubmit); // username validation fails
validator.validatePassword(password, validateField, isOnBeforeSubmit); // password is changed

// then
const result = validator.validateUsername(username, true);
expect(result).to.not.be.null;
});


it('should not validate password if username is validated when not submitting', () => {

// given
const validateField = noop;
const isOnBeforeSubmit = false;
const username = 'username';
const password = '';

// when
validator.validateUsername('', isOnBeforeSubmit); // first time
validator.validatePassword(password, validateField, isOnBeforeSubmit); // password validation fails
validator.validateUsername(username, isOnBeforeSubmit); // username is changed

// then
const result = validator.validatePassword(password, validateField, isOnBeforeSubmit);
expect(result).to.be.null;
});


it('should validate password if username is validated when submitting', () => {

// given
const validateField = noop;
const isOnBeforeSubmit = false;
const username = 'username';
const password = '';

// when
validator.validateUsername('', isOnBeforeSubmit); // first time
validator.validatePassword(password, validateField, isOnBeforeSubmit); // password validation fails
validator.validateUsername(username, isOnBeforeSubmit); // username is changed

// then
const result = validator.validatePassword(password, validateField, true);
expect(result).to.not.be.null;
});
});

0 comments on commit 88cb646

Please sign in to comment.