2019-04-06 02:02:39 +00:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-01-15 00:10:45 +00:00
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2019-04-06 02:02:39 +00:00
|
|
|
import statusCodes from '~/lib/utils/http_status';
|
|
|
|
import { fetchFunctions, fetchMetrics } from '~/serverless/store/actions';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2021-02-01 15:08:56 +00:00
|
|
|
import { mockServerlessFunctions, mockMetrics } from '../mock_data';
|
2019-04-06 02:02:39 +00:00
|
|
|
import { adjustMetricQuery } from '../utils';
|
|
|
|
|
|
|
|
describe('ServerlessActions', () => {
|
|
|
|
describe('fetchFunctions', () => {
|
2020-12-24 00:10:25 +00:00
|
|
|
it('should successfully fetch functions', (done) => {
|
2019-04-06 02:02:39 +00:00
|
|
|
const endpoint = '/functions';
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockServerlessFunctions));
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
fetchFunctions,
|
|
|
|
{ functionsPath: endpoint },
|
|
|
|
{},
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{ type: 'requestFunctionsLoading' },
|
|
|
|
{ type: 'receiveFunctionsSuccess', payload: mockServerlessFunctions },
|
|
|
|
],
|
|
|
|
() => {
|
|
|
|
mock.restore();
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-24 00:10:25 +00:00
|
|
|
it('should successfully retry', (done) => {
|
2019-04-06 02:02:39 +00:00
|
|
|
const endpoint = '/functions';
|
|
|
|
const mock = new MockAdapter(axios);
|
2019-04-07 03:00:28 +00:00
|
|
|
mock
|
|
|
|
.onGet(endpoint)
|
2020-12-24 00:10:25 +00:00
|
|
|
.reply(() => new Promise((resolve) => setTimeout(() => resolve(200), Infinity)));
|
2019-04-06 02:02:39 +00:00
|
|
|
|
|
|
|
testAction(
|
|
|
|
fetchFunctions,
|
|
|
|
{ functionsPath: endpoint },
|
|
|
|
{},
|
|
|
|
[],
|
|
|
|
[{ type: 'requestFunctionsLoading' }],
|
|
|
|
() => {
|
|
|
|
mock.restore();
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchMetrics', () => {
|
2020-12-24 00:10:25 +00:00
|
|
|
it('should return no prometheus', (done) => {
|
2019-04-06 02:02:39 +00:00
|
|
|
const endpoint = '/metrics';
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
mock.onGet(endpoint).reply(statusCodes.NO_CONTENT);
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
fetchMetrics,
|
|
|
|
{ metricsPath: endpoint, hasPrometheus: false },
|
|
|
|
{},
|
|
|
|
[],
|
|
|
|
[{ type: 'receiveMetricsNoPrometheus' }],
|
|
|
|
() => {
|
|
|
|
mock.restore();
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-24 00:10:25 +00:00
|
|
|
it('should successfully fetch metrics', (done) => {
|
2019-04-06 02:02:39 +00:00
|
|
|
const endpoint = '/metrics';
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockMetrics));
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
fetchMetrics,
|
|
|
|
{ metricsPath: endpoint, hasPrometheus: true },
|
|
|
|
{},
|
|
|
|
[],
|
|
|
|
[{ type: 'receiveMetricsSuccess', payload: adjustMetricQuery(mockMetrics) }],
|
|
|
|
() => {
|
|
|
|
mock.restore();
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|