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
14 fixtureLoader.ensureIntegrationEnvironment('GITLAB_USER_TOKEN', 'GITLAB_GROUP1_URI');
20 let oauthToken = null;
21 let GitLabGroupService;
24 GitLabGroupService = proxyquireNoCallThru('../lib/group-service', {
25 './get-gitlab-access-token-from-user': function() {
26 return Promise.resolve(oauthToken);
35 describe('as a GitLab user', () => {
37 oauthToken = fixtureLoader.GITLAB_USER_TOKEN;
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 => {
49 'group has not gone through the standardized'
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
62 allGroups.length > ownerGroups.length,
63 `Expected allGroups(${allGroups.length}) > ownerGroups(${ownerGroups.length})`
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);
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, {
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, {
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',
118 assert.deepEqual(membership, {
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, {