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
15 fixtureLoader.ensureIntegrationEnvironment('GITLAB_USER_TOKEN', 'GITLAB_PUBLIC_PROJECT1_URI');
21 let oauthToken = null;
22 let GitLabProjectService;
25 GitLabProjectService = proxyquireNoCallThru('../lib/project-service', {
26 './get-gitlab-access-token-from-user': function() {
27 return Promise.resolve(oauthToken);
36 describe('as a GitLab user', () => {
38 oauthToken = fixtureLoader.GITLAB_USER_TOKEN;
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
47 assert(projects.length > 0);
48 projects.forEach(project => {
52 'project has not gone through the standardized'
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
62 const ownerProjects = await glProjectService.getProjects({
63 min_access_level: OWNER_ACCESS_LEVEL
66 // We expect the GitLab integration user to be part of many projects but
67 // only an owner in some of those projects
69 allProjects.length > ownerProjects.length,
70 `Expected allProjects(${allProjects.length}) > ownerProjects(${ownerProjects.length})`
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);
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
92 assert.deepEqual(membership, {
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
109 assert.deepEqual(membership, {
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',
125 assert.deepEqual(membership, {
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
142 assert.deepEqual(membership, {