diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 15:09:08 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 15:09:08 +0000 |
commit | b3a736ed88a1db0391cd9881e70b987bab7d89d1 (patch) | |
tree | a91ca3a06abd4c3412775ac3c49b11e3151df2be /spec/frontend/ide | |
parent | 5366964a10484c2783a646b35a6da9eece01b242 (diff) | |
download | gitlab-ce-b3a736ed88a1db0391cd9881e70b987bab7d89d1.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide')
-rw-r--r-- | spec/frontend/ide/mock_data.js | 1 | ||||
-rw-r--r-- | spec/frontend/ide/services/index_spec.js | 31 | ||||
-rw-r--r-- | spec/frontend/ide/stores/getters_spec.js | 36 |
3 files changed, 67 insertions, 1 deletions
diff --git a/spec/frontend/ide/mock_data.js b/spec/frontend/ide/mock_data.js index a1b57dca6bc..472516b6a2c 100644 --- a/spec/frontend/ide/mock_data.js +++ b/spec/frontend/ide/mock_data.js @@ -18,6 +18,7 @@ export const projectData = { }, mergeRequests: {}, merge_requests_enabled: true, + userPermissions: {}, default_branch: 'master', }; diff --git a/spec/frontend/ide/services/index_spec.js b/spec/frontend/ide/services/index_spec.js index 83a3cfe618b..55f174f4663 100644 --- a/spec/frontend/ide/services/index_spec.js +++ b/spec/frontend/ide/services/index_spec.js @@ -2,11 +2,17 @@ import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; import services from '~/ide/services'; import Api from '~/api'; +import gqClient from '~/ide/services/gql'; import { escapeFileUrl } from '~/lib/utils/url_utility'; +import getUserPermissions from '~/ide/queries/getUserPermissions.query.graphql'; +import { projectData } from '../mock_data'; jest.mock('~/api'); +jest.mock('~/ide/services/gql'); -const TEST_PROJECT_ID = 'alice/wonderland'; +const TEST_NAMESPACE = 'alice'; +const TEST_PROJECT = 'wonderland'; +const TEST_PROJECT_ID = `${TEST_NAMESPACE}/${TEST_PROJECT}`; const TEST_BRANCH = 'master-patch-123'; const TEST_COMMIT_SHA = '123456789'; const TEST_FILE_PATH = 'README2.md'; @@ -111,4 +117,27 @@ describe('IDE services', () => { }, ); }); + + describe('getProjectData', () => { + it('combines gql and API requests', () => { + const gqlProjectData = { + userPermissions: { + bogus: true, + }, + }; + Api.project.mockReturnValue(Promise.resolve({ data: { ...projectData } })); + gqClient.query.mockReturnValue(Promise.resolve({ data: { project: gqlProjectData } })); + + return services.getProjectData(TEST_NAMESPACE, TEST_PROJECT).then(response => { + expect(response).toEqual({ data: { ...projectData, ...gqlProjectData } }); + expect(Api.project).toHaveBeenCalledWith(TEST_PROJECT_ID); + expect(gqClient.query).toHaveBeenCalledWith({ + query: getUserPermissions, + variables: { + projectPath: TEST_PROJECT_ID, + }, + }); + }); + }); + }); }); diff --git a/spec/frontend/ide/stores/getters_spec.js b/spec/frontend/ide/stores/getters_spec.js index 21c5e886738..011be95c1d2 100644 --- a/spec/frontend/ide/stores/getters_spec.js +++ b/spec/frontend/ide/stores/getters_spec.js @@ -2,6 +2,8 @@ import * as getters from '~/ide/stores/getters'; import { createStore } from '~/ide/stores'; import { file } from '../helpers'; +const TEST_PROJECT_ID = 'test_project'; + describe('IDE store getters', () => { let localState; let localStore; @@ -398,4 +400,38 @@ describe('IDE store getters', () => { }, ); }); + + describe('findProjectPermissions', () => { + it('returns false if project not found', () => { + expect(localStore.getters.findProjectPermissions(TEST_PROJECT_ID)).toEqual({}); + }); + + it('finds permission in given project', () => { + const userPermissions = { + readMergeRequest: true, + createMergeRequestsIn: false, + }; + + localState.projects[TEST_PROJECT_ID] = { userPermissions }; + + expect(localStore.getters.findProjectPermissions(TEST_PROJECT_ID)).toBe(userPermissions); + }); + }); + + describe.each` + getterName | permissionKey + ${'canReadMergeRequests'} | ${'readMergeRequest'} + ${'canCreateMergeRequests'} | ${'createMergeRequestIn'} + `('$getterName', ({ getterName, permissionKey }) => { + it.each([true, false])('finds permission for current project (%s)', val => { + localState.projects[TEST_PROJECT_ID] = { + userPermissions: { + [permissionKey]: val, + }, + }; + localState.currentProjectId = TEST_PROJECT_ID; + + expect(localStore.getters[getterName]).toBe(val); + }); + }); }); |