Merge branch 'hotfix/21.56.9' into master
[gitter.git] / modules / gitlab / test / gitlab-project-service-test.js
blob270711f4336e6587ce2bbfb43b3370a42f3f9e18
1 'use strict';
3 const assert = require('assert');
4 const proxyquireNoCallThru = require('proxyquire').noCallThru();
5 const fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
7 // https://docs.gitlab.com/ee/api/access_requests.html
8 const GUEST_ACCESS_LEVEL = 10;
9 const OWNER_ACCESS_LEVEL = 50;
11 describe.skip('gitlab-project-service #flakey #slow #gitlab', function() {
12   // These tests timeout at 10000 sometimes otherwise
13   this.timeout(30000);
15   fixtureLoader.ensureIntegrationEnvironment('GITLAB_USER_TOKEN', 'GITLAB_PUBLIC_PROJECT1_URI');
17   const FAKE_USER = {
18     username: 'FAKE_USER'
19   };
21   let oauthToken = null;
22   let GitLabProjectService;
24   beforeEach(() => {
25     GitLabProjectService = proxyquireNoCallThru('../lib/project-service', {
26       './get-gitlab-access-token-from-user': function() {
27         return Promise.resolve(oauthToken);
28       }
29     });
30   });
32   afterEach(() => {
33     oauthToken = null;
34   });
36   describe('as a GitLab user', () => {
37     beforeEach(() => {
38       oauthToken = fixtureLoader.GITLAB_USER_TOKEN;
39     });
41     describe('getProjects', () => {
42       it('should fetch projects', async () => {
43         const glProjectService = new GitLabProjectService(FAKE_USER);
44         const projects = await glProjectService.getProjects({
45           min_access_level: GUEST_ACCESS_LEVEL
46         });
47         assert(projects.length > 0);
48         projects.forEach(project => {
49           assert.strictEqual(
50             project.backend,
51             'gitlab',
52             'project has not gone through the standardized'
53           );
54         });
55       });
57       it('should fetch projects with parameters', async () => {
58         const glProjectService = new GitLabProjectService(FAKE_USER);
59         const allProjects = await glProjectService.getProjects({
60           min_access_level: GUEST_ACCESS_LEVEL
61         });
62         const ownerProjects = await glProjectService.getProjects({
63           min_access_level: OWNER_ACCESS_LEVEL
64         });
66         // We expect the GitLab integration user to be part of many projects but
67         // only an owner in some of those projects
68         assert(
69           allProjects.length > ownerProjects.length,
70           `Expected allProjects(${allProjects.length}) > ownerProjects(${ownerProjects.length})`
71         );
72       });
73     });
75     it('should fetch project', async () => {
76       const glProjectService = new GitLabProjectService(FAKE_USER);
77       const project = await glProjectService.getProject(fixtureLoader.GITLAB_PUBLIC_PROJECT1_URI);
78       assert.equal(project.backend, 'gitlab', 'project has not gone through the standardized');
79       assert.equal(project.uri, fixtureLoader.GITLAB_PUBLIC_PROJECT1_URI);
80     });
82     describe('getMembership', () => {
83       it('should fetch project member', async () => {
84         const glProjectService = new GitLabProjectService(FAKE_USER);
85         // User: https://gitlab.com/gitter-integration-tests
86         const gitterIntegrationTestsUserId = '2619770';
87         const membership = await glProjectService.getMembership(
88           'gitter-integration-tests-group/public-project1',
89           gitterIntegrationTestsUserId
90         );
92         assert.deepEqual(membership, {
93           accessLevel: 50,
94           isMember: true,
95           isMaintainer: true,
96           isOwner: true
97         });
98       });
100       it('should fetch project member from inherited members', async () => {
101         const glProjectService = new GitLabProjectService(FAKE_USER);
102         // User: https://gitlab.com/gitter-integration-tests
103         const gitterIntegrationTestsUserId = '2619770';
104         const membership = await glProjectService.getMembership(
105           'gitter-integration-tests-group/subgroup-inherited-members/public-project1',
106           gitterIntegrationTestsUserId
107         );
109         assert.deepEqual(membership, {
110           accessLevel: 50,
111           isMember: true,
112           isMaintainer: true,
113           isOwner: true
114         });
115       });
117       it('should return false for non-existant project member', async () => {
118         const glProjectService = new GitLabProjectService(FAKE_USER);
119         const nonExistantUserId = '999999';
120         const membership = await glProjectService.getMembership(
121           'gitter-integration-tests-group',
122           nonExistantUserId
123         );
125         assert.deepEqual(membership, {
126           accessLevel: 0,
127           isMember: false,
128           isMaintainer: false,
129           isOwner: false
130         });
131       });
133       it('should not be isOwner when only maintainer', async () => {
134         const glProjectService = new GitLabProjectService(FAKE_USER);
135         // User: https://gitlab.com/gitter-integration-tests
136         const gitterIntegrationTestsUserId = '2619770';
137         const membership = await glProjectService.getMembership(
138           'gitter-integration-tests-maintainer-group/maintainer-project1',
139           gitterIntegrationTestsUserId
140         );
142         assert.deepEqual(membership, {
143           accessLevel: 40,
144           isMember: true,
145           isMaintainer: true,
146           isOwner: false
147         });
148       });
149     });
150   });