|
16 | 16 |
|
17 | 17 | var should = require('should');
|
18 | 18 | var client = require('./client');
|
| 19 | +var gitlab = require('../'); |
19 | 20 |
|
20 | 21 | describe('gitlab.test.js', function () {
|
| 22 | + describe('setAuthentication', function () { |
| 23 | + var req = {}; |
| 24 | + beforeEach(function () { |
| 25 | + req = { |
| 26 | + params: { |
| 27 | + data: {} |
| 28 | + } |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + it('should default to using a private token', function() { |
| 33 | + var privateToken = 'private'; |
| 34 | + gitlab.prototype.setAuthentication.call({ |
| 35 | + privateToken: privateToken |
| 36 | + }, req); |
| 37 | + |
| 38 | + req.params.data.private_token.should.equal(privateToken); |
| 39 | + req.params.data.should.not.have.keys('access_token'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should use access token if provided', function() { |
| 43 | + var accessToken = 'access'; |
| 44 | + gitlab.prototype.setAuthentication.call({ |
| 45 | + accessToken: accessToken |
| 46 | + }, req); |
| 47 | + |
| 48 | + req.params.data.access_token.should.equal(accessToken); |
| 49 | + req.params.data.should.not.have.keys('private_token'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should prefer already passed private token on the request object', function() { |
| 53 | + var privateToken = 'private'; |
| 54 | + var existingPrivateToken = 'already-private'; |
| 55 | + |
| 56 | + req.params.data.private_token = existingPrivateToken; |
| 57 | + gitlab.prototype.setAuthentication.call({ |
| 58 | + privateToken: privateToken |
| 59 | + }, req); |
| 60 | + |
| 61 | + req.params.data.private_token.should.equal(existingPrivateToken); |
| 62 | + req.params.data.should.not.have.keys('access_token'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should prefer already passed access token on the request object', function() { |
| 66 | + var accessToken = 'access'; |
| 67 | + var existingAccessToken = 'already-access'; |
| 68 | + |
| 69 | + req.params.data.access_token = existingAccessToken; |
| 70 | + gitlab.prototype.setAuthentication.call({ |
| 71 | + accessToken: accessToken |
| 72 | + }, req); |
| 73 | + |
| 74 | + req.params.data.access_token.should.equal(existingAccessToken); |
| 75 | + req.params.data.should.not.have.keys('private_token'); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
21 | 79 | describe('Client.request()', function () {
|
22 | 80 | it('should request success', function (done) {
|
23 | 81 | client.request('get', '/projects', {}, function (err, projects) {
|
|
0 commit comments