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

91 lines
2.5 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';
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 axios from '~/lib/utils/axios_utils';
import { adjustMetricQuery } from '../utils';
describe('ServerlessActions', () => {
describe('fetchFunctions', () => {
2021-03-08 18:12:59 +05:30
it('should successfully fetch functions', (done) => {
2019-07-07 11:18:12 +05:30
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();
},
);
});
2021-03-08 18:12:59 +05:30
it('should successfully retry', (done) => {
2019-07-07 11:18:12 +05:30
const endpoint = '/functions';
const mock = new MockAdapter(axios);
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
testAction(
fetchFunctions,
{ functionsPath: endpoint },
{},
[],
[{ type: 'requestFunctionsLoading' }],
() => {
mock.restore();
done();
},
);
});
});
describe('fetchMetrics', () => {
2021-03-08 18:12:59 +05:30
it('should return no prometheus', (done) => {
2019-07-07 11:18:12 +05:30
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();
},
);
});
2021-03-08 18:12:59 +05:30
it('should successfully fetch metrics', (done) => {
2019-07-07 11:18:12 +05:30
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();
},
);
});
});
});