diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-14 18:12:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-14 18:12:05 +0300 |
commit | b119503b7039d1e79b87300a145afdcd1145c2d6 (patch) | |
tree | 9977d51c4fd8177a20f1805c14f0cb6750baee1c /spec/frontend/api | |
parent | d378fdaa60adb7217e3fc798580ad206127728d5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/api')
-rw-r--r-- | spec/frontend/api/projects_api_spec.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/frontend/api/projects_api_spec.js b/spec/frontend/api/projects_api_spec.js new file mode 100644 index 00000000000..8f40b557e1f --- /dev/null +++ b/spec/frontend/api/projects_api_spec.js @@ -0,0 +1,62 @@ +import MockAdapter from 'axios-mock-adapter'; +import * as projectsApi from '~/api/projects_api'; +import axios from '~/lib/utils/axios_utils'; + +describe('~/api/projects_api.js', () => { + let mock; + let originalGon; + + const projectId = 1; + + beforeEach(() => { + mock = new MockAdapter(axios); + + originalGon = window.gon; + window.gon = { api_version: 'v7' }; + }); + + afterEach(() => { + mock.restore(); + window.gon = originalGon; + }); + + describe('getProjects', () => { + beforeEach(() => { + jest.spyOn(axios, 'get'); + }); + + it('retrieves projects from the correct URL and returns them in the response data', () => { + const expectedUrl = '/api/v7/projects.json'; + const expectedParams = { params: { per_page: 20, search: '', simple: true } }; + const expectedProjects = [{ name: 'project 1' }]; + const query = ''; + const options = {}; + + mock.onGet(expectedUrl).reply(200, { data: expectedProjects }); + + return projectsApi.getProjects(query, options).then(({ data }) => { + expect(axios.get).toHaveBeenCalledWith(expectedUrl, expectedParams); + expect(data.data).toEqual(expectedProjects); + }); + }); + }); + + describe('importProjectMembers', () => { + beforeEach(() => { + jest.spyOn(axios, 'post'); + }); + + it('posts to the correct URL and returns the response message', () => { + const targetId = 2; + const expectedUrl = '/api/v7/projects/1/import_project_members/2'; + const expectedMessage = 'Successfully imported'; + + mock.onPost(expectedUrl).replyOnce(200, expectedMessage); + + return projectsApi.importProjectMembers(projectId, targetId).then(({ data }) => { + expect(axios.post).toHaveBeenCalledWith(expectedUrl); + expect(data).toEqual(expectedMessage); + }); + }); + }); +}); |