Merge branch 'hotfix/21.56.9' into master
[gitter.git] / modules / gitlab / test / gitlab-group-service-test.js
blobc068049cb7d5978364dac8ec36384b0125ad25af
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 OWNER_ACCESS_LEVEL = 50;
10 describe.skip('gitlab-group-service #flakey #slow #gitlab', function() {
11 // These tests timeout at 10000 sometimes otherwise
12 this.timeout(30000);
14 fixtureLoader.ensureIntegrationEnvironment('GITLAB_USER_TOKEN', 'GITLAB_GROUP1_URI');
16 const FAKE_USER = {
17 username: 'FAKE_USER'
20 let oauthToken = null;
21 let GitLabGroupService;
23 beforeEach(() => {
24 GitLabGroupService = proxyquireNoCallThru('../lib/group-service', {
25 './get-gitlab-access-token-from-user': function() {
26 return Promise.resolve(oauthToken);
28 });
29 });
31 afterEach(() => {
32 oauthToken = null;
33 });
35 describe('as a GitLab user', () => {
36 beforeEach(() => {
37 oauthToken = fixtureLoader.GITLAB_USER_TOKEN;
38 });
40 describe('getGroups', () => {
41 it('should fetch groups', async () => {
42 const glGroupService = new GitLabGroupService(FAKE_USER);
43 const groups = await glGroupService.getGroups();
44 assert(groups.length > 0);
45 groups.forEach(group => {
46 assert.strictEqual(
47 group.backend,
48 'gitlab',
49 'group has not gone through the standardized'
51 });
52 });
54 it('should fetch groups with parameters', async () => {
55 const glService = new GitLabGroupService(FAKE_USER);
56 const allGroups = await glService.getGroups();
57 const ownerGroups = await glService.getGroups({ min_access_level: OWNER_ACCESS_LEVEL });
59 // We expect the GitLab integration user to be part of many groups but
60 // only an owner in some of those groups
61 assert(
62 allGroups.length > ownerGroups.length,
63 `Expected allGroups(${allGroups.length}) > ownerGroups(${ownerGroups.length})`
65 });
66 });
68 it('should fetch group', async () => {
69 const glGroupService = new GitLabGroupService(FAKE_USER);
70 const group = await glGroupService.getGroup(fixtureLoader.GITLAB_GROUP1_URI);
71 assert.equal(group.backend, 'gitlab', 'group has not gone through the standardized');
72 assert.equal(group.uri, fixtureLoader.GITLAB_GROUP1_URI);
73 });
75 describe('getMembership', () => {
76 it('should fetch group member', async () => {
77 const glGroupService = new GitLabGroupService(FAKE_USER);
78 // User: https://gitlab.com/gitter-integration-tests
79 const gitterIntegrationTestsUserId = '2619770';
80 const membership = await glGroupService.getMembership(
81 'gitter-integration-tests-group',
82 gitterIntegrationTestsUserId
85 assert.deepEqual(membership, {
86 accessLevel: 50,
87 isMember: true,
88 isMaintainer: true,
89 isOwner: true
90 });
91 });
93 it('should fetch group member from inherited members', async () => {
94 const glGroupService = new GitLabGroupService(FAKE_USER);
95 // User: https://gitlab.com/gitter-integration-tests
96 const gitterIntegrationTestsUserId = '2619770';
97 const membership = await glGroupService.getMembership(
98 'gitter-integration-tests-group/subgroup-inherited-members',
99 gitterIntegrationTestsUserId
102 assert.deepEqual(membership, {
103 accessLevel: 50,
104 isMember: true,
105 isMaintainer: true,
106 isOwner: true
110 it('should return false for non-existant group member', async () => {
111 const glGroupService = new GitLabGroupService(FAKE_USER);
112 const nonExistantUserId = '999999';
113 const membership = await glGroupService.getMembership(
114 'gitter-integration-tests-group',
115 nonExistantUserId
118 assert.deepEqual(membership, {
119 accessLevel: 0,
120 isMember: false,
121 isMaintainer: false,
122 isOwner: false
126 it('should not be isOwner when only maintainer', async () => {
127 const glGroupService = new GitLabGroupService(FAKE_USER);
128 // User: https://gitlab.com/gitter-integration-tests
129 const gitterIntegrationTestsUserId = '2619770';
130 const membership = await glGroupService.getMembership(
131 'gitter-integration-tests-maintainer-group',
132 gitterIntegrationTestsUserId
135 assert.deepEqual(membership, {
136 accessLevel: 40,
137 isMember: true,
138 isMaintainer: true,
139 isOwner: false