debian-mirror-gitlab/spec/frontend/api/packages_api_spec.js

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

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-01-26 12:08:38 +05:30
import MockAdapter from 'axios-mock-adapter';
import { publishPackage } from '~/api/packages_api';
import axios from '~/lib/utils/axios_utils';
import httpStatus from '~/lib/utils/http_status';
describe('Api', () => {
const dummyApiVersion = 'v3000';
const dummyUrlRoot = '/gitlab';
const dummyGon = {
api_version: dummyApiVersion,
relative_url_root: dummyUrlRoot,
};
let originalGon;
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
originalGon = window.gon;
window.gon = { ...dummyGon };
});
afterEach(() => {
mock.restore();
window.gon = originalGon;
});
describe('packages', () => {
const projectPath = 'project_a';
const name = 'foo';
const packageVersion = '0';
const apiResponse = [{ id: 1, name: 'foo' }];
describe('publishPackage', () => {
it('publishes the package', () => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/packages/generic/${name}/${packageVersion}/${name}`;
jest.spyOn(axios, 'put');
mock.onPut(expectedUrl).replyOnce(httpStatus.OK, apiResponse);
return publishPackage(
2022-03-02 08:16:31 +05:30
{
projectPath,
name,
version: 0,
fileName: name,
files: [new File(['zip contents'], 'bar.zip')],
},
2022-01-26 12:08:38 +05:30
{ status: 'hidden', select: 'package_file' },
).then(({ data }) => {
expect(data).toEqual(apiResponse);
2022-03-02 08:16:31 +05:30
expect(axios.put).toHaveBeenCalledWith(expectedUrl, expect.any(File), {
2022-01-26 12:08:38 +05:30
params: { select: 'package_file', status: 'hidden' },
});
});
});
});
});
});