debian-mirror-gitlab/spec/frontend/serverless/store/actions_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-07-07 11:18:12 +05:30
import MockAdapter from 'axios-mock-adapter';
2021-03-08 18:12:59 +05:30
import testAction from 'helpers/vuex_action_helper';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2019-07-07 11:18:12 +05:30
import statusCodes from '~/lib/utils/http_status';
import { fetchFunctions, fetchMetrics } from '~/serverless/store/actions';
import { mockServerlessFunctions, mockMetrics } from '../mock_data';
import { adjustMetricQuery } from '../utils';
describe('ServerlessActions', () => {
2022-06-21 17:19:12 +05:30
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
2019-07-07 11:18:12 +05:30
describe('fetchFunctions', () => {
2022-06-21 17:19:12 +05:30
it('should successfully fetch functions', () => {
2019-07-07 11:18:12 +05:30
const endpoint = '/functions';
mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockServerlessFunctions));
2022-06-21 17:19:12 +05:30
return testAction(
2019-07-07 11:18:12 +05:30
fetchFunctions,
{ functionsPath: endpoint },
{},
[],
[
{ type: 'requestFunctionsLoading' },
{ type: 'receiveFunctionsSuccess', payload: mockServerlessFunctions },
],
);
});
2022-06-21 17:19:12 +05:30
it('should successfully retry', () => {
2019-07-07 11:18:12 +05:30
const endpoint = '/functions';
mock
.onGet(endpoint)
2021-03-08 18:12:59 +05:30
.reply(() => new Promise((resolve) => setTimeout(() => resolve(200), Infinity)));
2019-07-07 11:18:12 +05:30
2022-06-21 17:19:12 +05:30
return testAction(
2019-07-07 11:18:12 +05:30
fetchFunctions,
{ functionsPath: endpoint },
{},
[],
[{ type: 'requestFunctionsLoading' }],
);
});
});
describe('fetchMetrics', () => {
2022-06-21 17:19:12 +05:30
it('should return no prometheus', () => {
2019-07-07 11:18:12 +05:30
const endpoint = '/metrics';
mock.onGet(endpoint).reply(statusCodes.NO_CONTENT);
2022-06-21 17:19:12 +05:30
return testAction(
2019-07-07 11:18:12 +05:30
fetchMetrics,
{ metricsPath: endpoint, hasPrometheus: false },
{},
[],
[{ type: 'receiveMetricsNoPrometheus' }],
);
});
2022-06-21 17:19:12 +05:30
it('should successfully fetch metrics', () => {
2019-07-07 11:18:12 +05:30
const endpoint = '/metrics';
mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockMetrics));
2022-06-21 17:19:12 +05:30
return testAction(
2019-07-07 11:18:12 +05:30
fetchMetrics,
{ metricsPath: endpoint, hasPrometheus: true },
{},
[],
[{ type: 'receiveMetricsSuccess', payload: adjustMetricQuery(mockMetrics) }],
);
});
});
});