Merge branch 'hotfix/21.56.9' into master
[gitter.git] / modules / gitlab / test / gitlab-issuable-service-test.js
blob00f141dead551b5021c26419d0d3c3032a7bfa08
1 'use strict';
3 const Promise = require('bluebird');
4 const assert = require('assert');
5 const proxyquireNoCallThru = require('proxyquire').noCallThru();
6 //const GitLabIssuableService = require('..').GitLabIssuableService;
7 const fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
8 const TestError = require('gitter-web-test-utils/lib/test-error');
10 describe.skip('gitlab-issue-service #slow #gitlab', function() {
11 // These tests timeout at 10000 sometimes otherwise
12 this.timeout(30000);
14 fixtureLoader.ensureIntegrationEnvironment(
15 'GITLAB_USER_USERNAME',
16 'GITLAB_USER_TOKEN',
17 'GITLAB_PUBLIC_PROJECT1_URI',
18 'GITLAB_PRIVATE_PROJECT1_URI',
19 'GITLAB_UNAUTHORIZED_PRIVATE_PROJECT1_URI'
22 const FAKE_USER = {
23 username: 'FAKE_USER'
26 let oauthToken = null;
27 let GitLabIssuableService;
29 beforeEach(() => {
30 GitLabIssuableService = proxyquireNoCallThru('../lib/issuable-service', {
31 './get-gitlab-access-token-from-user': function() {
32 return Promise.resolve(oauthToken);
34 });
35 });
37 afterEach(() => {
38 oauthToken = null;
39 });
41 describe('as a GitLab user', () => {
42 beforeEach(() => {
43 oauthToken = fixtureLoader.GITLAB_USER_TOKEN;
44 });
46 it('should fetch public issue', () => {
47 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
48 return glService.getIssue(fixtureLoader.GITLAB_PUBLIC_PROJECT1_URI, 1).then(issue => {
49 assert.strictEqual(issue.iid, 1);
50 assert.strictEqual(issue.state, 'open');
51 assert.strictEqual(issue.author.username, fixtureLoader.GITLAB_USER_USERNAME);
52 });
53 });
55 it("shouldn't fetch missing issue", () => {
56 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
57 return glService
58 .getIssue(fixtureLoader.GITLAB_PUBLIC_PROJECT1_URI, 999999)
59 .then(() => {
60 assert.fail(new TestError("Shouldn't be able to fetch missing issue"));
62 .catch(err => {
63 if (err instanceof TestError) {
64 throw err;
67 assert.strictEqual(err.status, 404);
68 });
69 });
71 it('should fetch confidential issue', () => {
72 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
73 return glService.getIssue(fixtureLoader.GITLAB_PUBLIC_PROJECT1_URI, 2).then(issue => {
74 assert.strictEqual(issue.iid, 2);
75 assert.strictEqual(issue.state, 'open');
76 assert.strictEqual(issue.author.username, fixtureLoader.GITLAB_USER_USERNAME);
77 });
78 });
80 it('should fetch private issue', () => {
81 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
82 return glService.getIssue(fixtureLoader.GITLAB_PRIVATE_PROJECT1_URI, 1).then(issue => {
83 assert.strictEqual(issue.iid, 1);
84 assert.strictEqual(issue.state, 'open');
85 assert.strictEqual(issue.author.username, fixtureLoader.GITLAB_USER_USERNAME);
86 });
87 });
89 it("shouldn't fetch issue in unauthorized private project", () => {
90 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
91 return glService
92 .getIssue(fixtureLoader.GITLAB_UNAUTHORIZED_PRIVATE_PROJECT1_URI, 1)
93 .then(() => {
94 assert.fail(
95 new TestError("Shouldn't be able to fetch issue in unauthorized private project")
98 .catch(err => {
99 if (err instanceof TestError) {
100 throw err;
103 assert.strictEqual(err.status, 404);
108 describe('using public token pool', () => {
109 beforeEach(() => {
110 oauthToken = null;
113 it('should fetch public issue', () => {
114 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
115 return glService.getIssue(fixtureLoader.GITLAB_PUBLIC_PROJECT1_URI, 1).then(issue => {
116 assert.strictEqual(issue.iid, 1);
117 assert.strictEqual(issue.state, 'open');
118 assert.strictEqual(issue.author.username, fixtureLoader.GITLAB_USER_USERNAME);
122 it("shouldn't fetch confidential issue", () => {
123 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
124 return glService
125 .getIssue(fixtureLoader.GITLAB_PUBLIC_PROJECT1_URI, 2)
126 .then(() => {
127 assert.fail(new TestError("Shouldn't be able to fetch confidential issue"));
129 .catch(err => {
130 if (err instanceof TestError) {
131 throw err;
134 assert.strictEqual(err.status, 404);
138 it("shouldn't fetch private issue", () => {
139 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
140 return glService
141 .getIssue(fixtureLoader.GITLAB_PRIVATE_PROJECT1_URI, 1)
142 .then(() => {
143 assert.fail(
144 new TestError("Shouldn't be able to fetch issue in unauthorized private project")
147 .catch(err => {
148 if (err instanceof TestError) {
149 throw err;
152 assert.strictEqual(err.status, 404);
156 it("shouldn't fetch issue in unauthorized private project", () => {
157 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
158 return glService
159 .getIssue(fixtureLoader.GITLAB_UNAUTHORIZED_PRIVATE_PROJECT1_URI, 1)
160 .then(() => {
161 assert.fail(
162 new TestError("Shouldn't be able to fetch issue in unauthorized private project")
165 .catch(err => {
166 if (err instanceof TestError) {
167 throw err;
170 assert.strictEqual(err.status, 404);