Commit aaa16315 authored by Tom Quirk's avatar Tom Quirk

Address maintainer feedback

- add spec for test settings error state
- capture non-user errors in Sentry
parent b2755055
<script> <script>
import { GlButton, GlModalDirective, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui'; import { GlButton, GlModalDirective, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui';
import * as Sentry from '@sentry/browser';
import { mapState, mapActions, mapGetters } from 'vuex'; import { mapState, mapActions, mapGetters } from 'vuex';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { import {
...@@ -114,13 +115,15 @@ export default { ...@@ -114,13 +115,15 @@ export default {
.then(({ data: { error, message = I18N_FETCH_TEST_SETTINGS_DEFAULT_ERROR_MESSAGE } }) => { .then(({ data: { error, message = I18N_FETCH_TEST_SETTINGS_DEFAULT_ERROR_MESSAGE } }) => {
if (error) { if (error) {
eventHub.$emit(VALIDATE_INTEGRATION_FORM_EVENT); eventHub.$emit(VALIDATE_INTEGRATION_FORM_EVENT);
throw new Error(message); this.$toast.show(message);
return;
} }
this.$toast.show(I18N_SUCCESSFUL_CONNECTION_MESSAGE); this.$toast.show(I18N_SUCCESSFUL_CONNECTION_MESSAGE);
}) })
.catch(({ message = I18N_DEFAULT_ERROR_MESSAGE }) => { .catch((error) => {
this.$toast.show(message); this.$toast.show(I18N_DEFAULT_ERROR_MESSAGE);
Sentry.captureException(error);
}) })
.finally(() => { .finally(() => {
this.testingLoading = false; this.testingLoading = false;
......
import axios from 'axios'; import axios from 'axios';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import * as Sentry from '@sentry/browser';
import { setHTMLFixture } from 'helpers/fixtures'; import { setHTMLFixture } from 'helpers/fixtures';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { mockIntegrationProps } from 'jest/integrations/edit/mock_data'; import { mockIntegrationProps } from 'jest/integrations/edit/mock_data';
...@@ -18,12 +19,14 @@ import { ...@@ -18,12 +19,14 @@ import {
I18N_SUCCESSFUL_CONNECTION_MESSAGE, I18N_SUCCESSFUL_CONNECTION_MESSAGE,
VALIDATE_INTEGRATION_FORM_EVENT, VALIDATE_INTEGRATION_FORM_EVENT,
SAVE_INTEGRATION_EVENT, SAVE_INTEGRATION_EVENT,
I18N_DEFAULT_ERROR_MESSAGE,
} from '~/integrations/constants'; } from '~/integrations/constants';
import { createStore } from '~/integrations/edit/store'; import { createStore } from '~/integrations/edit/store';
import eventHub from '~/integrations/edit/event_hub'; import eventHub from '~/integrations/edit/event_hub';
import httpStatus from '~/lib/utils/http_status'; import httpStatus from '~/lib/utils/http_status';
jest.mock('~/integrations/edit/event_hub'); jest.mock('~/integrations/edit/event_hub');
jest.mock('@sentry/browser');
describe('IntegrationForm', () => { describe('IntegrationForm', () => {
const mockToastShow = jest.fn(); const mockToastShow = jest.fn();
...@@ -469,13 +472,14 @@ describe('IntegrationForm', () => { ...@@ -469,13 +472,14 @@ describe('IntegrationForm', () => {
}); });
describe.each` describe.each`
scenario | errorMessage | expectToast scenario | replyStatus | errorMessage | expectToast | expectSentry
${'when test settings succeeds'} | ${'an error'} | ${'an error'} ${'when "test settings" request fails'} | ${httpStatus.INTERNAL_SERVER_ERROR} | ${undefined} | ${I18N_DEFAULT_ERROR_MESSAGE} | ${true}
${'when test settings fails'} | ${undefined} | ${I18N_SUCCESSFUL_CONNECTION_MESSAGE} ${'when "test settings" returns an error'} | ${httpStatus.OK} | ${'an error'} | ${'an error'} | ${false}
`('$scenario', ({ errorMessage, expectToast }) => { ${'when "test settings" succeeds'} | ${httpStatus.OK} | ${undefined} | ${I18N_SUCCESSFUL_CONNECTION_MESSAGE} | ${false}
`('$scenario', ({ replyStatus, errorMessage, expectToast, expectSentry }) => {
beforeEach(async () => { beforeEach(async () => {
mockAxios.onPut(mockTestPath).replyOnce(httpStatus.OK, { mockAxios.onPut(mockTestPath).replyOnce(replyStatus, {
error: Boolean(errorMessage) || undefined, error: Boolean(errorMessage),
message: errorMessage, message: errorMessage,
}); });
...@@ -494,6 +498,10 @@ describe('IntegrationForm', () => { ...@@ -494,6 +498,10 @@ describe('IntegrationForm', () => {
it('sets save button `disabled` prop to `false`', () => { it('sets save button `disabled` prop to `false`', () => {
expect(findSaveButton().props('disabled')).toBe(false); expect(findSaveButton().props('disabled')).toBe(false);
}); });
it(`${expectSentry ? 'does' : 'does not'} capture exception in Sentry`, () => {
expect(Sentry.captureException).toHaveBeenCalledTimes(expectSentry ? 1 : 0);
});
}); });
}); });
}); });
......
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