Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/api_spec.js')
-rw-r--r--spec/frontend/api_spec.js95
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';