blob: 9b11fe2bff0afd33dfd6d9e491a04f5997fdb48c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import AxiosMockAdapter from 'axios-mock-adapter';
import { createAlert } from '~/alert';
import { ERROR_MSG } from '~/incidents_settings/constants';
import IncidentsSettingsService from '~/incidents_settings/incidents_settings_service';
import axios from '~/lib/utils/axios_utils';
import { HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_OK } from '~/lib/utils/http_status';
import { refreshCurrentPage } from '~/lib/utils/url_utility';
jest.mock('~/alert');
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(HTTP_STATUS_OK);
return service.updateSettings({}).then(() => {
expect(refreshCurrentPage).toHaveBeenCalled();
});
});
it('should display an alert on update error', () => {
mock.onPatch().reply(HTTP_STATUS_BAD_REQUEST);
return service.updateSettings({}).then(() => {
expect(createAlert).toHaveBeenCalledWith({
message: expect.stringContaining(ERROR_MSG),
});
});
});
});
describe('resetWebhookUrl', () => {
it('should make a call for webhook update', () => {
jest.spyOn(axios, 'post');
mock.onPost().reply(HTTP_STATUS_OK);
return service.resetWebhookUrl().then(() => {
expect(axios.post).toHaveBeenCalledWith(webhookUpdateEndpoint);
});
});
});
});
|