2021-03-11 19:13:27 +05:30
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { mount, createLocalVue } from '@vue/test-utils';
|
2021-02-22 17:27:13 +05:30
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2021-03-11 19:13:27 +05:30
|
|
|
import VueApollo from 'vue-apollo';
|
2021-04-17 20:07:23 +05:30
|
|
|
import createHttpIntegrationMutation from 'ee_else_ce/alerts_settings/graphql/mutations/create_http_integration.mutation.graphql';
|
|
|
|
import updateHttpIntegrationMutation from 'ee_else_ce/alerts_settings/graphql/mutations/update_http_integration.mutation.graphql';
|
2021-03-08 18:12:59 +05:30
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { useMockIntersectionObserver } from 'helpers/mock_dom_observer';
|
2021-03-11 19:13:27 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-01-29 00:20:46 +05:30
|
|
|
import IntegrationsList from '~/alerts_settings/components/alerts_integrations_list.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import AlertsSettingsForm from '~/alerts_settings/components/alerts_settings_form.vue';
|
2021-04-17 20:07:23 +05:30
|
|
|
import AlertsSettingsWrapper, {
|
|
|
|
i18n,
|
|
|
|
} from '~/alerts_settings/components/alerts_settings_wrapper.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { typeSet } from '~/alerts_settings/constants';
|
2021-01-29 00:20:46 +05:30
|
|
|
import createPrometheusIntegrationMutation from '~/alerts_settings/graphql/mutations/create_prometheus_integration.mutation.graphql';
|
|
|
|
import destroyHttpIntegrationMutation from '~/alerts_settings/graphql/mutations/destroy_http_integration.mutation.graphql';
|
|
|
|
import resetHttpTokenMutation from '~/alerts_settings/graphql/mutations/reset_http_token.mutation.graphql';
|
|
|
|
import resetPrometheusTokenMutation from '~/alerts_settings/graphql/mutations/reset_prometheus_token.mutation.graphql';
|
2021-04-17 20:07:23 +05:30
|
|
|
import updateCurrentHttpIntegrationMutation from '~/alerts_settings/graphql/mutations/update_current_http_integration.mutation.graphql';
|
|
|
|
import updateCurrentPrometheusIntegrationMutation from '~/alerts_settings/graphql/mutations/update_current_prometheus_integration.mutation.graphql';
|
2021-03-11 19:13:27 +05:30
|
|
|
import updatePrometheusIntegrationMutation from '~/alerts_settings/graphql/mutations/update_prometheus_integration.mutation.graphql';
|
|
|
|
import getIntegrationsQuery from '~/alerts_settings/graphql/queries/get_integrations.query.graphql';
|
2021-04-17 20:07:23 +05:30
|
|
|
import alertsUpdateService from '~/alerts_settings/services';
|
2021-01-29 00:20:46 +05:30
|
|
|
import {
|
|
|
|
ADD_INTEGRATION_ERROR,
|
|
|
|
RESET_INTEGRATION_TOKEN_ERROR,
|
|
|
|
UPDATE_INTEGRATION_ERROR,
|
|
|
|
INTEGRATION_PAYLOAD_TEST_ERROR,
|
|
|
|
DELETE_INTEGRATION_ERROR,
|
|
|
|
} from '~/alerts_settings/utils/error_messages';
|
2021-04-17 20:07:23 +05:30
|
|
|
import createFlash, { FLASH_TYPES } from '~/flash';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2021-01-29 00:20:46 +05:30
|
|
|
import {
|
|
|
|
createHttpVariables,
|
|
|
|
updateHttpVariables,
|
|
|
|
createPrometheusVariables,
|
|
|
|
updatePrometheusVariables,
|
2021-04-17 20:07:23 +05:30
|
|
|
HTTP_ID,
|
|
|
|
PROMETHEUS_ID,
|
2021-01-29 00:20:46 +05:30
|
|
|
errorMsg,
|
|
|
|
getIntegrationsQueryResponse,
|
|
|
|
destroyIntegrationResponse,
|
|
|
|
integrationToDestroy,
|
|
|
|
destroyIntegrationResponseWithErrors,
|
|
|
|
} from './mocks/apollo_mock';
|
2021-03-11 19:13:27 +05:30
|
|
|
import mockIntegrations from './mocks/integrations.json';
|
|
|
|
import { defaultAlertSettingsConfig } from './util';
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
jest.mock('~/flash');
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
|
|
|
|
describe('AlertsSettingsWrapper', () => {
|
|
|
|
let wrapper;
|
|
|
|
let fakeApollo;
|
|
|
|
let destroyIntegrationHandler;
|
|
|
|
useMockIntersectionObserver();
|
2021-04-17 20:07:23 +05:30
|
|
|
const httpMappingData = {
|
|
|
|
payloadExample: '{"test: : "field"}',
|
|
|
|
payloadAttributeMappings: [],
|
|
|
|
payloadAlertFields: [],
|
|
|
|
};
|
|
|
|
const httpIntegrations = {
|
|
|
|
list: [
|
|
|
|
{
|
|
|
|
id: mockIntegrations[0].id,
|
|
|
|
...httpMappingData,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: mockIntegrations[1].id,
|
|
|
|
...httpMappingData,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: mockIntegrations[2].id,
|
|
|
|
httpMappingData,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const findLoader = () => wrapper.findComponent(IntegrationsList).findComponent(GlLoadingIcon);
|
|
|
|
const findIntegrationsList = () => wrapper.findComponent(IntegrationsList);
|
2021-01-29 00:20:46 +05:30
|
|
|
const findIntegrations = () => wrapper.find(IntegrationsList).findAll('table tbody tr');
|
2021-04-17 20:07:23 +05:30
|
|
|
const findAddIntegrationBtn = () => wrapper.find('[data-testid="add-integration-btn"]');
|
|
|
|
const findAlertsSettingsForm = () => wrapper.findComponent(AlertsSettingsForm);
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
async function destroyHttpIntegration(localWrapper) {
|
|
|
|
await jest.runOnlyPendingTimers();
|
|
|
|
await localWrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
localWrapper
|
|
|
|
.find(IntegrationsList)
|
|
|
|
.vm.$emit('delete-integration', { id: integrationToDestroy.id });
|
|
|
|
}
|
|
|
|
|
|
|
|
async function awaitApolloDomMock() {
|
|
|
|
await wrapper.vm.$nextTick(); // kick off the DOM update
|
|
|
|
await jest.runOnlyPendingTimers(); // kick off the mocked GQL stuff (promises)
|
|
|
|
await wrapper.vm.$nextTick(); // kick off the DOM update for flash
|
|
|
|
}
|
|
|
|
|
|
|
|
const createComponent = ({ data = {}, provide = {}, loading = false } = {}) => {
|
|
|
|
wrapper = mount(AlertsSettingsWrapper, {
|
|
|
|
data() {
|
|
|
|
return { ...data };
|
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
...defaultAlertSettingsConfig,
|
|
|
|
...provide,
|
|
|
|
},
|
|
|
|
mocks: {
|
|
|
|
$apollo: {
|
|
|
|
mutate: jest.fn(),
|
|
|
|
query: jest.fn(),
|
|
|
|
queries: {
|
|
|
|
integrations: {
|
|
|
|
loading,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function createComponentWithApollo({
|
|
|
|
destroyHandler = jest.fn().mockResolvedValue(destroyIntegrationResponse),
|
|
|
|
} = {}) {
|
|
|
|
localVue.use(VueApollo);
|
|
|
|
destroyIntegrationHandler = destroyHandler;
|
|
|
|
|
|
|
|
const requestHandlers = [
|
|
|
|
[getIntegrationsQuery, jest.fn().mockResolvedValue(getIntegrationsQueryResponse)],
|
|
|
|
[destroyHttpIntegrationMutation, destroyIntegrationHandler],
|
|
|
|
];
|
|
|
|
|
|
|
|
fakeApollo = createMockApollo(requestHandlers);
|
|
|
|
|
|
|
|
wrapper = mount(AlertsSettingsWrapper, {
|
|
|
|
localVue,
|
|
|
|
apolloProvider: fakeApollo,
|
|
|
|
provide: {
|
|
|
|
...defaultAlertSettingsConfig,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
2021-02-22 17:27:13 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('template', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
integrations: { list: mockIntegrations },
|
|
|
|
httpIntegrations: { list: [] },
|
|
|
|
currentIntegration: mockIntegrations[0],
|
|
|
|
},
|
|
|
|
loading: false,
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('renders alerts integrations list and add new integration button by default', () => {
|
|
|
|
expect(findLoader().exists()).toBe(false);
|
|
|
|
expect(findIntegrations()).toHaveLength(mockIntegrations.length);
|
|
|
|
expect(findAddIntegrationBtn().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does NOT render settings form by default', () => {
|
|
|
|
expect(findAlertsSettingsForm().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('hides `add new integration` button and displays setting form on btn click', async () => {
|
|
|
|
const addNewIntegrationBtn = findAddIntegrationBtn();
|
|
|
|
expect(addNewIntegrationBtn.exists()).toBe(true);
|
|
|
|
await addNewIntegrationBtn.trigger('click');
|
|
|
|
expect(findAlertsSettingsForm().exists()).toBe(true);
|
|
|
|
expect(addNewIntegrationBtn.exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows loading indicator inside the IntegrationsList table', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
createComponent({
|
|
|
|
data: { integrations: {} },
|
|
|
|
loading: true,
|
|
|
|
});
|
|
|
|
expect(wrapper.find(IntegrationsList).exists()).toBe(true);
|
|
|
|
expect(findLoader().exists()).toBe(true);
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('Integration updates', () => {
|
|
|
|
beforeEach(() => {
|
2021-01-29 00:20:46 +05:30
|
|
|
createComponent({
|
2021-04-17 20:07:23 +05:30
|
|
|
data: {
|
|
|
|
integrations: { list: mockIntegrations },
|
|
|
|
currentIntegration: mockIntegrations[0],
|
|
|
|
formVisible: true,
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
loading: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('calls `$apollo.mutate` with `createHttpIntegrationMutation`', () => {
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({
|
|
|
|
data: { createHttpIntegrationMutation: { integration: { id: '1' } } },
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
findAlertsSettingsForm().vm.$emit('create-new-integration', {
|
2021-01-29 00:20:46 +05:30
|
|
|
type: typeSet.http,
|
|
|
|
variables: createHttpVariables,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledTimes(1);
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: createHttpIntegrationMutation,
|
|
|
|
update: expect.anything(),
|
|
|
|
variables: createHttpVariables,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls `$apollo.mutate` with `updateHttpIntegrationMutation`', () => {
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({
|
|
|
|
data: { updateHttpIntegrationMutation: { integration: { id: '1' } } },
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
findAlertsSettingsForm().vm.$emit('update-integration', {
|
2021-01-29 00:20:46 +05:30
|
|
|
type: typeSet.http,
|
|
|
|
variables: updateHttpVariables,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: updateHttpIntegrationMutation,
|
|
|
|
variables: updateHttpVariables,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls `$apollo.mutate` with `resetHttpTokenMutation`', () => {
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({
|
|
|
|
data: { resetHttpTokenMutation: { integration: { id: '1' } } },
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
findAlertsSettingsForm().vm.$emit('reset-token', {
|
2021-01-29 00:20:46 +05:30
|
|
|
type: typeSet.http,
|
2021-04-17 20:07:23 +05:30
|
|
|
variables: { id: HTTP_ID },
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: resetHttpTokenMutation,
|
|
|
|
variables: {
|
2021-04-17 20:07:23 +05:30
|
|
|
id: HTTP_ID,
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls `$apollo.mutate` with `createPrometheusIntegrationMutation`', () => {
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({
|
|
|
|
data: { createPrometheusIntegrationMutation: { integration: { id: '2' } } },
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
findAlertsSettingsForm().vm.$emit('create-new-integration', {
|
2021-01-29 00:20:46 +05:30
|
|
|
type: typeSet.prometheus,
|
|
|
|
variables: createPrometheusVariables,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledTimes(1);
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: createPrometheusIntegrationMutation,
|
|
|
|
update: expect.anything(),
|
|
|
|
variables: createPrometheusVariables,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls `$apollo.mutate` with `updatePrometheusIntegrationMutation`', () => {
|
|
|
|
createComponent({
|
2021-04-17 20:07:23 +05:30
|
|
|
data: {
|
|
|
|
integrations: { list: mockIntegrations },
|
|
|
|
currentIntegration: mockIntegrations[3],
|
|
|
|
formVisible: true,
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
loading: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({
|
|
|
|
data: { updatePrometheusIntegrationMutation: { integration: { id: '2' } } },
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
findAlertsSettingsForm().vm.$emit('update-integration', {
|
2021-01-29 00:20:46 +05:30
|
|
|
type: typeSet.prometheus,
|
|
|
|
variables: updatePrometheusVariables,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: updatePrometheusIntegrationMutation,
|
|
|
|
variables: updatePrometheusVariables,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls `$apollo.mutate` with `resetPrometheusTokenMutation`', () => {
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({
|
|
|
|
data: { resetPrometheusTokenMutation: { integration: { id: '1' } } },
|
|
|
|
});
|
2021-04-17 20:07:23 +05:30
|
|
|
findAlertsSettingsForm().vm.$emit('reset-token', {
|
2021-01-29 00:20:46 +05:30
|
|
|
type: typeSet.prometheus,
|
2021-04-17 20:07:23 +05:30
|
|
|
variables: { id: PROMETHEUS_ID },
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: resetPrometheusTokenMutation,
|
|
|
|
variables: {
|
2021-04-17 20:07:23 +05:30
|
|
|
id: PROMETHEUS_ID,
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an error alert when integration creation fails ', async () => {
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockRejectedValue(ADD_INTEGRATION_ERROR);
|
2021-04-17 20:07:23 +05:30
|
|
|
findAlertsSettingsForm().vm.$emit('create-new-integration', {});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({ message: ADD_INTEGRATION_ERROR });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an error alert when integration token reset fails ', async () => {
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockRejectedValue(RESET_INTEGRATION_TOKEN_ERROR);
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
findAlertsSettingsForm().vm.$emit('reset-token', {});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({ message: RESET_INTEGRATION_TOKEN_ERROR });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an error alert when integration update fails ', async () => {
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockRejectedValue(errorMsg);
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
findAlertsSettingsForm().vm.$emit('update-integration', {});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({ message: UPDATE_INTEGRATION_ERROR });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an error alert when integration test payload fails ', async () => {
|
2021-02-22 17:27:13 +05:30
|
|
|
const mock = new AxiosMockAdapter(axios);
|
|
|
|
mock.onPost(/(.*)/).replyOnce(403);
|
2021-04-17 20:07:23 +05:30
|
|
|
return wrapper.vm.testAlertPayload({ endpoint: '', data: '', token: '' }).then(() => {
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({ message: INTEGRATION_PAYLOAD_TEST_ERROR });
|
|
|
|
expect(createFlash).toHaveBeenCalledTimes(1);
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls `$apollo.mutate` with `updateCurrentHttpIntegrationMutation` on HTTP integration edit', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
createComponent({
|
2021-04-17 20:07:23 +05:30
|
|
|
data: {
|
|
|
|
integrations: { list: mockIntegrations },
|
|
|
|
currentIntegration: mockIntegrations[0],
|
|
|
|
httpIntegrations,
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
loading: false,
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate');
|
|
|
|
findIntegrationsList().vm.$emit('edit-integration', updateHttpVariables);
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: updateCurrentHttpIntegrationMutation,
|
|
|
|
variables: { ...mockIntegrations[0], ...httpMappingData },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls `$apollo.mutate` with `updateCurrentPrometheusIntegrationMutation` on PROMETHEUS integration edit', () => {
|
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
integrations: { list: mockIntegrations },
|
|
|
|
currentIntegration: mockIntegrations[3],
|
|
|
|
httpIntegrations,
|
|
|
|
},
|
|
|
|
loading: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.spyOn(wrapper.vm.$apollo, 'mutate');
|
|
|
|
findIntegrationsList().vm.$emit('edit-integration', updatePrometheusVariables);
|
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: updateCurrentPrometheusIntegrationMutation,
|
|
|
|
variables: mockIntegrations[3],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Test alert', () => {
|
|
|
|
it('makes `updateTestAlert` service call', async () => {
|
|
|
|
jest.spyOn(alertsUpdateService, 'updateTestAlert').mockResolvedValueOnce();
|
|
|
|
const testPayload = '{"title":"test"}';
|
|
|
|
findAlertsSettingsForm().vm.$emit('test-alert-payload', testPayload);
|
|
|
|
expect(alertsUpdateService.updateTestAlert).toHaveBeenCalledWith(testPayload);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows success message on successful test', async () => {
|
|
|
|
jest.spyOn(alertsUpdateService, 'updateTestAlert').mockResolvedValueOnce({});
|
|
|
|
findAlertsSettingsForm().vm.$emit('test-alert-payload', '');
|
|
|
|
await waitForPromises();
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({
|
|
|
|
message: i18n.alertSent,
|
|
|
|
type: FLASH_TYPES.SUCCESS,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows error message when test alert fails', async () => {
|
|
|
|
jest.spyOn(alertsUpdateService, 'updateTestAlert').mockRejectedValueOnce({});
|
|
|
|
findAlertsSettingsForm().vm.$emit('test-alert-payload', '');
|
|
|
|
await waitForPromises();
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({
|
|
|
|
message: INTEGRATION_PAYLOAD_TEST_ERROR,
|
|
|
|
});
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with mocked Apollo client', () => {
|
|
|
|
it('has a selection of integrations loaded via the getIntegrationsQuery', async () => {
|
|
|
|
createComponentWithApollo();
|
|
|
|
|
|
|
|
await jest.runOnlyPendingTimers();
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(findIntegrations()).toHaveLength(4);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls a mutation with correct parameters and destroys a integration', async () => {
|
|
|
|
createComponentWithApollo();
|
|
|
|
|
|
|
|
await destroyHttpIntegration(wrapper);
|
|
|
|
|
|
|
|
expect(destroyIntegrationHandler).toHaveBeenCalled();
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(findIntegrations()).toHaveLength(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays flash if mutation had a recoverable error', async () => {
|
|
|
|
createComponentWithApollo({
|
|
|
|
destroyHandler: jest.fn().mockResolvedValue(destroyIntegrationResponseWithErrors),
|
|
|
|
});
|
|
|
|
|
|
|
|
await destroyHttpIntegration(wrapper);
|
|
|
|
await awaitApolloDomMock();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({ message: 'Houston, we have a problem' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays flash if mutation had a non-recoverable error', async () => {
|
|
|
|
createComponentWithApollo({
|
|
|
|
destroyHandler: jest.fn().mockRejectedValue('Error'),
|
|
|
|
});
|
|
|
|
|
|
|
|
await destroyHttpIntegration(wrapper);
|
|
|
|
await awaitApolloDomMock();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({
|
|
|
|
message: DELETE_INTEGRATION_ERROR,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|