debian-mirror-gitlab/spec/frontend/api/groups_api_spec.js
2022-08-27 11:52:29 +05:30

46 lines
1.1 KiB
JavaScript

import MockAdapter from 'axios-mock-adapter';
import httpStatus from '~/lib/utils/http_status';
import axios from '~/lib/utils/axios_utils';
import { updateGroup } from '~/api/groups_api';
const mockApiVersion = 'v4';
const mockUrlRoot = '/gitlab';
describe('GroupsApi', () => {
let originalGon;
let mock;
const dummyGon = {
api_version: mockApiVersion,
relative_url_root: mockUrlRoot,
};
beforeEach(() => {
mock = new MockAdapter(axios);
originalGon = window.gon;
window.gon = { ...dummyGon };
});
afterEach(() => {
mock.restore();
window.gon = originalGon;
});
describe('updateGroup', () => {
const mockGroupId = '99';
const mockData = { attr: 'value' };
const expectedUrl = `${mockUrlRoot}/api/${mockApiVersion}/groups/${mockGroupId}`;
beforeEach(() => {
mock.onPut(expectedUrl).reply(({ data }) => {
return [httpStatus.OK, { id: mockGroupId, ...JSON.parse(data) }];
});
});
it('updates group', async () => {
const res = await updateGroup(mockGroupId, mockData);
expect(res.data).toMatchObject({ id: mockGroupId, ...mockData });
});
});
});