diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /spec/frontend/api | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'spec/frontend/api')
-rw-r--r-- | spec/frontend/api/packages_api_spec.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/frontend/api/packages_api_spec.js b/spec/frontend/api/packages_api_spec.js new file mode 100644 index 00000000000..3286dccb1b2 --- /dev/null +++ b/spec/frontend/api/packages_api_spec.js @@ -0,0 +1,53 @@ +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( + { projectPath, name, version: 0, fileName: name, files: [{}] }, + { status: 'hidden', select: 'package_file' }, + ).then(({ data }) => { + expect(data).toEqual(apiResponse); + expect(axios.put).toHaveBeenCalledWith(expectedUrl, expect.any(FormData), { + headers: { 'Content-Type': 'multipart/form-data' }, + params: { select: 'package_file', status: 'hidden' }, + }); + }); + }); + }); + }); +}); |