Commit 9c4ac016 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Remove jest test callbacks from API specs

Jest 27 does not support the test callback anymore so
the following code is no longer valid:

```
it('test', (done) => { /* code */ })
```
parent f4fd015d
...@@ -158,33 +158,32 @@ describe('Api', () => { ...@@ -158,33 +158,32 @@ describe('Api', () => {
}); });
describe('group', () => { describe('group', () => {
it('fetches a group', (done) => { it('fetches a group', () => {
const groupId = '123456'; const groupId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}`;
mock.onGet(expectedUrl).reply(httpStatus.OK, { mock.onGet(expectedUrl).reply(httpStatus.OK, {
name: 'test', name: 'test',
}); });
return new Promise((resolve) => {
Api.group(groupId, (response) => { Api.group(groupId, (response) => {
expect(response.name).toBe('test'); expect(response.name).toBe('test');
done(); resolve();
});
}); });
}); });
}); });
describe('groupMembers', () => { describe('groupMembers', () => {
it('fetches group members', (done) => { it('fetches group members', () => {
const groupId = '54321'; const groupId = '54321';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/members`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/members`;
const expectedData = [{ id: 7 }]; const expectedData = [{ id: 7 }];
mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData); mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData);
Api.groupMembers(groupId) return Api.groupMembers(groupId).then(({ data }) => {
.then(({ data }) => {
expect(data).toEqual(expectedData); expect(data).toEqual(expectedData);
}) });
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -233,7 +232,7 @@ describe('Api', () => { ...@@ -233,7 +232,7 @@ describe('Api', () => {
}); });
describe('groupMilestones', () => { describe('groupMilestones', () => {
it('fetches group milestones', (done) => { it('fetches group milestones', () => {
const groupId = '16'; const groupId = '16';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/milestones`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/milestones`;
const expectedData = [ const expectedData = [
...@@ -253,17 +252,14 @@ describe('Api', () => { ...@@ -253,17 +252,14 @@ describe('Api', () => {
]; ];
mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData); mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData);
Api.groupMilestones(groupId) return Api.groupMilestones(groupId).then(({ data }) => {
.then(({ data }) => {
expect(data).toEqual(expectedData); expect(data).toEqual(expectedData);
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('groups', () => { describe('groups', () => {
it('fetches groups', (done) => { it('fetches groups', () => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups.json`;
...@@ -273,16 +269,18 @@ describe('Api', () => { ...@@ -273,16 +269,18 @@ describe('Api', () => {
}, },
]); ]);
return new Promise((resolve) => {
Api.groups(query, options, (response) => { Api.groups(query, options, (response) => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); resolve();
});
}); });
}); });
}); });
describe('groupLabels', () => { describe('groupLabels', () => {
it('fetches group labels', (done) => { it('fetches group labels', () => {
const options = { params: { search: 'foo' } }; const options = { params: { search: 'foo' } };
const expectedGroup = 'gitlab-org'; const expectedGroup = 'gitlab-org';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${expectedGroup}/labels`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${expectedGroup}/labels`;
...@@ -293,18 +291,15 @@ describe('Api', () => { ...@@ -293,18 +291,15 @@ describe('Api', () => {
}, },
]); ]);
Api.groupLabels(expectedGroup, options) return Api.groupLabels(expectedGroup, options).then((res) => {
.then((res) => {
expect(res.length).toBe(1); expect(res.length).toBe(1);
expect(res[0].name).toBe('Foo Label'); expect(res[0].name).toBe('Foo Label');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('namespaces', () => { describe('namespaces', () => {
it('fetches namespaces', (done) => { it('fetches namespaces', () => {
const query = 'dummy query'; const query = 'dummy query';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/namespaces.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/namespaces.json`;
mock.onGet(expectedUrl).reply(httpStatus.OK, [ mock.onGet(expectedUrl).reply(httpStatus.OK, [
...@@ -313,16 +308,18 @@ describe('Api', () => { ...@@ -313,16 +308,18 @@ describe('Api', () => {
}, },
]); ]);
return new Promise((resolve) => {
Api.namespaces(query, (response) => { Api.namespaces(query, (response) => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); resolve();
});
}); });
}); });
}); });
describe('projects', () => { describe('projects', () => {
it('fetches projects with membership when logged in', (done) => { it('fetches projects with membership when logged in', () => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`;
...@@ -333,14 +330,16 @@ describe('Api', () => { ...@@ -333,14 +330,16 @@ describe('Api', () => {
}, },
]); ]);
return new Promise((resolve) => {
Api.projects(query, options, (response) => { Api.projects(query, options, (response) => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); resolve();
});
}); });
}); });
it('fetches projects without membership when not logged in', (done) => { it('fetches projects without membership when not logged in', () => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`;
...@@ -350,31 +349,30 @@ describe('Api', () => { ...@@ -350,31 +349,30 @@ describe('Api', () => {
}, },
]); ]);
return new Promise((resolve) => {
Api.projects(query, options, (response) => { Api.projects(query, options, (response) => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); resolve();
});
}); });
}); });
}); });
describe('updateProject', () => { describe('updateProject', () => {
it('update a project with the given payload', (done) => { it('update a project with the given payload', () => {
const projectPath = 'foo'; const projectPath = 'foo';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}`;
mock.onPut(expectedUrl).reply(httpStatus.OK, { foo: 'bar' }); mock.onPut(expectedUrl).reply(httpStatus.OK, { foo: 'bar' });
Api.updateProject(projectPath, { foo: 'bar' }) return Api.updateProject(projectPath, { foo: 'bar' }).then(({ data }) => {
.then(({ data }) => {
expect(data.foo).toBe('bar'); expect(data.foo).toBe('bar');
done(); });
})
.catch(done.fail);
}); });
}); });
describe('projectUsers', () => { describe('projectUsers', () => {
it('fetches all users of a particular project', (done) => { it('fetches all users of a particular project', () => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const projectPath = 'gitlab-org%2Fgitlab-ce'; const projectPath = 'gitlab-org%2Fgitlab-ce';
...@@ -385,13 +383,10 @@ describe('Api', () => { ...@@ -385,13 +383,10 @@ describe('Api', () => {
}, },
]); ]);
Api.projectUsers('gitlab-org/gitlab-ce', query, options) return Api.projectUsers('gitlab-org/gitlab-ce', query, options).then((response) => {
.then((response) => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -399,38 +394,32 @@ describe('Api', () => { ...@@ -399,38 +394,32 @@ describe('Api', () => {
const projectPath = 'abc'; const projectPath = 'abc';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests`;
it('fetches all merge requests for a project', (done) => { it('fetches all merge requests for a project', () => {
const mockData = [{ source_branch: 'foo' }, { source_branch: 'bar' }]; const mockData = [{ source_branch: 'foo' }, { source_branch: 'bar' }];
mock.onGet(expectedUrl).reply(httpStatus.OK, mockData); mock.onGet(expectedUrl).reply(httpStatus.OK, mockData);
Api.projectMergeRequests(projectPath) return Api.projectMergeRequests(projectPath).then(({ data }) => {
.then(({ data }) => {
expect(data.length).toEqual(2); expect(data.length).toEqual(2);
expect(data[0].source_branch).toBe('foo'); expect(data[0].source_branch).toBe('foo');
expect(data[1].source_branch).toBe('bar'); expect(data[1].source_branch).toBe('bar');
}) });
.then(done)
.catch(done.fail);
}); });
it('fetches merge requests filtered with passed params', (done) => { it('fetches merge requests filtered with passed params', () => {
const params = { const params = {
source_branch: 'bar', source_branch: 'bar',
}; };
const mockData = [{ source_branch: 'bar' }]; const mockData = [{ source_branch: 'bar' }];
mock.onGet(expectedUrl, { params }).reply(httpStatus.OK, mockData); mock.onGet(expectedUrl, { params }).reply(httpStatus.OK, mockData);
Api.projectMergeRequests(projectPath, params) return Api.projectMergeRequests(projectPath, params).then(({ data }) => {
.then(({ data }) => {
expect(data.length).toEqual(1); expect(data.length).toEqual(1);
expect(data[0].source_branch).toBe('bar'); expect(data[0].source_branch).toBe('bar');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('projectMergeRequest', () => { describe('projectMergeRequest', () => {
it('fetches a merge request', (done) => { it('fetches a merge request', () => {
const projectPath = 'abc'; const projectPath = 'abc';
const mergeRequestId = '123456'; const mergeRequestId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}`;
...@@ -438,17 +427,14 @@ describe('Api', () => { ...@@ -438,17 +427,14 @@ describe('Api', () => {
title: 'test', title: 'test',
}); });
Api.projectMergeRequest(projectPath, mergeRequestId) return Api.projectMergeRequest(projectPath, mergeRequestId).then(({ data }) => {
.then(({ data }) => {
expect(data.title).toBe('test'); expect(data.title).toBe('test');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('projectMergeRequestChanges', () => { describe('projectMergeRequestChanges', () => {
it('fetches the changes of a merge request', (done) => { it('fetches the changes of a merge request', () => {
const projectPath = 'abc'; const projectPath = 'abc';
const mergeRequestId = '123456'; const mergeRequestId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/changes`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/changes`;
...@@ -456,17 +442,14 @@ describe('Api', () => { ...@@ -456,17 +442,14 @@ describe('Api', () => {
title: 'test', title: 'test',
}); });
Api.projectMergeRequestChanges(projectPath, mergeRequestId) return Api.projectMergeRequestChanges(projectPath, mergeRequestId).then(({ data }) => {
.then(({ data }) => {
expect(data.title).toBe('test'); expect(data.title).toBe('test');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('projectMergeRequestVersions', () => { describe('projectMergeRequestVersions', () => {
it('fetches the versions of a merge request', (done) => { it('fetches the versions of a merge request', () => {
const projectPath = 'abc'; const projectPath = 'abc';
const mergeRequestId = '123456'; const mergeRequestId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/versions`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/versions`;
...@@ -476,30 +459,24 @@ describe('Api', () => { ...@@ -476,30 +459,24 @@ describe('Api', () => {
}, },
]); ]);
Api.projectMergeRequestVersions(projectPath, mergeRequestId) return Api.projectMergeRequestVersions(projectPath, mergeRequestId).then(({ data }) => {
.then(({ data }) => {
expect(data.length).toBe(1); expect(data.length).toBe(1);
expect(data[0].id).toBe(123); expect(data[0].id).toBe(123);
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('projectRunners', () => { describe('projectRunners', () => {
it('fetches the runners of a project', (done) => { it('fetches the runners of a project', () => {
const projectPath = 7; const projectPath = 7;
const params = { scope: 'active' }; const params = { scope: 'active' };
const mockData = [{ id: 4 }]; const mockData = [{ id: 4 }];
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/runners`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/runners`;
mock.onGet(expectedUrl, { params }).reply(httpStatus.OK, mockData); mock.onGet(expectedUrl, { params }).reply(httpStatus.OK, mockData);
Api.projectRunners(projectPath, { params }) return Api.projectRunners(projectPath, { params }).then(({ data }) => {
.then(({ data }) => {
expect(data).toEqual(mockData); expect(data).toEqual(mockData);
}) });
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -528,7 +505,7 @@ describe('Api', () => { ...@@ -528,7 +505,7 @@ describe('Api', () => {
}); });
describe('projectMilestones', () => { describe('projectMilestones', () => {
it('fetches project milestones', (done) => { it('fetches project milestones', () => {
const projectId = 1; const projectId = 1;
const options = { state: 'active' }; const options = { state: 'active' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/1/milestones`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/1/milestones`;
...@@ -540,13 +517,10 @@ describe('Api', () => { ...@@ -540,13 +517,10 @@ describe('Api', () => {
}, },
]); ]);
Api.projectMilestones(projectId, options) return Api.projectMilestones(projectId, options).then(({ data }) => {
.then(({ data }) => {
expect(data.length).toBe(1); expect(data.length).toBe(1);
expect(data[0].title).toBe('milestone1'); expect(data[0].title).toBe('milestone1');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -614,7 +588,7 @@ describe('Api', () => { ...@@ -614,7 +588,7 @@ describe('Api', () => {
}); });
describe('newLabel', () => { describe('newLabel', () => {
it('creates a new project label', (done) => { it('creates a new project label', () => {
const namespace = 'some namespace'; const namespace = 'some namespace';
const project = 'some project'; const project = 'some project';
const labelData = { some: 'data' }; const labelData = { some: 'data' };
...@@ -633,13 +607,15 @@ describe('Api', () => { ...@@ -633,13 +607,15 @@ describe('Api', () => {
]; ];
}); });
return new Promise((resolve) => {
Api.newLabel(namespace, project, labelData, (response) => { Api.newLabel(namespace, project, labelData, (response) => {
expect(response.name).toBe('test'); expect(response.name).toBe('test');
done(); resolve();
});
}); });
}); });
it('creates a new group label', (done) => { it('creates a new group label', () => {
const namespace = 'group/subgroup'; const namespace = 'group/subgroup';
const labelData = { name: 'Foo', color: '#000000' }; const labelData = { name: 'Foo', color: '#000000' };
const expectedUrl = Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespace); const expectedUrl = Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespace);
...@@ -654,15 +630,17 @@ describe('Api', () => { ...@@ -654,15 +630,17 @@ describe('Api', () => {
]; ];
}); });
return new Promise((resolve) => {
Api.newLabel(namespace, undefined, labelData, (response) => { Api.newLabel(namespace, undefined, labelData, (response) => {
expect(response.name).toBe('Foo'); expect(response.name).toBe('Foo');
done(); resolve();
});
}); });
}); });
}); });
describe('groupProjects', () => { describe('groupProjects', () => {
it('fetches group projects', (done) => { it('fetches group projects', () => {
const groupId = '123456'; const groupId = '123456';
const query = 'dummy query'; const query = 'dummy query';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/projects.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/projects.json`;
...@@ -672,10 +650,12 @@ describe('Api', () => { ...@@ -672,10 +650,12 @@ describe('Api', () => {
}, },
]); ]);
return new Promise((resolve) => {
Api.groupProjects(groupId, query, {}, (response) => { Api.groupProjects(groupId, query, {}, (response) => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); resolve();
});
}); });
}); });
...@@ -764,12 +744,14 @@ describe('Api', () => { ...@@ -764,12 +744,14 @@ describe('Api', () => {
templateKey, templateKey,
)}`; )}`;
it('fetches an issue template', (done) => { it('fetches an issue template', () => {
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test'); mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
Api.issueTemplate(namespace, project, templateKey, templateType, (error, response) => { return new Promise((resolve) => {
Api.issueTemplate(namespace, project, templateKey, templateType, (_, response) => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); resolve();
});
}); });
}); });
...@@ -777,8 +759,11 @@ describe('Api', () => { ...@@ -777,8 +759,11 @@ describe('Api', () => {
it('rejects the Promise', () => { it('rejects the Promise', () => {
mock.onGet(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR); mock.onGet(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
return new Promise((resolve) => {
Api.issueTemplate(namespace, project, templateKey, templateType, () => { Api.issueTemplate(namespace, project, templateKey, templateType, () => {
expect(mock.history.get).toHaveLength(1); expect(mock.history.get).toHaveLength(1);
resolve();
});
}); });
}); });
}); });
...@@ -790,19 +775,21 @@ describe('Api', () => { ...@@ -790,19 +775,21 @@ describe('Api', () => {
const templateType = 'template type'; const templateType = 'template type';
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}`; const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}`;
it('fetches all templates by type', (done) => { it('fetches all templates by type', () => {
const expectedData = [ const expectedData = [
{ key: 'Template1', name: 'Template 1', content: 'This is template 1!' }, { key: 'Template1', name: 'Template 1', content: 'This is template 1!' },
]; ];
mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData); mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData);
Api.issueTemplates(namespace, project, templateType, (error, response) => { return new Promise((resolve) => {
Api.issueTemplates(namespace, project, templateType, (_, response) => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
const { key, name, content } = response[0]; const { key, name, content } = response[0];
expect(key).toBe('Template1'); expect(key).toBe('Template1');
expect(name).toBe('Template 1'); expect(name).toBe('Template 1');
expect(content).toBe('This is template 1!'); expect(content).toBe('This is template 1!');
done(); resolve();
});
}); });
}); });
...@@ -818,34 +805,44 @@ describe('Api', () => { ...@@ -818,34 +805,44 @@ describe('Api', () => {
}); });
describe('projectTemplates', () => { describe('projectTemplates', () => {
it('fetches a list of templates', (done) => { it('fetches a list of templates', () => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses`;
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test'); mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
return new Promise((resolve) => {
Api.projectTemplates('gitlab-org/gitlab-ce', 'licenses', {}, (response) => { Api.projectTemplates('gitlab-org/gitlab-ce', 'licenses', {}, (response) => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); resolve();
});
}); });
}); });
}); });
describe('projectTemplate', () => { describe('projectTemplate', () => {
it('fetches a single template', (done) => { it('fetches a single template', () => {
const data = { unused: 'option' }; const data = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses/test%20license`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses/test%20license`;
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test'); mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
Api.projectTemplate('gitlab-org/gitlab-ce', 'licenses', 'test license', data, (response) => { return new Promise((resolve) => {
Api.projectTemplate(
'gitlab-org/gitlab-ce',
'licenses',
'test license',
data,
(response) => {
expect(response).toBe('test'); expect(response).toBe('test');
done(); resolve();
},
);
}); });
}); });
}); });
describe('users', () => { describe('users', () => {
it('fetches users', (done) => { it('fetches users', () => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users.json`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users.json`;
...@@ -855,68 +852,56 @@ describe('Api', () => { ...@@ -855,68 +852,56 @@ describe('Api', () => {
}, },
]); ]);
Api.users(query, options) return Api.users(query, options).then(({ data }) => {
.then(({ data }) => {
expect(data.length).toBe(1); expect(data.length).toBe(1);
expect(data[0].name).toBe('test'); expect(data[0].name).toBe('test');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('user', () => { describe('user', () => {
it('fetches single user', (done) => { it('fetches single user', () => {
const userId = '123456'; const userId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}`;
mock.onGet(expectedUrl).reply(httpStatus.OK, { mock.onGet(expectedUrl).reply(httpStatus.OK, {
name: 'testuser', name: 'testuser',
}); });
Api.user(userId) return Api.user(userId).then(({ data }) => {
.then(({ data }) => {
expect(data.name).toBe('testuser'); expect(data.name).toBe('testuser');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('user counts', () => { describe('user counts', () => {
it('fetches single user counts', (done) => { it('fetches single user counts', () => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/user_counts`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/user_counts`;
mock.onGet(expectedUrl).reply(httpStatus.OK, { mock.onGet(expectedUrl).reply(httpStatus.OK, {
merge_requests: 4, merge_requests: 4,
}); });
Api.userCounts() return Api.userCounts().then(({ data }) => {
.then(({ data }) => {
expect(data.merge_requests).toBe(4); expect(data.merge_requests).toBe(4);
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('user status', () => { describe('user status', () => {
it('fetches single user status', (done) => { it('fetches single user status', () => {
const userId = '123456'; const userId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}/status`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}/status`;
mock.onGet(expectedUrl).reply(httpStatus.OK, { mock.onGet(expectedUrl).reply(httpStatus.OK, {
message: 'testmessage', message: 'testmessage',
}); });
Api.userStatus(userId) return Api.userStatus(userId).then(({ data }) => {
.then(({ data }) => {
expect(data.message).toBe('testmessage'); expect(data.message).toBe('testmessage');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('user projects', () => { describe('user projects', () => {
it('fetches all projects that belong to a particular user', (done) => { it('fetches all projects that belong to a particular user', () => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const userId = '123456'; const userId = '123456';
...@@ -927,16 +912,18 @@ describe('Api', () => { ...@@ -927,16 +912,18 @@ describe('Api', () => {
}, },
]); ]);
return new Promise((resolve) => {
Api.userProjects(userId, query, options, (response) => { Api.userProjects(userId, query, options, (response) => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); resolve();
});
}); });
}); });
}); });
describe('commitPipelines', () => { describe('commitPipelines', () => {
it('fetches pipelines for a given commit', (done) => { it('fetches pipelines for a given commit', () => {
const projectId = 'example/foobar'; const projectId = 'example/foobar';
const commitSha = 'abc123def'; const commitSha = 'abc123def';
const expectedUrl = `${dummyUrlRoot}/${projectId}/commit/${commitSha}/pipelines`; const expectedUrl = `${dummyUrlRoot}/${projectId}/commit/${commitSha}/pipelines`;
...@@ -946,13 +933,10 @@ describe('Api', () => { ...@@ -946,13 +933,10 @@ describe('Api', () => {
}, },
]); ]);
Api.commitPipelines(projectId, commitSha) return Api.commitPipelines(projectId, commitSha).then(({ data }) => {
.then(({ data }) => {
expect(data.length).toBe(1); expect(data.length).toBe(1);
expect(data[0].name).toBe('test'); expect(data[0].name).toBe('test');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -977,7 +961,7 @@ describe('Api', () => { ...@@ -977,7 +961,7 @@ describe('Api', () => {
}); });
describe('createBranch', () => { describe('createBranch', () => {
it('creates new branch', (done) => { it('creates new branch', () => {
const ref = 'main'; const ref = 'main';
const branch = 'new-branch-name'; const branch = 'new-branch-name';
const dummyProjectPath = 'gitlab-org/gitlab-ce'; const dummyProjectPath = 'gitlab-org/gitlab-ce';
...@@ -991,18 +975,15 @@ describe('Api', () => { ...@@ -991,18 +975,15 @@ describe('Api', () => {
name: branch, name: branch,
}); });
Api.createBranch(dummyProjectPath, { ref, branch }) return Api.createBranch(dummyProjectPath, { ref, branch }).then(({ data }) => {
.then(({ data }) => {
expect(data.name).toBe(branch); expect(data.name).toBe(branch);
expect(axios.post).toHaveBeenCalledWith(expectedUrl, { ref, branch }); expect(axios.post).toHaveBeenCalledWith(expectedUrl, { ref, branch });
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('projectForks', () => { describe('projectForks', () => {
it('gets forked projects', (done) => { it('gets forked projects', () => {
const dummyProjectPath = 'gitlab-org/gitlab-ce'; const dummyProjectPath = 'gitlab-org/gitlab-ce';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent( const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
dummyProjectPath, dummyProjectPath,
...@@ -1012,20 +993,17 @@ describe('Api', () => { ...@@ -1012,20 +993,17 @@ describe('Api', () => {
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, ['fork']); mock.onGet(expectedUrl).replyOnce(httpStatus.OK, ['fork']);
Api.projectForks(dummyProjectPath, { visibility: 'private' }) return Api.projectForks(dummyProjectPath, { visibility: 'private' }).then(({ data }) => {
.then(({ data }) => {
expect(data).toEqual(['fork']); expect(data).toEqual(['fork']);
expect(axios.get).toHaveBeenCalledWith(expectedUrl, { expect(axios.get).toHaveBeenCalledWith(expectedUrl, {
params: { visibility: 'private' }, params: { visibility: 'private' },
}); });
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('createContextCommits', () => { describe('createContextCommits', () => {
it('creates a new context commit', (done) => { it('creates a new context commit', () => {
const projectPath = 'abc'; const projectPath = 'abc';
const mergeRequestId = '123456'; const mergeRequestId = '123456';
const commitsData = ['abcdefg']; const commitsData = ['abcdefg'];
...@@ -1044,17 +1022,16 @@ describe('Api', () => { ...@@ -1044,17 +1022,16 @@ describe('Api', () => {
}, },
]); ]);
Api.createContextCommits(projectPath, mergeRequestId, expectedData) return Api.createContextCommits(projectPath, mergeRequestId, expectedData).then(
.then(({ data }) => { ({ data }) => {
expect(data[0].title).toBe('Dummy commit'); expect(data[0].title).toBe('Dummy commit');
}) },
.then(done) );
.catch(done.fail);
}); });
}); });
describe('allContextCommits', () => { describe('allContextCommits', () => {
it('gets all context commits', (done) => { it('gets all context commits', () => {
const projectPath = 'abc'; const projectPath = 'abc';
const mergeRequestId = '123456'; const mergeRequestId = '123456';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/context_commits`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/context_commits`;
...@@ -1065,17 +1042,14 @@ describe('Api', () => { ...@@ -1065,17 +1042,14 @@ describe('Api', () => {
.onGet(expectedUrl) .onGet(expectedUrl)
.replyOnce(200, [{ id: 'abcdef', short_id: 'abcdefghi', title: 'Dummy commit title' }]); .replyOnce(200, [{ id: 'abcdef', short_id: 'abcdefghi', title: 'Dummy commit title' }]);
Api.allContextCommits(projectPath, mergeRequestId) return Api.allContextCommits(projectPath, mergeRequestId).then(({ data }) => {
.then(({ data }) => {
expect(data[0].title).toBe('Dummy commit title'); expect(data[0].title).toBe('Dummy commit title');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
describe('removeContextCommits', () => { describe('removeContextCommits', () => {
it('removes context commits', (done) => { it('removes context commits', () => {
const projectPath = 'abc'; const projectPath = 'abc';
const mergeRequestId = '123456'; const mergeRequestId = '123456';
const commitsData = ['abcdefg']; const commitsData = ['abcdefg'];
...@@ -1088,12 +1062,9 @@ describe('Api', () => { ...@@ -1088,12 +1062,9 @@ describe('Api', () => {
mock.onDelete(expectedUrl).replyOnce(204); mock.onDelete(expectedUrl).replyOnce(204);
Api.removeContextCommits(projectPath, mergeRequestId, expectedData) return Api.removeContextCommits(projectPath, mergeRequestId, expectedData).then(() => {
.then(() => {
expect(axios.delete).toHaveBeenCalledWith(expectedUrl, { data: expectedData }); expect(axios.delete).toHaveBeenCalledWith(expectedUrl, { data: expectedData });
}) });
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -1336,41 +1307,37 @@ describe('Api', () => { ...@@ -1336,41 +1307,37 @@ describe('Api', () => {
}); });
describe('updateIssue', () => { describe('updateIssue', () => {
it('update an issue with the given payload', (done) => { it('update an issue with the given payload', () => {
const projectId = 8; const projectId = 8;
const issue = 1; const issue = 1;
const expectedArray = [1, 2, 3]; const expectedArray = [1, 2, 3];
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/issues/${issue}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/issues/${issue}`;
mock.onPut(expectedUrl).reply(httpStatus.OK, { assigneeIds: expectedArray }); mock.onPut(expectedUrl).reply(httpStatus.OK, { assigneeIds: expectedArray });
Api.updateIssue(projectId, issue, { assigneeIds: expectedArray }) return Api.updateIssue(projectId, issue, { assigneeIds: expectedArray }).then(({ data }) => {
.then(({ data }) => {
expect(data.assigneeIds).toEqual(expectedArray); expect(data.assigneeIds).toEqual(expectedArray);
done(); });
})
.catch(done.fail);
}); });
}); });
describe('updateMergeRequest', () => { describe('updateMergeRequest', () => {
it('update an issue with the given payload', (done) => { it('update an issue with the given payload', () => {
const projectId = 8; const projectId = 8;
const mergeRequest = 1; const mergeRequest = 1;
const expectedArray = [1, 2, 3]; const expectedArray = [1, 2, 3];
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/merge_requests/${mergeRequest}`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/merge_requests/${mergeRequest}`;
mock.onPut(expectedUrl).reply(httpStatus.OK, { assigneeIds: expectedArray }); mock.onPut(expectedUrl).reply(httpStatus.OK, { assigneeIds: expectedArray });
Api.updateMergeRequest(projectId, mergeRequest, { assigneeIds: expectedArray }) return Api.updateMergeRequest(projectId, mergeRequest, { assigneeIds: expectedArray }).then(
.then(({ data }) => { ({ data }) => {
expect(data.assigneeIds).toEqual(expectedArray); expect(data.assigneeIds).toEqual(expectedArray);
done(); },
}) );
.catch(done.fail);
}); });
}); });
describe('tags', () => { describe('tags', () => {
it('fetches all tags of a particular project', (done) => { it('fetches all tags of a particular project', () => {
const query = 'dummy query'; const query = 'dummy query';
const options = { unused: 'option' }; const options = { unused: 'option' };
const projectId = 8; const projectId = 8;
...@@ -1381,13 +1348,10 @@ describe('Api', () => { ...@@ -1381,13 +1348,10 @@ describe('Api', () => {
}, },
]); ]);
Api.tags(projectId, query, options) return Api.tags(projectId, query, options).then(({ data }) => {
.then(({ data }) => {
expect(data.length).toBe(1); expect(data.length).toBe(1);
expect(data[0].name).toBe('test'); expect(data[0].name).toBe('test');
}) });
.then(done)
.catch(done.fail);
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment