Commit b1d71f2a authored by Ben Wheeler's avatar Ben Wheeler

revised join flow tests

parent 7b2e7582
...@@ -97,8 +97,8 @@ describe('JoinFlow', () => { ...@@ -97,8 +97,8 @@ describe('JoinFlow', () => {
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj); joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled(); expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: false, errorAllowsTryAgain: false,
errorMsg: 'registration.problemsAre "username: This field is required."' errorMsg: 'registration.problemsAre: "username: This field is required."'
}); });
}); });
...@@ -120,7 +120,7 @@ describe('JoinFlow', () => { ...@@ -120,7 +120,7 @@ describe('JoinFlow', () => {
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj); joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled(); expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: false, errorAllowsTryAgain: false,
errorMsg: null errorMsg: null
}); });
}); });
...@@ -142,7 +142,7 @@ describe('JoinFlow', () => { ...@@ -142,7 +142,7 @@ describe('JoinFlow', () => {
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj); joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled(); expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: false, errorAllowsTryAgain: false,
errorMsg: null errorMsg: null
}); });
}); });
...@@ -164,7 +164,7 @@ describe('JoinFlow', () => { ...@@ -164,7 +164,7 @@ describe('JoinFlow', () => {
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj); joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled(); expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: true errorAllowsTryAgain: true
}); });
}); });
...@@ -173,7 +173,7 @@ describe('JoinFlow', () => { ...@@ -173,7 +173,7 @@ describe('JoinFlow', () => {
joinFlowInstance.setState({}); joinFlowInstance.setState({});
joinFlowInstance.handleCaptchaError(); joinFlowInstance.handleCaptchaError();
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: false, errorAllowsTryAgain: false,
errorMsg: 'registration.errorCaptcha' errorMsg: 'registration.errorCaptcha'
}); });
}); });
...@@ -214,13 +214,13 @@ describe('JoinFlow', () => { ...@@ -214,13 +214,13 @@ describe('JoinFlow', () => {
expect(progressionWrapper).toHaveLength(1); expect(progressionWrapper).toHaveLength(1);
}); });
test('when numAttempts is 0 and registrationError canTryAgain is true, ' + test('when numAttempts is 0 and registrationError errorAllowsTryAgain is true, ' +
'RegistrationErrorStep receives canTryAgain prop with value true', () => { 'RegistrationErrorStep receives errorAllowsTryAgain prop with value true', () => {
const joinFlowWrapper = getJoinFlowWrapper(); const joinFlowWrapper = getJoinFlowWrapper();
joinFlowWrapper.instance().setState({ joinFlowWrapper.instance().setState({
numAttempts: 0, numAttempts: 0,
registrationError: { registrationError: {
canTryAgain: true, errorAllowsTryAgain: true,
errorMsg: 'halp there is a errors!!' errorMsg: 'halp there is a errors!!'
} }
}); });
...@@ -228,13 +228,13 @@ describe('JoinFlow', () => { ...@@ -228,13 +228,13 @@ describe('JoinFlow', () => {
expect(registrationErrorWrapper.first().props().canTryAgain).toEqual(true); expect(registrationErrorWrapper.first().props().canTryAgain).toEqual(true);
}); });
test('when numAttempts is 1 and registrationError canTryAgain is true, ' + test('when numAttempts is 1 and registrationError errorAllowsTryAgain is true, ' +
'RegistrationErrorStep receives canTryAgain prop with value true', () => { 'RegistrationErrorStep receives errorAllowsTryAgain prop with value true', () => {
const joinFlowWrapper = getJoinFlowWrapper(); const joinFlowWrapper = getJoinFlowWrapper();
joinFlowWrapper.instance().setState({ joinFlowWrapper.instance().setState({
numAttempts: 1, numAttempts: 1,
registrationError: { registrationError: {
canTryAgain: true, errorAllowsTryAgain: true,
errorMsg: 'halp there is a errors!!' errorMsg: 'halp there is a errors!!'
} }
}); });
...@@ -242,13 +242,13 @@ describe('JoinFlow', () => { ...@@ -242,13 +242,13 @@ describe('JoinFlow', () => {
expect(registrationErrorWrapper.first().props().canTryAgain).toEqual(true); expect(registrationErrorWrapper.first().props().canTryAgain).toEqual(true);
}); });
test('when numAttempts is 2 and registrationError canTryAgain is true, ' + test('when numAttempts is 2 and registrationError errorAllowsTryAgain is true, ' +
'RegistrationErrorStep receives canTryAgain prop with value false', () => { 'RegistrationErrorStep receives errorAllowsTryAgain prop with value false', () => {
const joinFlowWrapper = getJoinFlowWrapper(); const joinFlowWrapper = getJoinFlowWrapper();
joinFlowWrapper.instance().setState({ joinFlowWrapper.instance().setState({
numAttempts: 2, numAttempts: 2,
registrationError: { registrationError: {
canTryAgain: true, errorAllowsTryAgain: true,
errorMsg: 'halp there is a errors!!' errorMsg: 'halp there is a errors!!'
} }
}); });
...@@ -256,13 +256,13 @@ describe('JoinFlow', () => { ...@@ -256,13 +256,13 @@ describe('JoinFlow', () => {
expect(registrationErrorWrapper.first().props().canTryAgain).toEqual(false); expect(registrationErrorWrapper.first().props().canTryAgain).toEqual(false);
}); });
test('when numAttempts is 0 and registrationError canTryAgain is false, ' + test('when numAttempts is 0 and registrationError errorAllowsTryAgain is false, ' +
'RegistrationErrorStep receives canTryAgain prop with value false', () => { 'RegistrationErrorStep receives errorAllowsTryAgain prop with value false', () => {
const joinFlowWrapper = getJoinFlowWrapper(); const joinFlowWrapper = getJoinFlowWrapper();
joinFlowWrapper.instance().setState({ joinFlowWrapper.instance().setState({
numAttempts: 0, numAttempts: 0,
registrationError: { registrationError: {
canTryAgain: false, errorAllowsTryAgain: false,
errorMsg: 'halp there is a errors!!' errorMsg: 'halp there is a errors!!'
} }
}); });
...@@ -304,80 +304,80 @@ describe('JoinFlow', () => { ...@@ -304,80 +304,80 @@ describe('JoinFlow', () => {
expect(formDataReference).not.toEqual(joinFlowInstance.state.formData); expect(formDataReference).not.toEqual(joinFlowInstance.state.formData);
}); });
test('getBodyErrors returns object of errors', () => { test('getErrorsFromResponse returns object of errors', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const bodyErrors = joinFlowInstance.getBodyErrors(null, responseBodyMultipleErrs, {statusCode: 200}); const errorsFromResponse =
expect(bodyErrors).toEqual({ joinFlowInstance.getErrorsFromResponse(null, responseBodyMultipleErrs, {statusCode: 200});
username: ['This field is required.'], expect(errorsFromResponse).toEqual([
recaptcha: ['Incorrect, please try again.'] {
}); fieldName: 'username',
}); errorStr: 'This field is required.'
}, {
test('getBodyErrors called with non-null err returns falsy', () => { fieldName: 'recaptcha',
const joinFlowInstance = getJoinFlowWrapper().instance(); errorStr: 'Incorrect, please try again.'
const bodyErrors = joinFlowInstance.getBodyErrors({}, responseBodyMultipleErrs, {statusCode: 200}); }
expect(bodyErrors).toBeFalsy(); ]);
}); });
test('getBodyErrors called with non-200 status code returns falsy', () => { test('getErrorsFromResponse called with non-null err returns empty array', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const bodyErrors = joinFlowInstance.getBodyErrors({}, responseBodyMultipleErrs, {statusCode: 400}); const errorsFromResponse =
expect(bodyErrors).toBeFalsy(); joinFlowInstance.getErrorsFromResponse({}, responseBodyMultipleErrs, {statusCode: 200});
expect(errorsFromResponse).toEqual([]);
}); });
test('getSingleError returns single error, when given response body with only one error', () => { test('getErrorsFromResponse called with non-200 status code returns empty array', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const bodyErrors = joinFlowInstance.getBodyErrors(null, responseBodySingleErr, {statusCode: 200}); const errorsFromResponse =
const singleError = joinFlowInstance.getSingleError(bodyErrors); joinFlowInstance.getErrorsFromResponse({}, responseBodyMultipleErrs, {statusCode: 400});
expect(singleError).toEqual({ expect(errorsFromResponse).toEqual([]);
fieldName: 'recaptcha',
errorStr: 'Incorrect, please try again.'
});
}); });
test('getSingleError returns falsy, when given response body with multiple errors', () => { test('getErrorsFromResponse gets single error, when given response body with only one error', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const bodyErrors = joinFlowInstance.getBodyErrors(null, responseBodyMultipleErrs, {statusCode: 200}); const errorsFromResponse =
const singleError = joinFlowInstance.getSingleError(bodyErrors); joinFlowInstance.getErrorsFromResponse(null, responseBodySingleErr, {statusCode: 200});
expect(singleError).toBeFalsy(); expect(errorsFromResponse.length).toEqual(1);
}); });
test('getCustomErrMsg string when given response body with multiple errors', () => { test('getCustomErrMsg string when given response body with multiple errors', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const bodyErrors = joinFlowInstance.getBodyErrors(null, responseBodyMultipleErrs, {statusCode: 200}); const errorsFromResponse =
const customErrMsg = joinFlowInstance.getCustomErrMsg(bodyErrors); joinFlowInstance.getErrorsFromResponse(null, responseBodyMultipleErrs, {statusCode: 200});
expect(customErrMsg).toEqual('registration.problemsAre "username: This field is required.; ' + const customErrMsg = joinFlowInstance.getCustomErrMsg(errorsFromResponse);
expect(customErrMsg).toEqual('registration.problemsAre: "username: This field is required.; ' +
'recaptcha: Incorrect, please try again."'); 'recaptcha: Incorrect, please try again."');
}); });
test('getCustomErrMsg string when given response body with single error', () => { test('getCustomErrMsg string when given response body with single error', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const bodyErrors = joinFlowInstance.getBodyErrors(null, responseBodySingleErr, {statusCode: 200}); const errorsFromResponse =
const customErrMsg = joinFlowInstance.getCustomErrMsg(bodyErrors); joinFlowInstance.getErrorsFromResponse(null, responseBodySingleErr, {statusCode: 200});
expect(customErrMsg).toEqual('registration.problemsAre "recaptcha: Incorrect, please try again."'); const customErrMsg = joinFlowInstance.getCustomErrMsg(errorsFromResponse);
expect(customErrMsg).toEqual('registration.problemsAre: "recaptcha: Incorrect, please try again."');
}); });
test('getRegistrationSuccess returns true when given response body with single error', () => { test('registrationIsSuccessful returns true when given response body with single error', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const success = joinFlowInstance.getRegistrationSuccess(null, responseBodySuccess, {statusCode: 200}); const success = joinFlowInstance.registrationIsSuccessful(null, responseBodySuccess, {statusCode: 200});
expect(success).toEqual(true); expect(success).toEqual(true);
}); });
test('getRegistrationSuccess returns false when given status code not 200', () => { test('registrationIsSuccessful returns false when given status code not 200', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const success = joinFlowInstance.getRegistrationSuccess(null, responseBodySuccess, {statusCode: 500}); const success = joinFlowInstance.registrationIsSuccessful(null, responseBodySuccess, {statusCode: 500});
expect(success).toEqual(false); expect(success).toEqual(false);
}); });
test('getRegistrationSuccess returns false when given body with success field false', () => { test('registrationIsSuccessful returns false when given body with success field false', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const success = joinFlowInstance.getRegistrationSuccess(null, responseBodySingleErr, {statusCode: 200}); const success = joinFlowInstance.registrationIsSuccessful(null, responseBodySingleErr, {statusCode: 200});
expect(success).toEqual(false); expect(success).toEqual(false);
}); });
test('getRegistrationSuccess returns false when given non null err', () => { test('registrationIsSuccessful returns false when given non null err', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
const success = joinFlowInstance.getRegistrationSuccess({}, responseBodySuccess, {statusCode: 200}); const success = joinFlowInstance.registrationIsSuccessful({}, responseBodySuccess, {statusCode: 200});
expect(success).toEqual(false); expect(success).toEqual(false);
}); });
...@@ -396,7 +396,7 @@ describe('JoinFlow', () => { ...@@ -396,7 +396,7 @@ describe('JoinFlow', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
joinFlowInstance.handleRegistrationResponse(null, responseBodySingleErr, {statusCode: 200}); joinFlowInstance.handleRegistrationResponse(null, responseBodySingleErr, {statusCode: 200});
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: false, errorAllowsTryAgain: false,
errorMsg: 'registration.errorCaptcha' errorMsg: 'registration.errorCaptcha'
}); });
}); });
...@@ -405,8 +405,8 @@ describe('JoinFlow', () => { ...@@ -405,8 +405,8 @@ describe('JoinFlow', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
joinFlowInstance.handleRegistrationResponse(null, responseBodyMultipleErrs, {statusCode: 200}); joinFlowInstance.handleRegistrationResponse(null, responseBodyMultipleErrs, {statusCode: 200});
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: false, errorAllowsTryAgain: false,
errorMsg: 'registration.problemsAre "username: This field is required.; ' + errorMsg: 'registration.problemsAre: "username: This field is required.; ' +
'recaptcha: Incorrect, please try again."' 'recaptcha: Incorrect, please try again."'
}); });
}); });
...@@ -415,7 +415,7 @@ describe('JoinFlow', () => { ...@@ -415,7 +415,7 @@ describe('JoinFlow', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
joinFlowInstance.handleRegistrationResponse({}, responseBodyMultipleErrs, {statusCode: 200}); joinFlowInstance.handleRegistrationResponse({}, responseBodyMultipleErrs, {statusCode: 200});
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: true errorAllowsTryAgain: true
}); });
}); });
...@@ -423,7 +423,7 @@ describe('JoinFlow', () => { ...@@ -423,7 +423,7 @@ describe('JoinFlow', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
joinFlowInstance.handleRegistrationResponse({}, responseBodyMultipleErrs, {statusCode: 400}); joinFlowInstance.handleRegistrationResponse({}, responseBodyMultipleErrs, {statusCode: 400});
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: true errorAllowsTryAgain: true
}); });
}); });
...@@ -431,8 +431,7 @@ describe('JoinFlow', () => { ...@@ -431,8 +431,7 @@ describe('JoinFlow', () => {
const joinFlowInstance = getJoinFlowWrapper().instance(); const joinFlowInstance = getJoinFlowWrapper().instance();
joinFlowInstance.handleRegistrationResponse(null, responseBodyMultipleErrs, {statusCode: 500}); joinFlowInstance.handleRegistrationResponse(null, responseBodyMultipleErrs, {statusCode: 500});
expect(joinFlowInstance.state.registrationError).toEqual({ expect(joinFlowInstance.state.registrationError).toEqual({
canTryAgain: false, errorAllowsTryAgain: true
errorMsg: null
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment