mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-26 17:16:11 -05:00
revised join flow and registration error tests
This commit is contained in:
parent
0305fff670
commit
b2e7a0c9eb
2 changed files with 63 additions and 115 deletions
|
@ -57,117 +57,6 @@ describe('JoinFlow', () => {
|
||||||
.dive(); // unwrap injectIntl(JoinFlow)
|
.dive(); // unwrap injectIntl(JoinFlow)
|
||||||
};
|
};
|
||||||
|
|
||||||
test('handleRegistrationResponse with successful response', () => {
|
|
||||||
const props = {
|
|
||||||
refreshSession: jest.fn()
|
|
||||||
};
|
|
||||||
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
|
||||||
const responseErr = null;
|
|
||||||
const responseBody = [
|
|
||||||
{
|
|
||||||
success: true
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const responseObj = {
|
|
||||||
statusCode: 200
|
|
||||||
};
|
|
||||||
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
|
|
||||||
expect(joinFlowInstance.props.refreshSession).toHaveBeenCalled();
|
|
||||||
expect(joinFlowInstance.state.registrationError).toBe(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('handleRegistrationResponse with healthy response, indicating failure', () => {
|
|
||||||
const props = {
|
|
||||||
refreshSession: jest.fn()
|
|
||||||
};
|
|
||||||
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
|
||||||
const responseErr = null;
|
|
||||||
const responseBody = [
|
|
||||||
{
|
|
||||||
msg: 'This field is required.',
|
|
||||||
errors: {
|
|
||||||
username: ['This field is required.']
|
|
||||||
},
|
|
||||||
success: false
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const responseObj = {
|
|
||||||
statusCode: 200
|
|
||||||
};
|
|
||||||
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
|
|
||||||
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
|
|
||||||
expect(joinFlowInstance.state.registrationError).toEqual({
|
|
||||||
errorAllowsTryAgain: false,
|
|
||||||
errorMsg: 'registration.problemsAre: "username: This field is required."'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('handleRegistrationResponse with failure response, with error fields missing', () => {
|
|
||||||
const props = {
|
|
||||||
refreshSession: jest.fn()
|
|
||||||
};
|
|
||||||
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
|
||||||
const responseErr = null;
|
|
||||||
const responseBody = [
|
|
||||||
{
|
|
||||||
msg: 'This field is required.',
|
|
||||||
success: false
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const responseObj = {
|
|
||||||
statusCode: 200
|
|
||||||
};
|
|
||||||
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
|
|
||||||
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
|
|
||||||
expect(joinFlowInstance.state.registrationError).toEqual({
|
|
||||||
errorAllowsTryAgain: false,
|
|
||||||
errorMsg: null
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('handleRegistrationResponse with failure response, with no text explanation', () => {
|
|
||||||
const props = {
|
|
||||||
refreshSession: jest.fn()
|
|
||||||
};
|
|
||||||
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
|
||||||
const responseErr = null;
|
|
||||||
const responseBody = [
|
|
||||||
{
|
|
||||||
success: false
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const responseObj = {
|
|
||||||
statusCode: 200
|
|
||||||
};
|
|
||||||
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
|
|
||||||
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
|
|
||||||
expect(joinFlowInstance.state.registrationError).toEqual({
|
|
||||||
errorAllowsTryAgain: false,
|
|
||||||
errorMsg: null
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('handleRegistrationResponse with failure status code', () => {
|
|
||||||
const props = {
|
|
||||||
refreshSession: jest.fn()
|
|
||||||
};
|
|
||||||
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
|
||||||
const responseErr = null;
|
|
||||||
const responseBody = [
|
|
||||||
{
|
|
||||||
success: false
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const responseObj = {
|
|
||||||
statusCode: 400
|
|
||||||
};
|
|
||||||
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
|
|
||||||
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
|
|
||||||
expect(joinFlowInstance.state.registrationError).toEqual({
|
|
||||||
errorAllowsTryAgain: true
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('handleCaptchaError gives state with captcha message', () => {
|
test('handleCaptchaError gives state with captcha message', () => {
|
||||||
const joinFlowInstance = getJoinFlowWrapper().instance();
|
const joinFlowInstance = getJoinFlowWrapper().instance();
|
||||||
joinFlowInstance.setState({});
|
joinFlowInstance.setState({});
|
||||||
|
@ -388,6 +277,7 @@ describe('JoinFlow', () => {
|
||||||
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
||||||
joinFlowInstance.handleRegistrationResponse(null, responseBodySuccess, {statusCode: 200});
|
joinFlowInstance.handleRegistrationResponse(null, responseBodySuccess, {statusCode: 200});
|
||||||
expect(joinFlowInstance.state.registrationError).toEqual(null);
|
expect(joinFlowInstance.state.registrationError).toEqual(null);
|
||||||
|
expect(joinFlowInstance.props.refreshSession).toHaveBeenCalled();
|
||||||
expect(joinFlowInstance.state.step).toEqual(1);
|
expect(joinFlowInstance.state.step).toEqual(1);
|
||||||
expect(joinFlowInstance.state.waiting).toBeFalsy();
|
expect(joinFlowInstance.state.waiting).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
@ -401,6 +291,29 @@ describe('JoinFlow', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('handleRegistrationResponse with failure response, with error fields missing', () => {
|
||||||
|
const props = {
|
||||||
|
refreshSession: jest.fn()
|
||||||
|
};
|
||||||
|
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
||||||
|
const responseErr = null;
|
||||||
|
const responseBody = [
|
||||||
|
{
|
||||||
|
msg: 'This field is required.',
|
||||||
|
success: false
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const responseObj = {
|
||||||
|
statusCode: 200
|
||||||
|
};
|
||||||
|
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
|
||||||
|
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
|
||||||
|
expect(joinFlowInstance.state.registrationError).toEqual({
|
||||||
|
errorAllowsTryAgain: false,
|
||||||
|
errorMsg: null
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('handleRegistrationResponse when passed body with unfamiliar server error', () => {
|
test('handleRegistrationResponse when passed body with unfamiliar server error', () => {
|
||||||
const joinFlowInstance = getJoinFlowWrapper().instance();
|
const joinFlowInstance = getJoinFlowWrapper().instance();
|
||||||
joinFlowInstance.handleRegistrationResponse(null, responseBodyMultipleErrs, {statusCode: 200});
|
joinFlowInstance.handleRegistrationResponse(null, responseBodyMultipleErrs, {statusCode: 200});
|
||||||
|
@ -411,6 +324,28 @@ describe('JoinFlow', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('handleRegistrationResponse with failure response, with no text explanation', () => {
|
||||||
|
const props = {
|
||||||
|
refreshSession: jest.fn()
|
||||||
|
};
|
||||||
|
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
||||||
|
const responseErr = null;
|
||||||
|
const responseBody = [
|
||||||
|
{
|
||||||
|
success: false
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const responseObj = {
|
||||||
|
statusCode: 200
|
||||||
|
};
|
||||||
|
joinFlowInstance.handleRegistrationResponse(responseErr, responseBody, responseObj);
|
||||||
|
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
|
||||||
|
expect(joinFlowInstance.state.registrationError).toEqual({
|
||||||
|
errorAllowsTryAgain: false,
|
||||||
|
errorMsg: null
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('handleRegistrationResponse when passed non null outgoing request error', () => {
|
test('handleRegistrationResponse when passed non null outgoing request error', () => {
|
||||||
const joinFlowInstance = getJoinFlowWrapper().instance();
|
const joinFlowInstance = getJoinFlowWrapper().instance();
|
||||||
joinFlowInstance.handleRegistrationResponse({}, responseBodyMultipleErrs, {statusCode: 200});
|
joinFlowInstance.handleRegistrationResponse({}, responseBodyMultipleErrs, {statusCode: 200});
|
||||||
|
@ -420,8 +355,12 @@ describe('JoinFlow', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('handleRegistrationResponse when passed status 400', () => {
|
test('handleRegistrationResponse when passed status 400', () => {
|
||||||
const joinFlowInstance = getJoinFlowWrapper().instance();
|
const props = {
|
||||||
|
refreshSession: jest.fn()
|
||||||
|
};
|
||||||
|
const joinFlowInstance = getJoinFlowWrapper(props).instance();
|
||||||
joinFlowInstance.handleRegistrationResponse({}, responseBodyMultipleErrs, {statusCode: 400});
|
joinFlowInstance.handleRegistrationResponse({}, responseBodyMultipleErrs, {statusCode: 400});
|
||||||
|
expect(joinFlowInstance.props.refreshSession).not.toHaveBeenCalled();
|
||||||
expect(joinFlowInstance.state.registrationError).toEqual({
|
expect(joinFlowInstance.state.registrationError).toEqual({
|
||||||
errorAllowsTryAgain: true
|
errorAllowsTryAgain: true
|
||||||
});
|
});
|
||||||
|
@ -434,7 +373,4 @@ describe('JoinFlow', () => {
|
||||||
errorAllowsTryAgain: true
|
errorAllowsTryAgain: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('handleErrorNext', () => {
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -38,6 +38,18 @@ describe('RegistrationErrorStep', () => {
|
||||||
expect(errMsgElement.text()).toEqual('halp there is a errors!!');
|
expect(errMsgElement.text()).toEqual('halp there is a errors!!');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('when errorMsg is null, registrationError does not show it', () => {
|
||||||
|
const props = {
|
||||||
|
canTryAgain: true,
|
||||||
|
errorMsg: null,
|
||||||
|
onSubmit: onSubmit
|
||||||
|
};
|
||||||
|
const joinFlowStepWrapper = getRegistrationErrorStepWrapper(props).find(JoinFlowStep);
|
||||||
|
const joinFlowStepInstance = joinFlowStepWrapper.dive();
|
||||||
|
const errMsgElement = joinFlowStepInstance.find('.registration-error-msg');
|
||||||
|
expect(errMsgElement).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
test('when no errorMsg provided, registrationError does not show it', () => {
|
test('when no errorMsg provided, registrationError does not show it', () => {
|
||||||
const props = {
|
const props = {
|
||||||
canTryAgain: true,
|
canTryAgain: true,
|
||||||
|
|
Loading…
Reference in a new issue