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
14 fixtureLoader.ensureIntegrationEnvironment(
15 'GITLAB_USER_USERNAME',
17 'GITLAB_PUBLIC_PROJECT1_URI',
18 'GITLAB_PRIVATE_PROJECT1_URI',
19 'GITLAB_UNAUTHORIZED_PRIVATE_PROJECT1_URI'
26 let oauthToken = null;
27 let GitLabIssuableService;
30 GitLabIssuableService = proxyquireNoCallThru('../lib/issuable-service', {
31 './get-gitlab-access-token-from-user': function() {
32 return Promise.resolve(oauthToken);
41 describe('as a GitLab user', () => {
43 oauthToken = fixtureLoader.GITLAB_USER_TOKEN;
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);
55 it("shouldn't fetch missing issue", () => {
56 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
58 .getIssue(fixtureLoader.GITLAB_PUBLIC_PROJECT1_URI, 999999)
60 assert.fail(new TestError("Shouldn't be able to fetch missing issue"));
63 if (err instanceof TestError) {
67 assert.strictEqual(err.status, 404);
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);
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);
89 it("shouldn't fetch issue in unauthorized private project", () => {
90 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
92 .getIssue(fixtureLoader.GITLAB_UNAUTHORIZED_PRIVATE_PROJECT1_URI, 1)
95 new TestError("Shouldn't be able to fetch issue in unauthorized private project")
99 if (err instanceof TestError) {
103 assert.strictEqual(err.status, 404);
108 describe('using public token pool', () => {
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');
125 .getIssue(fixtureLoader.GITLAB_PUBLIC_PROJECT1_URI, 2)
127 assert.fail(new TestError("Shouldn't be able to fetch confidential issue"));
130 if (err instanceof TestError) {
134 assert.strictEqual(err.status, 404);
138 it("shouldn't fetch private issue", () => {
139 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
141 .getIssue(fixtureLoader.GITLAB_PRIVATE_PROJECT1_URI, 1)
144 new TestError("Shouldn't be able to fetch issue in unauthorized private project")
148 if (err instanceof TestError) {
152 assert.strictEqual(err.status, 404);
156 it("shouldn't fetch issue in unauthorized private project", () => {
157 const glService = new GitLabIssuableService(FAKE_USER, 'issues');
159 .getIssue(fixtureLoader.GITLAB_UNAUTHORIZED_PRIVATE_PROJECT1_URI, 1)
162 new TestError("Shouldn't be able to fetch issue in unauthorized private project")
166 if (err instanceof TestError) {
170 assert.strictEqual(err.status, 404);