diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/frontend/api_spec.js | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/frontend/api_spec.js')
-rw-r--r-- | spec/frontend/api_spec.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/frontend/api_spec.js b/spec/frontend/api_spec.js index c1a23d441b3..c94637e04af 100644 --- a/spec/frontend/api_spec.js +++ b/spec/frontend/api_spec.js @@ -46,6 +46,77 @@ describe('Api', () => { }); }); + describe('packages', () => { + const projectId = 'project_a'; + const packageId = 'package_b'; + const apiResponse = [{ id: 1, name: 'foo' }]; + + describe('groupPackages', () => { + const groupId = 'group_a'; + + it('fetch all group packages', () => { + const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/packages`; + jest.spyOn(axios, 'get'); + mock.onGet(expectedUrl).replyOnce(200, apiResponse); + + return Api.groupPackages(groupId).then(({ data }) => { + expect(data).toEqual(apiResponse); + expect(axios.get).toHaveBeenCalledWith(expectedUrl, {}); + }); + }); + }); + + describe('projectPackages', () => { + it('fetch all project packages', () => { + const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/packages`; + jest.spyOn(axios, 'get'); + mock.onGet(expectedUrl).replyOnce(200, apiResponse); + + return Api.projectPackages(projectId).then(({ data }) => { + expect(data).toEqual(apiResponse); + expect(axios.get).toHaveBeenCalledWith(expectedUrl, {}); + }); + }); + }); + + describe('buildProjectPackageUrl', () => { + it('returns the right url', () => { + const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/packages/${packageId}`; + const url = Api.buildProjectPackageUrl(projectId, packageId); + expect(url).toEqual(expectedUrl); + }); + }); + + describe('projectPackage', () => { + it('fetch package details', () => { + const expectedUrl = `foo`; + jest.spyOn(Api, 'buildProjectPackageUrl').mockReturnValue(expectedUrl); + jest.spyOn(axios, 'get'); + mock.onGet(expectedUrl).replyOnce(200, apiResponse); + + return Api.projectPackage(projectId, packageId).then(({ data }) => { + expect(data).toEqual(apiResponse); + expect(axios.get).toHaveBeenCalledWith(expectedUrl); + }); + }); + }); + + describe('deleteProjectPackage', () => { + it('delete a package', () => { + const expectedUrl = `foo`; + + jest.spyOn(Api, 'buildProjectPackageUrl').mockReturnValue(expectedUrl); + jest.spyOn(axios, 'delete'); + mock.onDelete(expectedUrl).replyOnce(200, true); + + return Api.deleteProjectPackage(projectId, packageId).then(({ data }) => { + expect(data).toEqual(true); + expect(axios.delete).toHaveBeenCalledWith(expectedUrl); + }); + }); + }); + }); + describe('group', () => { it('fetches a group', done => { const groupId = '123456'; @@ -366,6 +437,30 @@ describe('Api', () => { }); }); + describe('commit', () => { + const projectId = 'user/project'; + const sha = 'abcd0123'; + const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent( + projectId, + )}/repository/commits/${sha}`; + + it('fetches a single commit', () => { + mock.onGet(expectedUrl).reply(200, { id: sha }); + + return Api.commit(projectId, sha).then(({ data: commit }) => { + expect(commit.id).toBe(sha); + }); + }); + + it('fetches a single commit without stats', () => { + mock.onGet(expectedUrl, { params: { stats: false } }).reply(200, { id: sha }); + + return Api.commit(projectId, sha, { stats: false }).then(({ data: commit }) => { + expect(commit.id).toBe(sha); + }); + }); + }); + describe('issueTemplate', () => { it('fetches an issue template', done => { const namespace = 'some namespace'; |