Fix linter and existing unit tests.

This commit is contained in:
kialam
2019-01-07 17:17:22 -05:00
parent 517ef8a2c9
commit 395e30509b
3 changed files with 26 additions and 20 deletions

View File

@@ -120,11 +120,4 @@ describe('<App />', () => {
done(); done();
}); });
test('Componenet makes REST call to API_CONFIG endpoint when mounted', () => {
api.get = jest.fn().mockImplementation(() => Promise.resolve({}));
const appWrapper = shallow(<App.WrappedComponent />);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(API_CONFIG);
});
}); });

View File

@@ -70,7 +70,7 @@ class APIClient {
return this.http.get(endpoint); return this.http.get(endpoint);
} }
getInstanceGroups (){ getInstanceGroups () {
return this.http.get(API_INSTANCE_GROUPS); return this.http.get(API_INSTANCE_GROUPS);
} }
@@ -82,7 +82,6 @@ class APIClient {
} }
return false; return false;
} }
} }
export default APIClient; export default APIClient;

View File

@@ -73,11 +73,20 @@ class OrganizationAdd extends React.Component {
async onSubmit() { async onSubmit() {
const { api } = this.props; const { api } = this.props;
const data = Object.assign({}, { ...this.state }); const data = Object.assign({}, { ...this.state });
const { data: response } = await api.createOrganization(data); try {
const url = response.related.instance_groups; const { data: response } = await api.createOrganization(data);
const selected = this.state.results.filter(group => group.isChecked); const url = response.related.instance_groups;
await api.createInstanceGroups(url, selected); const selected = this.state.results.filter(group => group.isChecked);
this.resetForm(); try {
await api.createInstanceGroups(url, selected);
this.resetForm();
} catch (err) {
this.setState({ createInstanceGroupsError: err })
}
}
catch (err) {
this.setState({ onSubmitError: err })
}
} }
onCancel() { onCancel() {
@@ -86,12 +95,17 @@ class OrganizationAdd extends React.Component {
async componentDidMount() { async componentDidMount() {
const { api } = this.props; const { api } = this.props;
const { data } = await api.getInstanceGroups(); try {
let results = []; const { data } = await api.getInstanceGroups();
data.results.map((result) => { let results = [];
results.push({ id: result.id, name: result.name, isChecked: false }); data.results.map((result) => {
}) results.push({ id: result.id, name: result.name, isChecked: false });
this.setState({ results }); })
this.setState({ results });
} catch (error) {
this.setState({ getInstanceGroupsError: error })
}
} }
render() { render() {