2020-07-16 15:09:38 +00:00
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2021-06-04 18:10:08 +00:00
|
|
|
import createFlash from '~/flash';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { ERROR_MSG } from '~/incidents_settings/constants';
|
|
|
|
import IncidentsSettingsService from '~/incidents_settings/incidents_settings_service';
|
2020-08-17 21:09:56 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-07-16 15:09:38 +00:00
|
|
|
import httpStatusCodes from '~/lib/utils/http_status';
|
|
|
|
import { refreshCurrentPage } from '~/lib/utils/url_utility';
|
|
|
|
|
|
|
|
jest.mock('~/flash');
|
|
|
|
jest.mock('~/lib/utils/url_utility');
|
|
|
|
|
|
|
|
describe('IncidentsSettingsService', () => {
|
|
|
|
const settingsEndpoint = 'operations/settings';
|
|
|
|
const webhookUpdateEndpoint = 'webhook/update';
|
|
|
|
let mock;
|
|
|
|
let service;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new AxiosMockAdapter(axios);
|
|
|
|
service = new IncidentsSettingsService(settingsEndpoint, webhookUpdateEndpoint);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateSettings', () => {
|
|
|
|
it('should refresh the page on successful update', () => {
|
|
|
|
mock.onPatch().reply(httpStatusCodes.OK);
|
|
|
|
|
|
|
|
return service.updateSettings({}).then(() => {
|
|
|
|
expect(refreshCurrentPage).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should display a flash message on update error', () => {
|
|
|
|
mock.onPatch().reply(httpStatusCodes.BAD_REQUEST);
|
|
|
|
|
|
|
|
return service.updateSettings({}).then(() => {
|
2021-06-04 18:10:08 +00:00
|
|
|
expect(createFlash).toHaveBeenCalledWith({
|
|
|
|
message: expect.stringContaining(ERROR_MSG),
|
|
|
|
});
|
2020-07-16 15:09:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('resetWebhookUrl', () => {
|
|
|
|
it('should make a call for webhook update', () => {
|
|
|
|
jest.spyOn(axios, 'post');
|
|
|
|
mock.onPost().reply(httpStatusCodes.OK);
|
|
|
|
|
|
|
|
return service.resetWebhookUrl().then(() => {
|
|
|
|
expect(axios.post).toHaveBeenCalledWith(webhookUpdateEndpoint);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|