-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathgitlab.test.js
131 lines (111 loc) · 3.88 KB
/
gitlab.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**!
* gitlab - test/gitlab.test.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <[email protected]> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var should = require('should');
var client = require('./client');
var gitlab = require('../');
describe('gitlab.test.js', function () {
describe('setAuthentication', function () {
var req = {};
beforeEach(function () {
req = {
params: {
data: {}
}
}
});
it('should default to using a private token', function() {
var privateToken = 'private';
gitlab.prototype.setAuthentication.call({
privateToken: privateToken
}, req);
req.params.data.private_token.should.equal(privateToken);
req.params.data.should.not.have.keys('access_token');
});
it('should use access token if provided', function() {
var accessToken = 'access';
gitlab.prototype.setAuthentication.call({
accessToken: accessToken
}, req);
req.params.data.access_token.should.equal(accessToken);
req.params.data.should.not.have.keys('private_token');
});
it('should prefer already passed private token on the request object', function() {
var privateToken = 'private';
var existingPrivateToken = 'already-private';
req.params.data.private_token = existingPrivateToken;
gitlab.prototype.setAuthentication.call({
privateToken: privateToken
}, req);
req.params.data.private_token.should.equal(existingPrivateToken);
req.params.data.should.not.have.keys('access_token');
});
it('should prefer already passed access token on the request object', function() {
var accessToken = 'access';
var existingAccessToken = 'already-access';
req.params.data.access_token = existingAccessToken;
gitlab.prototype.setAuthentication.call({
accessToken: accessToken
}, req);
req.params.data.access_token.should.equal(existingAccessToken);
req.params.data.should.not.have.keys('private_token');
});
});
describe('Client.request()', function () {
it('should request success', function (done) {
client.request('get', '/projects', {}, function (err, projects) {
should.not.exists(err);
projects.length.should.above(0);
done();
});
});
it('should request with promise way success', function (done) {
client.promise.request('get', '/projects', {})
.then(function (projects) {
projects.length.should.above(0);
done();
})
.catch(done);
});
it('should request with thunk way success', function* () {
var projects = yield client.thunk.request('get', '/projects', {});
projects.length.should.above(0);
});
it('should request 404 error', function (done) {
client.request('get', '/projects/:id/milestones', {id: 99999999}, function (err, milestones) {
should.exists(err);
should.not.exists(milestones);
done();
});
});
it('should request 401 error when token wrong', function (done) {
client.request('get', '/projects/:id/milestones', {id: 223, private_token: 'wrong'}, function (err, milestones) {
should.exists(err);
err.name.should.equal('Gitlab401Error');
err.message.should.containEql('401 Unauthorized');
should.not.exists(milestones);
done();
});
});
it.skip('should request 405 error when method wrong', function (done) {
client.request('post', '/projects/:id/milestones/:milestone_id', {id: 1909028, milestone_id: 120370, title: '123'},
function (err, milestones) {
should.exists(err);
err.name.should.equal('Gitlab405Error');
err.message.should.containEql('Unknow Error 405');
should.not.exists(milestones);
done();
});
});
});
});