Merge branch 'hotfix/21.56.9' into master
[gitter.git] / modules / gitlab / test / gitlab-uri-validator-test.js
blob4dc1d89756f63eaf855505ac61671a4cd108a213
1 'use strict';
3 const assert = require('assert');
4 const fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
5 const proxyquireNoCallThru = require('proxyquire').noCallThru();
7 describe('gitlab-uri-validator #slow #gitlab', function() {
8 const fixture = fixtureLoader.setup({
9 user1: {}
10 });
12 let validateGitlabUri;
13 let getUserByUsernameStub;
14 let getGroupStub;
15 let getProjectStub;
16 beforeEach(() => {
17 getUserByUsernameStub = null;
18 getGroupStub = null;
19 getProjectStub = null;
20 validateGitlabUri = proxyquireNoCallThru('../lib/gitlab-uri-validator', {
21 './user-service': function() {
22 return {
23 getUserByUsername: getUserByUsernameStub
26 './group-service': function() {
27 return {
28 getGroup: getGroupStub
31 './project-service': function() {
32 return {
33 getProject: getProjectStub
36 });
37 });
39 it('validate real group', async () => {
40 getGroupStub = () => {
41 return {
42 backend: 'gitlab',
43 id: 1540914,
44 name: 'GitLab.org / gitter',
45 avatar_url:
46 'https://assets.gitlab-static.net/uploads/-/system/group/avatar/1540914/icon_128x128.png',
47 uri: 'gitlab-org/gitter',
48 absoluteUri: 'https://gitlab.com/groups/gitlab-org/gitter'
52 const gitlabInfo = await validateGitlabUri(fixture.user1, 'gitlab-org/gitter');
53 assert(gitlabInfo);
54 assert.strictEqual(gitlabInfo.type, 'GROUP');
55 assert.strictEqual(gitlabInfo.uri, 'gitlab-org/gitter');
56 assert.strictEqual(gitlabInfo.externalId, 1540914);
57 });
59 it('validate real project', async () => {
60 getProjectStub = () => {
61 return {
62 backend: 'gitlab',
63 id: 7616684,
64 name: 'public-project1',
65 description: '',
66 absoluteUri: 'https://gitlab.com/gitter-integration-tests-group/public-project1',
67 uri: 'gitter-integration-tests-group/public-project1',
68 private: false,
69 avatar_url: null
73 const gitlabInfo = await validateGitlabUri(fixture.user1, 'gitterHQ/webapp');
74 assert(gitlabInfo);
75 assert.strictEqual(gitlabInfo.type, 'PROJECT');
76 assert.strictEqual(gitlabInfo.uri, 'gitter-integration-tests-group/public-project1');
77 assert.strictEqual(gitlabInfo.externalId, 7616684);
78 });
80 it('validate real user', async () => {
81 getUserByUsernameStub = () => {
82 return {
83 id: 1577466,
84 name: 'Gitter Badger',
85 username: 'gitter-badger',
86 state: 'active',
87 avatar_url:
88 'https://assets.gitlab-static.net/uploads/-/system/user/avatar/1577466/avatar.png',
89 web_url: 'https://gitlab.com/gitter-badger'
93 const gitlabInfo = await validateGitlabUri(fixture.user1, 'gitter-badger');
94 assert.deepEqual(gitlabInfo, {
95 description: 'Gitter Badger',
96 externalId: 1577466,
97 type: 'USER',
98 uri: 'gitter-badger'
99 });
102 it('validate nonexistant group does not throw', async () => {
103 getGroupStub = () => {
104 const err = new Error('Fake HTTPError: Not Found');
105 err.response = {
106 status: 404
110 const gitlabInfo = await validateGitlabUri(fixture.user1, 'foo-foo-does-not-exist');
111 assert.strictEqual(gitlabInfo, null);
114 it('validate nonexistant project does not throw', async () => {
115 getProjectStub = () => {
116 const err = new Error('Fake HTTPError: Not Found');
117 err.response = {
118 status: 404
122 const gitlabInfo = await validateGitlabUri(
123 fixture.user1,
124 'foo-foo-does-not-exist/bar-bar-what-up'
126 assert.strictEqual(gitlabInfo, null);
129 it('Connection problem to GitLab will throw', async () => {
130 getGroupStub = () => {
131 const err = new Error('Fake HTTPError: Not Found');
132 err.response = {
133 status: 500
137 const gitlabInfo = await validateGitlabUri(fixture.user1, 'foo-foo-does-not-exist');
138 assert.strictEqual(gitlabInfo, null);
141 it('Permission problem to GitLab will throw', async () => {
142 getGroupStub = () => {
143 const err = new Error('Fake HTTPError: Not Found');
144 err.response = {
145 status: 403
149 const gitlabInfo = await validateGitlabUri(fixture.user1, 'foo-foo-does-not-exist');
150 assert.strictEqual(gitlabInfo, null);