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({
12 let validateGitlabUri;
13 let getUserByUsernameStub;
17 getUserByUsernameStub = null;
19 getProjectStub = null;
20 validateGitlabUri = proxyquireNoCallThru('../lib/gitlab-uri-validator', {
21 './user-service': function() {
23 getUserByUsername: getUserByUsernameStub
26 './group-service': function() {
28 getGroup: getGroupStub
31 './project-service': function() {
33 getProject: getProjectStub
39 it('validate real group', async () => {
40 getGroupStub = () => {
44 name: 'GitLab.org / gitter',
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');
54 assert.strictEqual(gitlabInfo.type, 'GROUP');
55 assert.strictEqual(gitlabInfo.uri, 'gitlab-org/gitter');
56 assert.strictEqual(gitlabInfo.externalId, 1540914);
59 it('validate real project', async () => {
60 getProjectStub = () => {
64 name: 'public-project1',
66 absoluteUri: 'https://gitlab.com/gitter-integration-tests-group/public-project1',
67 uri: 'gitter-integration-tests-group/public-project1',
73 const gitlabInfo = await validateGitlabUri(fixture.user1, 'gitterHQ/webapp');
75 assert.strictEqual(gitlabInfo.type, 'PROJECT');
76 assert.strictEqual(gitlabInfo.uri, 'gitter-integration-tests-group/public-project1');
77 assert.strictEqual(gitlabInfo.externalId, 7616684);
80 it('validate real user', async () => {
81 getUserByUsernameStub = () => {
84 name: 'Gitter Badger',
85 username: 'gitter-badger',
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',
102 it('validate nonexistant group does not throw', async () => {
103 getGroupStub = () => {
104 const err = new Error('Fake HTTPError: Not Found');
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');
122 const gitlabInfo = await validateGitlabUri(
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');
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');
149 const gitlabInfo = await validateGitlabUri(fixture.user1, 'foo-foo-does-not-exist');
150 assert.strictEqual(gitlabInfo, null);