debian-mirror-gitlab/spec/frontend/mr_notes/stores/actions_spec.js

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

65 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-04-29 21:17:54 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status';
2022-06-21 17:19:12 +05:30
import { createStore } from '~/mr_notes/stores';
2021-04-29 21:17:54 +05:30
describe('MR Notes Mutator Actions', () => {
2022-06-21 17:19:12 +05:30
let store;
beforeEach(() => {
store = createStore();
});
2021-04-29 21:17:54 +05:30
describe('setEndpoints', () => {
2022-06-21 17:19:12 +05:30
it('sets endpoints', async () => {
2021-04-29 21:17:54 +05:30
const endpoints = { endpointA: 'a' };
2022-06-21 17:19:12 +05:30
await store.dispatch('setEndpoints', endpoints);
2021-04-29 21:17:54 +05:30
2022-06-21 17:19:12 +05:30
expect(store.state.page.endpoints).toEqual(endpoints);
2021-04-29 21:17:54 +05:30
});
});
describe('fetchMrMetadata', () => {
const mrMetadata = { meta: true, data: 'foo' };
2022-06-21 17:19:12 +05:30
const metadata = 'metadata';
const endpoints = { metadata };
2021-04-29 21:17:54 +05:30
let mock;
2022-06-21 17:19:12 +05:30
beforeEach(async () => {
await store.dispatch('setEndpoints', endpoints);
2021-04-29 21:17:54 +05:30
mock = new MockAdapter(axios);
2023-04-23 21:23:45 +05:30
mock.onGet(metadata).reply(HTTP_STATUS_OK, mrMetadata);
2021-04-29 21:17:54 +05:30
});
afterEach(() => {
mock.restore();
});
it('should fetch the data from the API', async () => {
2022-06-21 17:19:12 +05:30
await store.dispatch('fetchMrMetadata');
2021-04-29 21:17:54 +05:30
await axios.waitForAll();
expect(mock.history.get).toHaveLength(1);
2022-06-21 17:19:12 +05:30
expect(mock.history.get[0].url).toBe(metadata);
});
it('should set the fetched data into state', async () => {
await store.dispatch('fetchMrMetadata');
expect(store.state.page.mrMetadata).toEqual(mrMetadata);
2021-04-29 21:17:54 +05:30
});
2022-06-21 17:19:12 +05:30
it('should set failedToLoadMetadata flag when request fails', async () => {
2023-04-23 21:23:45 +05:30
mock.onGet(metadata).reply(HTTP_STATUS_INTERNAL_SERVER_ERROR);
2022-06-21 17:19:12 +05:30
await store.dispatch('fetchMrMetadata');
expect(store.state.page.failedToLoadMetadata).toBe(true);
2021-04-29 21:17:54 +05:30
});
});
});