This repository has been archived by the owner on May 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Display error when service instance creation fails #1173
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import style from 'cloudgov-style/css/cloudgov-style.css'; | ||
|
||
import createStyler from '../../util/create_styler'; | ||
|
||
const propTypes = { message: PropTypes.string }; | ||
const defaultProps = { message: '' }; | ||
|
||
export default class FormError extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.styler = createStyler(style); | ||
} | ||
|
||
render() { | ||
return ( | ||
<span className={ this.styler('error_message')}> | ||
{ this.props.message } | ||
</span> | ||
); | ||
} | ||
} | ||
const FormError = ({ message }) => | ||
<span className="error_message"> | ||
{ message } | ||
</span>; | ||
|
||
FormError.propTypes = propTypes; | ||
FormError.defaultProps = defaultProps; | ||
|
||
export default FormError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,8 +357,7 @@ describe('serviceActions', function() { | |
}); | ||
|
||
describe('createdInstance()', function() { | ||
it('should dispatch a server event of type instance created with service', | ||
function() { | ||
it('dispatchs a server event of type instance created with service', () => { | ||
var expectedInstance = { guid: 'asdfas' }; | ||
|
||
let expectedParams = { | ||
|
@@ -373,19 +372,47 @@ describe('serviceActions', function() { | |
}); | ||
}); | ||
|
||
describe('errorCreateInstance()', function() { | ||
it('should dispatch a server event of type error create instance', function() { | ||
var expectedErr = { status: 400 }; | ||
describe('errorCreateInstance()', () => { | ||
const type = serviceActionTypes.SERVICE_INSTANCE_CREATE_ERROR; | ||
let spy; | ||
|
||
let expectedParams = { | ||
error: expectedErr | ||
} | ||
let spy = setupServerSpy(sandbox); | ||
beforeEach(() => { | ||
spy = sandbox.spy(AppDispatcher, 'handleServerAction'); | ||
}); | ||
|
||
serviceActions.errorCreateInstance(expectedErr); | ||
afterEach(() => { | ||
spy.restore(); | ||
}); | ||
|
||
assertAction(spy, serviceActionTypes.SERVICE_INSTANCE_CREATE_ERROR, | ||
expectedParams); | ||
describe('server fault', () => { | ||
it('dispatches the correct error type and a code 500', () => { | ||
const originalError = { message: 'Bad error', stack: [] }; | ||
const actual = { code: 500 }; | ||
|
||
serviceActions.errorCreateInstance(originalError); | ||
|
||
const actionInfo = spy.getCall(0).args[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not using the test helpers here as I was having a hard time getting the test to validate when the arguments passed to the dispatch function are objects. |
||
const { type, error } = actionInfo; | ||
|
||
expect(spy).toHaveBeenCalledOnce(); | ||
expect(actionInfo.type).toEqual(type); | ||
expect(error).toEqual(actual); | ||
}); | ||
}); | ||
|
||
describe('API error/malformed request', () => { | ||
it('dispatches the correct error type and error data object', () => { | ||
const originalError = { response: { data: { hey: 'there' } } }; | ||
|
||
serviceActions.errorCreateInstance(originalError); | ||
|
||
const actionInfo = spy.getCall(0).args[0]; | ||
const { type, error } = actionInfo; | ||
|
||
expect(spy).toHaveBeenCalledOnce(); | ||
expect(actionInfo.type).toEqual(type); | ||
expect(error).toEqual(originalError.response.data); | ||
}); | ||
}); | ||
}); | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
static_src/test/unit/components/create_service_instance.spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import '../../global_setup'; | ||
|
||
import React from 'react'; | ||
import CreateServiceInstance from '../../../components/create_service_instance.jsx'; | ||
import FormError from '../../../components/form/form_error.jsx'; | ||
import Immutable from 'immutable'; | ||
import SpaceStore from '../../../stores/space_store'; | ||
import ServiceInstanceStore from '../../../stores/service_instance_store'; | ||
import { shallow } from 'enzyme'; | ||
|
||
describe('<CreateServiceInstance />', () => { | ||
beforeEach(() => { | ||
ServiceInstanceStore._createError = { description: 'Bad stuff everyone' }; | ||
}); | ||
|
||
it('displays an error message when ServiceInstanceStore has one', () => { | ||
SpaceStore._data = Immutable.fromJS([]); | ||
|
||
const wrapper = shallow(<CreateServiceInstance servicePlan={ {} } />); | ||
|
||
expect(wrapper.find(FormError).length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coming from a non-JS perspective:
it looks like
(response && response.data)
could evaluate to true or false.if true, safeError would be set to true.
if false, it would set safeError to {code: 500};
Now your tests, tell me it doesn't work that way, but just could be a little confusing at first glance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, don't you also need
error_code
to make sure this is a safe error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using this construct in JS, if the first argument evaluates to
true
, and the second argument is also true, the second argument will be executed. In this instance, executing means storing the value of the second argument in a variable, but you could, for example, pass a function as the second argument.If the second argument is also false, the fallback will be executed instead.
I concede that this might look a little confusing but it is a pretty common in JS.
If I misunderstood the question, and you already knew this, sorry 😬 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcscottiii For your second comment,
error_code
needn't be present, the store checks for the existence of one and returns the generic 500 error message if it isn't present.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the first one, I've seen it done like this with ternary operators commonly.
condition ? happy case : sad case
but sounds good.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the second one: ahh i gotcha.