bitbucket-server-nodejs
Advanced tools
Comparing version 2.10.0 to 2.11.0
@@ -1,2 +0,1 @@ | ||
exports.Client = require('./lib/client'); |
'use strict'; | ||
module.exports = function (client) { | ||
return { | ||
get: function (projectKey, repoKey, options) { | ||
return client.getCollection('projects/' + projectKey + '/repos/' + repoKey + '/branches', options); | ||
} | ||
}; | ||
return { | ||
get: function (projectKey, repoKey, options) { | ||
return client.getCollection('projects/' + projectKey + '/repos/' + repoKey + '/branches', options); | ||
} | ||
}; | ||
}; |
'use strict'; | ||
module.exports = function (client) { | ||
var getByType = function(type, projectKey, repoSlug, options) { | ||
options = options || {}; | ||
options.type = type; | ||
var getByType = function (type, projectKey, repoSlug, options) { | ||
options = options || {}; | ||
options.type = type; | ||
return client.getCollection('projects/' + projectKey + '/repos/' + repoSlug + '/settings/hooks', options); | ||
}; | ||
return client.getCollection('projects/' + projectKey + '/repos/' + repoSlug + '/settings/hooks', options); | ||
}; | ||
return { | ||
get: function(projectKey, repoSlug, options) { | ||
return client.getCollection('projects/' + projectKey + '/repos/' + repoSlug + '/settings/hooks', options); | ||
}, | ||
return { | ||
get: function (projectKey, repoSlug, options) { | ||
return client.getCollection('projects/' + projectKey + '/repos/' + repoSlug + '/settings/hooks', options); | ||
}, | ||
getHook: function(projectKey, repoSlug, hookKey, options) { | ||
return client.get('projects/' + projectKey + '/repos/' + repoSlug + '/settings/hooks/' + hookKey , options); | ||
}, | ||
getHook: function (projectKey, repoSlug, hookKey, options) { | ||
return client.get('projects/' + projectKey + '/repos/' + repoSlug + '/settings/hooks/' + hookKey, options); | ||
}, | ||
getPreReceive: function(projectKey, repoSlug, options) { | ||
return getByType('PRE_RECEIVE', projectKey, repoSlug, options); | ||
}, | ||
getPreReceive: function (projectKey, repoSlug, options) { | ||
return getByType('PRE_RECEIVE', projectKey, repoSlug, options); | ||
}, | ||
getPostReceive: function(type, projectKey, repoSlug, options) { | ||
return getByType('POST_RECEIVE', projectKey, repoSlug, options); | ||
}, | ||
getPostReceive: function (type, projectKey, repoSlug, options) { | ||
return getByType('POST_RECEIVE', projectKey, repoSlug, options); | ||
}, | ||
enable: function(projectKey, repoSlug, hookKey, hookDetails) { | ||
var path = 'projects/' + projectKey + '/repos/' + repoSlug + '/settings/hooks/' + hookKey + '/enabled'; | ||
return client.put(path, hookDetails); | ||
} | ||
enable: function (projectKey, repoSlug, hookKey, hookDetails) { | ||
var path = 'projects/' + projectKey + '/repos/' + repoSlug + '/settings/hooks/' + hookKey + '/enabled'; | ||
return client.put(path, hookDetails); | ||
} | ||
} | ||
}; |
'use strict'; | ||
module.exports = function (client) { | ||
return { | ||
get: function(options) { | ||
return client.getCollection('projects', options); | ||
} | ||
return { | ||
get: function (options) { | ||
return client.getCollection('projects', options); | ||
} | ||
} | ||
}; |
@@ -7,77 +7,77 @@ 'use strict'; | ||
function filterByAuthor(author) { | ||
return function(pr) { | ||
return !author || author === pr.author.user.name; | ||
}; | ||
function filterByAuthor (author) { | ||
return function (pr) { | ||
return !author || author === pr.author.user.name; | ||
}; | ||
} | ||
function filterByFork(fork) { | ||
return function(pr) { | ||
var from = pr.fromRef.repository.project.key + '/' + pr.fromRef.repository.slug; | ||
var to = pr.toRef.repository.project.key + '/' + pr.toRef.repository.slug; | ||
return (fork) ? from !== to : from === to; | ||
} | ||
function filterByFork (fork) { | ||
return function (pr) { | ||
var from = pr.fromRef.repository.project.key + '/' + pr.fromRef.repository.slug; | ||
var to = pr.toRef.repository.project.key + '/' + pr.toRef.repository.slug; | ||
return (fork) ? from !== to : from === to; | ||
} | ||
} | ||
module.exports = function (client) { | ||
var repos = require('./repos')(client); | ||
return { | ||
get: function(projectKey, repo, options) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
var repos = require('./repos')(client); | ||
return { | ||
get: function (projectKey, repo, options) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
var clientOptions = { args: { 'state': options.state || 'OPEN' } }; | ||
var path = 'projects/' + projectKey + '/repos/' + repo + '/pull-requests'; | ||
var clientOptions = { args: { 'state': options.state || 'OPEN' } }; | ||
var path = 'projects/' + projectKey + '/repos/' + repo + '/pull-requests'; | ||
return client.getCollection(path, clientOptions).then(function(response) { | ||
// filter by author. | ||
if (options.author) { | ||
response.values = response.values.filter(filterByAuthor(options.author)); | ||
} | ||
if (!utils.isUndefined(options.fork)) { | ||
response.values = response.values.filter(filterByFork(options.fork)); | ||
} | ||
return response; | ||
}); | ||
}, | ||
return client.getCollection(path, clientOptions).then(function (response) { | ||
// filter by author. | ||
if (options.author) { | ||
response.values = response.values.filter(filterByAuthor(options.author)); | ||
} | ||
if (!utils.isUndefined(options.fork)) { | ||
response.values = response.values.filter(filterByFork(options.fork)); | ||
} | ||
return response; | ||
}); | ||
}, | ||
getCombined: function(projectKey, repo, options) { | ||
getCombined: function (projectKey, repo, options) { | ||
if (projectKey && repo) { | ||
return this.get(projectKey, repo, options); | ||
} | ||
else { | ||
if (projectKey && repo) { | ||
return this.get(projectKey, repo, options); | ||
} | ||
else { | ||
var prsCombined = [ ]; | ||
var API = this; | ||
var prsCombined = []; | ||
var API = this; | ||
// Find all repos matching projectKey/repo & return all PRs for each. | ||
return new Promise(function(resolve, reject) { | ||
// Find all repos. | ||
repos.getCombined(projectKey).then(function(reposResponse) { | ||
// Async loop. | ||
async.forEachOf(reposResponse.values, function(repo, index, callback) { | ||
API.get(repo.project.key, repo.slug, options).then(function(prResponse) { | ||
prsCombined = utils(prsCombined).concat(prResponse.values).value(); | ||
callback(); | ||
}).catch(function(err) { | ||
callback(err); | ||
}); | ||
// Find all repos matching projectKey/repo & return all PRs for each. | ||
return new Promise(function (resolve, reject) { | ||
// Find all repos. | ||
repos.getCombined(projectKey).then(function (reposResponse) { | ||
// Async loop. | ||
async.forEachOf(reposResponse.values, function (repo, index, callback) { | ||
API.get(repo.project.key, repo.slug, options).then(function (prResponse) { | ||
prsCombined = utils(prsCombined).concat(prResponse.values).value(); | ||
callback(); | ||
}).catch(function (err) { | ||
callback(err); | ||
}); | ||
}, function(err) { // all PRs resolved. | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve({values:prsCombined}); | ||
} | ||
}); | ||
}).catch(function(err) { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
} | ||
}, function (err) { // all PRs resolved. | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve({ values: prsCombined }); | ||
} | ||
}); | ||
}).catch(function (err) { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
}; |
@@ -9,68 +9,92 @@ 'use strict'; | ||
module.exports = function (client) { | ||
var projects = require('./projects')(client); | ||
var projects = require('./projects')(client); | ||
var allRepos = []; | ||
return { | ||
get: function(projectKey, options) { | ||
return client.getCollection('projects/' + projectKey + '/repos', options); | ||
}, | ||
return { | ||
get: function (projectKey, options) { | ||
return client.getCollection('projects/' + projectKey + '/repos', options); | ||
}, | ||
getRepo: function(projectKey, repo, options) { | ||
return client.get('projects/' + projectKey + '/repos/' + repo, options); | ||
}, | ||
getAll: function (options) { | ||
var self = this; | ||
options = options || {}; | ||
browse: function(projectKey, repo, options) { | ||
options = options || {}; | ||
return client.getCollection('repos', options) | ||
.then(function (repos) { | ||
allRepos = _.concat(allRepos, repos.values); | ||
var uriPath = 'projects/' + projectKey + '/repos/' + repo + '/browse'; | ||
if (options.path) { | ||
// add first slash if it's missing only | ||
if (_.first(options.path) !== '/') { | ||
options.path = '/' + options.path; | ||
} | ||
if (!repos.isLastPage) { | ||
// Keep previous call's args | ||
options.args = options.args || {}; | ||
uriPath += options.path; | ||
} | ||
// Append 'start' arg | ||
options.args.start = repos.nextPageStart; | ||
return client.getCollection(uriPath, options); | ||
}, | ||
return self.getAll(options); | ||
} | ||
}) | ||
.then(function () { | ||
return allRepos; | ||
}); | ||
}, | ||
getCombined: function(projectKey, options) { | ||
if (projectKey) { | ||
return this.get(projectKey, options); | ||
} | ||
else { | ||
// For each project, get all repos. | ||
var reposCombined = []; | ||
getRepo: function (projectKey, repo, options) { | ||
return client.get('projects/' + projectKey + '/repos/' + repo, options); | ||
}, | ||
var API = this; | ||
browse: function (projectKey, repo, options) { | ||
options = options || {}; | ||
return new Promise(function(resolve, reject) { | ||
// Get all projects. | ||
projects.get().then(function(projectsResponse) { | ||
// Async, for each project. | ||
async.forEachOf(projectsResponse.values, function(project, index, callback) { | ||
// Get project repos. | ||
API.get(project.key).then(function(repoResponse) { | ||
// Merge to result. | ||
reposCombined = utils(reposCombined).concat(repoResponse.values).value(); | ||
callback(); | ||
}).catch(function(err) { | ||
callback(err); | ||
}); | ||
}, function(err) { // all repos resolved. | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve({values:reposCombined}); | ||
} | ||
}); | ||
}).catch(function(err) { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
var uriPath = 'projects/' + projectKey + '/repos/' + repo + '/browse'; | ||
if (options.path) { | ||
// add first slash, if missing | ||
if (_.first(options.path) !== '/') { | ||
options.path = '/' + options.path; | ||
} | ||
}; | ||
uriPath += options.path; | ||
} | ||
return client.getCollection(uriPath, options); | ||
}, | ||
getCombined: function (projectKey, options) { | ||
if (projectKey) { | ||
return this.get(projectKey, options); | ||
} | ||
else { | ||
// For each project, get all repos. | ||
var reposCombined = []; | ||
var API = this; | ||
return new Promise(function (resolve, reject) { | ||
// Get all projects. | ||
projects.get().then(function (projectsResponse) { | ||
// Async, for each project. | ||
async.forEachOf(projectsResponse.values, function (project, index, callback) { | ||
// Get project repos. | ||
API.get(project.key).then(function (repoResponse) { | ||
// Merge to result. | ||
reposCombined = utils(reposCombined).concat(repoResponse.values).value(); | ||
callback(); | ||
}).catch(function (err) { | ||
callback(err); | ||
}); | ||
}, function (err) { // all repos resolved. | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve({ values: reposCombined }); | ||
} | ||
}); | ||
}).catch(function (err) { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
} | ||
}; | ||
}; | ||
'use strict'; | ||
module.exports = function (client) { | ||
return { | ||
get: function (userSlug, options) { | ||
return client.get('users/' + userSlug + '/settings', options); | ||
} | ||
}; | ||
return { | ||
get: function (userSlug, options) { | ||
return client.get('users/' + userSlug + '/settings', options); | ||
} | ||
}; | ||
}; |
'use strict'; | ||
module.exports = function (client) { | ||
return { | ||
get: function (options) { | ||
return client.getCollection('users', options); | ||
}, | ||
return { | ||
get: function (options) { | ||
return client.getCollection('users', options); | ||
}, | ||
getUser: function (userSlug, options) { | ||
return client.get('users/' + userSlug, options); | ||
} | ||
}; | ||
getUser: function (userSlug, options) { | ||
return client.get('users/' + userSlug, options); | ||
} | ||
}; | ||
}; | ||
@@ -7,103 +7,103 @@ 'use strict'; | ||
function validateAuth(auth) { | ||
return !!(auth.username && auth.password); | ||
function validateAuth (auth) { | ||
return !!(auth.username && auth.password); | ||
} | ||
function validateOAuth(oauth) { | ||
var attributes = ['consumer_key', 'consumer_secret', 'signature_method', 'token', 'token_secret']; | ||
function validateOAuth (oauth) { | ||
var attributes = [ 'consumer_key', 'consumer_secret', 'signature_method', 'token', 'token_secret' ]; | ||
for (var i = 0; i < attributes.length; ++i) { | ||
var attribute = attributes[i]; | ||
for (var i = 0; i < attributes.length; ++i) { | ||
var attribute = attributes[ i ]; | ||
if (_.isEmpty(oauth[attribute])) { | ||
return attribute; | ||
} | ||
if (_.isEmpty(oauth[ attribute ])) { | ||
return attribute; | ||
} | ||
} | ||
} | ||
var Client = function (baseUrl, auth) { | ||
auth = auth || {}; | ||
auth = auth || {}; | ||
// defaults to 'public' auth if none provided | ||
auth.type = auth.type || 'public'; | ||
// defaults to 'public' auth if none provided | ||
auth.type = auth.type || 'public'; | ||
// required baseUrl | ||
if (!baseUrl) { | ||
throw new Error('Base URL is missing'); | ||
} else { | ||
// add ending slash if not present | ||
if (_.last(baseUrl) !== '/') { | ||
baseUrl += '/'; | ||
} | ||
// required baseUrl | ||
if (!baseUrl) { | ||
throw new Error('Base URL is missing'); | ||
} else { | ||
// add ending slash if not present | ||
if (_.last(baseUrl) !== '/') { | ||
baseUrl += '/'; | ||
} | ||
} | ||
// validate basic auth | ||
if (auth.type === 'basic') { | ||
var isValidAuthAttribute = validateAuth(auth); | ||
if (isValidAuthAttribute) { | ||
this.auth = auth; | ||
} else { | ||
throw new Error('Auth\'s username and/or password is missing'); | ||
} | ||
// validate basic auth | ||
if (auth.type === 'basic') { | ||
var isValidAuthAttribute = validateAuth(auth); | ||
if (isValidAuthAttribute) { | ||
this.auth = auth; | ||
} else { | ||
throw new Error('Auth\'s username and/or password is missing'); | ||
} | ||
} | ||
// validate oauth | ||
if (auth.type === 'oauth') { | ||
var missingOAuthAttribute = validateOAuth(auth); | ||
if (missingOAuthAttribute) { | ||
throw new Error('OAuth\'s ' + missingOAuthAttribute + ' is missing'); | ||
} else { | ||
this.oauth = auth; | ||
} | ||
// validate oauth | ||
if (auth.type === 'oauth') { | ||
var missingOAuthAttribute = validateOAuth(auth); | ||
if (missingOAuthAttribute) { | ||
throw new Error('OAuth\'s ' + missingOAuthAttribute + ' is missing'); | ||
} else { | ||
this.oauth = auth; | ||
} | ||
} | ||
this.baseUrl = baseUrl; | ||
this.baseUrl = baseUrl; | ||
// Init API. | ||
this.projects = require('./api/projects')(this); | ||
this.repos = require('./api/repos')(this); | ||
this.branches = require('./api/branches')(this); | ||
this.prs = require('./api/prs')(this); | ||
this.users= require('./api/users')(this); | ||
this.hooks = require('./api/hooks')(this); | ||
this.settings = require('./api/settings')(this); | ||
// Init API. | ||
this.projects = require('./api/projects')(this); | ||
this.repos = require('./api/repos')(this); | ||
this.branches = require('./api/branches')(this); | ||
this.prs = require('./api/prs')(this); | ||
this.users = require('./api/users')(this); | ||
this.hooks = require('./api/hooks')(this); | ||
this.settings = require('./api/settings')(this); | ||
}; | ||
Client.prototype.getCollection = function (path, options) { | ||
options = options || {}; | ||
options.args = _.defaults(options.args || {}, {'limit': 1000}); | ||
return this.get(path, options); | ||
options = options || {}; | ||
options.args = _.defaults(options.args || {}, { 'limit': 1000 }); | ||
return this.get(path, options); | ||
}; | ||
Client.prototype.get = function (path, options) { | ||
options = options || {}; | ||
options.args = options.args || {}; | ||
var query = qs.stringify(options.args); | ||
if (query) { | ||
query = '?' + query; | ||
} | ||
options = options || {}; | ||
options.args = options.args || {}; | ||
var query = qs.stringify(options.args); | ||
if (query) { | ||
query = '?' + query; | ||
} | ||
var params = { | ||
uri: this.baseUrl + path + query, | ||
auth: this.auth, | ||
oauth: this.oauth, | ||
json: true | ||
}; | ||
var params = { | ||
uri: this.baseUrl + path + query, | ||
auth: this.auth, | ||
oauth: this.oauth, | ||
json: true | ||
}; | ||
return request.get(params); | ||
return request.get(params); | ||
}; | ||
Client.prototype.put = function (path, data) { | ||
var params = { | ||
uri: this.baseUrl + path, | ||
headers: {'Content-Type': 'application/json'}, | ||
auth: this.auth, | ||
oauth: this.oauth, | ||
body: data, | ||
json: true | ||
}; | ||
var params = { | ||
uri: this.baseUrl + path, | ||
headers: { 'Content-Type': 'application/json' }, | ||
auth: this.auth, | ||
oauth: this.oauth, | ||
body: data, | ||
json: true | ||
}; | ||
return request.post(params); | ||
return request.post(params); | ||
}; | ||
module.exports = Client; |
@@ -80,3 +80,3 @@ { | ||
}, | ||
"version": "2.10.0" | ||
"version": "2.11.0" | ||
} |
@@ -67,2 +67,8 @@ | ||
Get all repos, using pagination. | ||
``` | ||
client.repos.getAll(); // Promise | ||
``` | ||
Get all repos for all projects. | ||
@@ -69,0 +75,0 @@ |
@@ -8,29 +8,29 @@ var assert = require('assert'); | ||
describe('Branches', function () { | ||
var requestGet, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
var requestGet, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
afterEach(function () { | ||
request.get.restore(); | ||
}); | ||
afterEach(function () { | ||
request.get.restore(); | ||
}); | ||
it('should get list of branches by project for a repo', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/branches.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
it('should get list of branches by project for a repo', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/branches.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
// Test repos.get API. | ||
bitbucketClient.branches.get('PRJ', 'my-repo') | ||
.then(function (branches) { | ||
assert.equal(branches.size, 5); | ||
assert.deepEqual(branches.values[0], expected.values[0]); | ||
assert.equal(requestGet.getCall(0).args[0].uri, 'http://localhost/projects/PRJ/repos/my-repo/branches?limit=1000'); | ||
// Test repos.get API. | ||
bitbucketClient.branches.get('PRJ', 'my-repo') | ||
.then(function (branches) { | ||
assert.equal(branches.size, 5); | ||
assert.deepEqual(branches.values[ 0 ], expected.values[ 0 ]); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, 'http://localhost/projects/PRJ/repos/my-repo/branches?limit=1000'); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -9,240 +9,240 @@ var assert = require('chai').assert; | ||
describe('Client', function () { | ||
var baseUrl = 'http://localhost/'; | ||
var auth = require('./mocks/auth'); | ||
var oauth = require('./mocks/oauth'); | ||
var repos = require('./mocks/repos'); | ||
var baseUrl = 'http://localhost/'; | ||
var auth = require('./mocks/auth'); | ||
var oauth = require('./mocks/oauth'); | ||
var repos = require('./mocks/repos'); | ||
it('should complain about missing baseUrl parameter', function (done) { | ||
assert.throws(function () { | ||
new BitbucketClient(null, oauth); | ||
}, 'Base URL is missing'); | ||
it('should complain about missing baseUrl parameter', function (done) { | ||
assert.throws(function () { | ||
new BitbucketClient(null, oauth); | ||
}, 'Base URL is missing'); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
it('should add missing slash at end only if it\'s missing', function (done) { | ||
var client = new BitbucketClient('http://localhost', auth); | ||
assert.equal(client.baseUrl, 'http://localhost/'); | ||
it('should add missing slash at end only if it\'s missing', function (done) { | ||
var client = new BitbucketClient('http://localhost', auth); | ||
assert.equal(client.baseUrl, 'http://localhost/'); | ||
client = new BitbucketClient('http://localhost/', auth); | ||
assert.equal(client.baseUrl, 'http://localhost/'); | ||
client = new BitbucketClient('http://localhost/', auth); | ||
assert.equal(client.baseUrl, 'http://localhost/'); | ||
done(); | ||
done(); | ||
}); | ||
it('should ignore all other auth fields if auth.type === public', function (done) { | ||
var client = new BitbucketClient('http://localhost', { | ||
type: 'public', | ||
username: 'username', | ||
password: 'password' | ||
}); | ||
it('should ignore all other auth fields if auth.type === public', function (done) { | ||
var client = new BitbucketClient('http://localhost', { | ||
type: 'public', | ||
username: 'username', | ||
password: 'password' | ||
}); | ||
assert.equal(client.auth, undefined); | ||
assert.equal(client.oauth, undefined); | ||
assert.equal(client.auth, undefined); | ||
assert.equal(client.oauth, undefined); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
it('should complain about missing username/password attributes if auth.type === basic', function (done) { | ||
var auth = { | ||
type: 'basic' | ||
}; | ||
it('should complain about missing username/password attributes if auth.type === basic', function (done) { | ||
var auth = { | ||
type: 'basic' | ||
}; | ||
assert.throws(function () { | ||
new BitbucketClient(baseUrl, auth); | ||
}, 'Auth\'s username and/or password is missing'); | ||
assert.throws(function () { | ||
new BitbucketClient(baseUrl, auth); | ||
}, 'Auth\'s username and/or password is missing'); | ||
done(); | ||
}); | ||
done(); | ||
it('should default to auth.type=public if none provided, this no auth or oauth object', function (done) { | ||
var client = new BitbucketClient(baseUrl, { | ||
username: 'username', | ||
password: 'password' | ||
}); | ||
it('should default to auth.type=public if none provided, this no auth or oauth object', function (done) { | ||
var client = new BitbucketClient(baseUrl, { | ||
username: 'username', | ||
password: 'password' | ||
}); | ||
assert.equal(client.auth, undefined); | ||
assert.equal(client.oauth, undefined); | ||
assert.equal(client.auth, undefined); | ||
assert.equal(client.oauth, undefined); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
it('should complain about missing username/password if auth.type === basic', function (done) { | ||
assert.throws(function () { | ||
new BitbucketClient(baseUrl, { | ||
type: 'basic' | ||
}); | ||
}, 'Auth\'s username and/or password is missing'); | ||
it('should complain about missing username/password if auth.type === basic', function (done) { | ||
assert.throws(function () { | ||
new BitbucketClient(baseUrl, { | ||
type: 'basic' | ||
}); | ||
}, 'Auth\'s username and/or password is missing'); | ||
assert.throws(function () { | ||
new BitbucketClient(baseUrl, { | ||
type: 'basic', | ||
username: 'username' | ||
}); | ||
}, 'Auth\'s username and/or password is missing'); | ||
assert.throws(function () { | ||
new BitbucketClient(baseUrl, { | ||
type: 'basic', | ||
username: 'username' | ||
}); | ||
}, 'Auth\'s username and/or password is missing'); | ||
assert.throws(function () { | ||
new BitbucketClient(baseUrl, { | ||
type: 'basic', | ||
password: 'password' | ||
}); | ||
}, 'Auth\'s username and/or password is missing'); | ||
done(); | ||
}); | ||
describe('should complain about missing oauth attributes when auth.type === oauth', function () { | ||
var attributes = [ 'consumer_key', 'consumer_secret', 'signature_method', 'token', 'token_secret' ]; | ||
_.each(attributes, function (attribute) { | ||
it('missing oauth attribute ' + attribute, function (done) { | ||
assert.throws(function () { | ||
new BitbucketClient(baseUrl, { | ||
type: 'basic', | ||
password: 'password' | ||
}); | ||
}, 'Auth\'s username and/or password is missing'); | ||
new BitbucketClient(baseUrl, _.omit(oauth, attribute)) | ||
}, 'OAuth\'s ' + attribute + ' is missing'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('should complain about missing oauth attributes when auth.type === oauth', function () { | ||
var attributes = ['consumer_key', 'consumer_secret', 'signature_method', 'token', 'token_secret']; | ||
it('should create a bitbucket client with no auth or oauth', function (done) { | ||
var client = new BitbucketClient(baseUrl); | ||
assert.typeOf(client, 'object'); | ||
_.each(attributes, function (attribute) { | ||
it('missing oauth attribute ' + attribute, function (done) { | ||
assert.throws(function () { | ||
new BitbucketClient(baseUrl, _.omit(oauth, attribute)) | ||
}, 'OAuth\'s ' + attribute + ' is missing'); | ||
assert.equal(client.baseUrl, baseUrl); | ||
assert.equal(client.auth, undefined); | ||
assert.equal(client.oauth, undefined); | ||
done(); | ||
}); | ||
assert.isNotNull(client.projects); | ||
assert.isNotNull(client.branches); | ||
assert.isNotNull(client.repos); | ||
assert.isNotNull(client.prs); | ||
assert.isNotNull(client.hooks); | ||
assert.isNotNull(client.settings); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
it('should create a bitbucket client with no auth or oauth', function (done) { | ||
var client = new BitbucketClient(baseUrl); | ||
assert.typeOf(client, 'object'); | ||
it('should create a bitbucket client with auth.type === basic', function (done) { | ||
var client = new BitbucketClient(baseUrl, auth); | ||
assert.typeOf(client, 'object'); | ||
assert.equal(client.baseUrl, baseUrl); | ||
assert.equal(client.auth, undefined); | ||
assert.equal(client.oauth, undefined); | ||
assert.equal(client.baseUrl, baseUrl); | ||
assert.equal(client.auth, auth); | ||
assert.isNotNull(client.projects); | ||
assert.isNotNull(client.branches); | ||
assert.isNotNull(client.repos); | ||
assert.isNotNull(client.prs); | ||
assert.isNotNull(client.hooks); | ||
assert.isNotNull(client.settings); | ||
assert.isNotNull(client.projects); | ||
assert.isNotNull(client.branches); | ||
assert.isNotNull(client.repos); | ||
assert.isNotNull(client.prs); | ||
assert.isNotNull(client.hooks); | ||
assert.isNotNull(client.users); | ||
assert.isNotNull(client.settings); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
it('should create a bitbucket client with auth.type === basic', function (done) { | ||
var client = new BitbucketClient(baseUrl, auth); | ||
assert.typeOf(client, 'object'); | ||
it('should create a bitbucket client with auth.type === oauth', function (done) { | ||
var client = new BitbucketClient(baseUrl, oauth); | ||
assert.typeOf(client, 'object'); | ||
assert.equal(client.baseUrl, baseUrl); | ||
assert.equal(client.auth, auth); | ||
assert.equal(client.baseUrl, baseUrl); | ||
assert.equal(client.oauth, oauth); | ||
assert.isNotNull(client.projects); | ||
assert.isNotNull(client.branches); | ||
assert.isNotNull(client.repos); | ||
assert.isNotNull(client.prs); | ||
assert.isNotNull(client.hooks); | ||
assert.isNotNull(client.users); | ||
assert.isNotNull(client.settings); | ||
assert.isNotNull(client.projects); | ||
assert.isNotNull(client.branches); | ||
assert.isNotNull(client.repos); | ||
assert.isNotNull(client.prs); | ||
assert.isNotNull(client.hooks); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
it('should create a bitbucket client with auth.type === oauth', function (done) { | ||
var client = new BitbucketClient(baseUrl, oauth); | ||
assert.typeOf(client, 'object'); | ||
describe('should set request params properly with a GET request', function () { | ||
var requestGet; | ||
assert.equal(client.baseUrl, baseUrl); | ||
assert.equal(client.oauth, oauth); | ||
beforeEach(function () { | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
assert.isNotNull(client.projects); | ||
assert.isNotNull(client.branches); | ||
assert.isNotNull(client.repos); | ||
assert.isNotNull(client.prs); | ||
assert.isNotNull(client.hooks); | ||
done(); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
describe('should set request params properly with a GET request', function () { | ||
var requestGet; | ||
it('should set uri and auth params properly', function (done) { | ||
var client = new BitbucketClient(baseUrl, auth); | ||
requestGet.returns(Promise.resolve(repos)); | ||
beforeEach(function () { | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
client.get('repos') | ||
.then(function () { | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, | ||
'http://localhost/repos'); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].auth, | ||
auth); | ||
it('should set uri and auth params properly', function (done) { | ||
var client = new BitbucketClient(baseUrl, auth); | ||
requestGet.returns(Promise.resolve(repos)); | ||
client.get('repos') | ||
.then(function () { | ||
assert.equal(requestGet.getCall(0).args[0].uri, | ||
'http://localhost/repos'); | ||
assert.equal(requestGet.getCall(0).args[0].auth, | ||
auth); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should set uri and oauth params properly', function (done) { | ||
var client = new BitbucketClient(baseUrl, oauth); | ||
requestGet.returns(Promise.resolve(repos)); | ||
it('should set uri and oauth params properly', function (done) { | ||
var client = new BitbucketClient(baseUrl, oauth); | ||
requestGet.returns(Promise.resolve(repos)); | ||
client.get('repos') | ||
.then(function () { | ||
assert.equal(requestGet.getCall(0).args[0].uri, | ||
'http://localhost/repos'); | ||
client.get('repos') | ||
.then(function () { | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, | ||
'http://localhost/repos'); | ||
assert.equal(requestGet.getCall(0).args[0].oauth, | ||
oauth); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].oauth, | ||
oauth); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('should set request params properly with a POST request', function () { | ||
var requestPost; | ||
describe('should set request params properly with a POST request', function () { | ||
var requestPost; | ||
beforeEach(function () { | ||
requestPost = sinon.stub(request, 'post'); | ||
requestPost.returns(Promise.resolve(repos)); | ||
}); | ||
beforeEach(function () { | ||
requestPost = sinon.stub(request, 'post'); | ||
requestPost.returns(Promise.resolve(repos)); | ||
}); | ||
afterEach(function () { | ||
requestPost.restore(); | ||
}); | ||
afterEach(function () { | ||
requestPost.restore(); | ||
}); | ||
it('should set uri and auth params properly', function (done) { | ||
var client = new BitbucketClient(baseUrl, auth); | ||
it('should set uri and auth params properly', function (done) { | ||
var client = new BitbucketClient(baseUrl, auth); | ||
client.put('repos') | ||
.then(function () { | ||
assert.equal(requestPost.getCall(0).args[0].uri, | ||
'http://localhost/repos'); | ||
client.put('repos') | ||
.then(function () { | ||
assert.equal(requestPost.getCall(0).args[ 0 ].uri, | ||
'http://localhost/repos'); | ||
assert.equal(requestPost.getCall(0).args[0].auth, | ||
auth); | ||
assert.equal(requestPost.getCall(0).args[ 0 ].auth, | ||
auth); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should set uri and oauth params properly', function (done) { | ||
var bitbucketClient2 = new BitbucketClient(baseUrl, oauth); | ||
it('should set uri and oauth params properly', function (done) { | ||
var bitbucketClient2 = new BitbucketClient(baseUrl, oauth); | ||
bitbucketClient2.put('repos') | ||
.then(function () { | ||
assert.equal(requestPost.getCall(0).args[0].uri, | ||
'http://localhost/repos'); | ||
bitbucketClient2.put('repos') | ||
.then(function () { | ||
assert.equal(requestPost.getCall(0).args[ 0 ].uri, | ||
'http://localhost/repos'); | ||
assert.equal(requestPost.getCall(0).args[0].oauth, | ||
oauth); | ||
assert.equal(requestPost.getCall(0).args[ 0 ].oauth, | ||
oauth); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -8,81 +8,81 @@ var assert = require('assert'); | ||
describe('Hooks', function () { | ||
var requestGet, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
var requestGet, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
it('should get list of hooks', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hooks.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
it('should get list of hooks', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hooks.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
// Test hooks.get API. | ||
bitbucketClient.hooks.get('PRJ', 'my-repo') | ||
.then(function (hooks) { | ||
assert.equal(hooks.size, 1); | ||
assert.deepEqual(hooks.values[0], expected.values[0]); | ||
assert.equal( | ||
requestGet.getCall(0).args[0].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/settings/hooks?limit=1000' | ||
); | ||
// Test hooks.get API. | ||
bitbucketClient.hooks.get('PRJ', 'my-repo') | ||
.then(function (hooks) { | ||
assert.equal(hooks.size, 1); | ||
assert.deepEqual(hooks.values[ 0 ], expected.values[ 0 ]); | ||
assert.equal( | ||
requestGet.getCall(0).args[ 0 ].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/settings/hooks?limit=1000' | ||
); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should get a single hook', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hook-single.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
it('should get a single hook', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hook-single.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
// Test hooks.get API. | ||
var hookKey = 'com.atlassian.stash.plugin.example:example-repository-hook'; | ||
bitbucketClient.hooks.getHook('PRJ', 'my-repo', hookKey) | ||
.then(function (hook) { | ||
assert.deepEqual(hook.details, expected.details); | ||
assert.equal( | ||
requestGet.getCall(0).args[0].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/settings/hooks/' + hookKey | ||
); | ||
// Test hooks.get API. | ||
var hookKey = 'com.atlassian.stash.plugin.example:example-repository-hook'; | ||
bitbucketClient.hooks.getHook('PRJ', 'my-repo', hookKey) | ||
.then(function (hook) { | ||
assert.deepEqual(hook.details, expected.details); | ||
assert.equal( | ||
requestGet.getCall(0).args[ 0 ].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/settings/hooks/' + hookKey | ||
); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should just get the PRE_RECEIVE hooks', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hooks.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
it('should just get the PRE_RECEIVE hooks', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hooks.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
// Test hooks.get API. | ||
bitbucketClient.hooks.getPreReceive('PRJ', 'my-repo') | ||
.then(function (hooks) { | ||
assert.equal(hooks.size, 1); | ||
assert.deepEqual(hooks.values[0], expected.values[0]); | ||
// Test hooks.get API. | ||
bitbucketClient.hooks.getPreReceive('PRJ', 'my-repo') | ||
.then(function (hooks) { | ||
assert.equal(hooks.size, 1); | ||
assert.deepEqual(hooks.values[ 0 ], expected.values[ 0 ]); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should just get the POST_RECEIVE hooks', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hooks.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
it('should just get the POST_RECEIVE hooks', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hooks.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
// Test hooks.get API. | ||
bitbucketClient.hooks.getPostReceive('PRJ', 'my-repo') | ||
.then(function (hooks) { | ||
assert.equal(hooks.size, 1); | ||
assert.deepEqual(hooks.values[0], expected.values[0]); | ||
// Test hooks.get API. | ||
bitbucketClient.hooks.getPostReceive('PRJ', 'my-repo') | ||
.then(function (hooks) { | ||
assert.equal(hooks.size, 1); | ||
assert.deepEqual(hooks.values[ 0 ], expected.values[ 0 ]); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -8,36 +8,36 @@ var assert = require('assert'); | ||
describe('Hooks', function () { | ||
var requestPost, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
var requestPost, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost', oauth); | ||
requestPost = sinon.stub(request, 'post'); | ||
}); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost', oauth); | ||
requestPost = sinon.stub(request, 'post'); | ||
}); | ||
afterEach(function () { | ||
requestPost.restore(); | ||
}); | ||
afterEach(function () { | ||
requestPost.restore(); | ||
}); | ||
it('should enable hooks', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hooks.json'); | ||
requestPost.returns(Promise.resolve(expected)); | ||
it('should enable hooks', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/hooks.json'); | ||
requestPost.returns(Promise.resolve(expected)); | ||
var hookDetails = { | ||
hook: 'hook', | ||
details: 'details' | ||
}; | ||
var hookDetails = { | ||
hook: 'hook', | ||
details: 'details' | ||
}; | ||
// Test hooks.get API. | ||
bitbucketClient.hooks.enable('projectKey', 'repoSlug', 'hookKey', hookDetails) | ||
.then(function (hooks) { | ||
assert.equal( | ||
requestPost.getCall(0).args[0].uri, | ||
'http://localhost/projects/projectKey/repos/repoSlug/settings/hooks/hookKey/enabled' | ||
); | ||
assert.equal(requestPost.getCall(0).args[0].body, hookDetails); | ||
// Test hooks.get API. | ||
bitbucketClient.hooks.enable('projectKey', 'repoSlug', 'hookKey', hookDetails) | ||
.then(function (hooks) { | ||
assert.equal( | ||
requestPost.getCall(0).args[ 0 ].uri, | ||
'http://localhost/projects/projectKey/repos/repoSlug/settings/hooks/hookKey/enabled' | ||
); | ||
assert.equal(requestPost.getCall(0).args[ 0 ].body, hookDetails); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -1,5 +0,5 @@ | ||
require('./client.spec'); | ||
require('./projects/get.spec'); | ||
require('./repos/get.spec'); | ||
require('./repos/getAll.spec'); | ||
require('./prs/get.spec'); | ||
@@ -6,0 +6,0 @@ require('./hooks/get.spec'); |
@@ -8,31 +8,31 @@ var assert = require('assert'); | ||
describe('Projects', function () { | ||
var requestGet, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
var requestGet, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
it('should get list of projects', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/projects.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
it('should get list of projects', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/projects.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
// Test projects.get API. | ||
bitbucketClient.projects.get() | ||
.then(function (projects) { | ||
assert.equal(projects.size, 1); | ||
assert.deepEqual(projects.values[0], expected.values[0]); | ||
assert.equal(requestGet.getCall(0).args[0].uri, 'http://localhost/projects?limit=1000'); | ||
assert.equal(requestGet.getCall(0).args[0].oauth, oauth); | ||
// Test projects.get API. | ||
bitbucketClient.projects.get() | ||
.then(function (projects) { | ||
assert.equal(projects.size, 1); | ||
assert.deepEqual(projects.values[ 0 ], expected.values[ 0 ]); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, 'http://localhost/projects?limit=1000'); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].oauth, oauth); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -8,151 +8,151 @@ var assert = require('assert'); | ||
describe('Pull Requests', function () { | ||
var requestGet, bitbucketClient; | ||
var auth = require('../mocks/auth'); | ||
var oauth = require('../mocks/oauth'); | ||
var requestGet, bitbucketClient; | ||
var auth = require('../mocks/auth'); | ||
var oauth = require('../mocks/oauth'); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
it('should get list of pull requests for a project/repo', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/prs.json'); | ||
it('should get list of pull requests for a project/repo', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/prs.json'); | ||
requestGet.onCall(0).returns(Promise.resolve(expected)); | ||
requestGet.onCall(1).returns(Promise.resolve(expected)); | ||
requestGet.onCall(0).returns(Promise.resolve(expected)); | ||
requestGet.onCall(1).returns(Promise.resolve(expected)); | ||
// Test prs.get API. | ||
bitbucketClient.prs.get('PRJ', 'my-repo') | ||
.then(function (prs) { | ||
assert.equal(prs.size, 1); | ||
assert.deepEqual(prs.values[0], expected.values[0]); | ||
// Test prs.get API. | ||
bitbucketClient.prs.get('PRJ', 'my-repo') | ||
.then(function (prs) { | ||
assert.equal(prs.size, 1); | ||
assert.deepEqual(prs.values[ 0 ], expected.values[ 0 ]); | ||
assert.equal( | ||
requestGet.getCall(0).args[0].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/pull-requests?limit=1000&state=OPEN' | ||
); | ||
assert.equal( | ||
requestGet.getCall(0).args[ 0 ].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/pull-requests?limit=1000&state=OPEN' | ||
); | ||
assert.equal( | ||
requestGet.getCall(0).args[0].oauth, | ||
oauth | ||
); | ||
assert.equal( | ||
requestGet.getCall(0).args[ 0 ].oauth, | ||
oauth | ||
); | ||
// Test getCombined proxies to normal get for project/repo. | ||
return bitbucketClient.prs.getCombined('PRJ', 'my-repo') | ||
}) | ||
.then(function (prs) { | ||
assert.equal(prs.size, 1); | ||
assert.deepEqual(prs.values[0], expected.values[0]); | ||
assert.equal( | ||
requestGet.getCall(1).args[0].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/pull-requests?limit=1000&state=OPEN' | ||
); | ||
done(); | ||
}); | ||
}); | ||
// Test getCombined proxies to normal get for project/repo. | ||
return bitbucketClient.prs.getCombined('PRJ', 'my-repo') | ||
}) | ||
.then(function (prs) { | ||
assert.equal(prs.size, 1); | ||
assert.deepEqual(prs.values[ 0 ], expected.values[ 0 ]); | ||
assert.equal( | ||
requestGet.getCall(1).args[ 0 ].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/pull-requests?limit=1000&state=OPEN' | ||
); | ||
done(); | ||
}); | ||
}); | ||
it('should get a combined list of pull requests for all repos', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
var expectedRepos = require('../mocks/repos.json'); | ||
var expectedPrs = require('../mocks/prs.json'); | ||
it('should get a combined list of pull requests for all repos', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
var expectedRepos = require('../mocks/repos.json'); | ||
var expectedPrs = require('../mocks/prs.json'); | ||
requestGet.onCall(0).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1).returns(Promise.resolve(expectedRepos)); | ||
requestGet.onCall(2).returns(Promise.resolve(expectedPrs)); | ||
requestGet.onCall(0).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1).returns(Promise.resolve(expectedRepos)); | ||
requestGet.onCall(2).returns(Promise.resolve(expectedPrs)); | ||
// Test prs.get API. | ||
bitbucketClient.prs.getCombined() | ||
.then(function (prs) { | ||
assert.deepEqual(prs.values[0], expectedPrs.values[0]); | ||
assert.equal( | ||
requestGet.getCall(0).args[0].uri, | ||
'http://localhost/projects?limit=1000' | ||
); | ||
assert.equal( | ||
requestGet.getCall(1).args[0].uri, | ||
'http://localhost/projects/PRJ/repos?limit=1000' | ||
); | ||
assert.equal( | ||
requestGet.getCall(2).args[0].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/pull-requests?limit=1000&state=OPEN' | ||
); | ||
done(); | ||
}); | ||
}); | ||
// Test prs.get API. | ||
bitbucketClient.prs.getCombined() | ||
.then(function (prs) { | ||
assert.deepEqual(prs.values[ 0 ], expectedPrs.values[ 0 ]); | ||
assert.equal( | ||
requestGet.getCall(0).args[ 0 ].uri, | ||
'http://localhost/projects?limit=1000' | ||
); | ||
assert.equal( | ||
requestGet.getCall(1).args[ 0 ].uri, | ||
'http://localhost/projects/PRJ/repos?limit=1000' | ||
); | ||
assert.equal( | ||
requestGet.getCall(2).args[ 0 ].uri, | ||
'http://localhost/projects/PRJ/repos/my-repo/pull-requests?limit=1000&state=OPEN' | ||
); | ||
done(); | ||
}); | ||
}); | ||
it('should filter PRs by author', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
var expectedRepos = require('../mocks/repos.json'); | ||
var expectedPrs = require('../mocks/prs.json'); | ||
it('should filter PRs by author', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
var expectedRepos = require('../mocks/repos.json'); | ||
var expectedPrs = require('../mocks/prs.json'); | ||
requestGet.onCall(0).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1).returns(Promise.resolve(expectedRepos)); | ||
requestGet.onCall(2).returns(Promise.resolve(expectedPrs)); | ||
requestGet.onCall(0).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1).returns(Promise.resolve(expectedRepos)); | ||
requestGet.onCall(2).returns(Promise.resolve(expectedPrs)); | ||
// Test prs.get API. | ||
bitbucketClient.prs.getCombined(null, null, { author: 'tom' }) | ||
.then(function (prs) { | ||
assert.deepEqual(prs.values[ 0 ], expectedPrs.values[ 0 ]); | ||
}) | ||
.then(function () { | ||
requestGet.onCall(3).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(4).returns(Promise.resolve(expectedRepos)); | ||
requestGet.onCall(5).returns(Promise.resolve(expectedPrs)); | ||
// Test prs.get API. | ||
bitbucketClient.prs.getCombined(null, null, {author: 'tom'}) | ||
.then(function (prs) { | ||
assert.deepEqual(prs.values[0], expectedPrs.values[0]); | ||
}) | ||
.then(function () { | ||
requestGet.onCall(3).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(4).returns(Promise.resolve(expectedRepos)); | ||
requestGet.onCall(5).returns(Promise.resolve(expectedPrs)); | ||
return bitbucketClient.prs.getCombined(null, null, { author: 'ben' }); | ||
}) | ||
.then(function (prs) { | ||
assert.equal(prs.values.length, 0); | ||
done(); | ||
}); | ||
}); | ||
// Test prs.get API. | ||
return bitbucketClient.prs.getCombined(null, null, {author: 'ben'}); | ||
}) | ||
.then(function (prs) { | ||
assert.equal(prs.values.length, 0); | ||
done(); | ||
}); | ||
}); | ||
it('should gracefully handle errors', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
var expectedRepos = require('../mocks/repos.json'); | ||
it('should gracefully handle errors', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
var expectedRepos = require('../mocks/repos.json'); | ||
requestGet.onCall(0).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1).returns(Promise.resolve(expectedRepos)); | ||
requestGet.onCall(2).throws(); | ||
requestGet.onCall(0).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1).returns(Promise.resolve(expectedRepos)); | ||
requestGet.onCall(2).throws(); | ||
// Test prs.get API. | ||
bitbucketClient.prs.getCombined() | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
// Test prs.get API. | ||
bitbucketClient.prs.getCombined() | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
requestGet.onCall(3).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(4).throws(); | ||
requestGet.onCall(3).returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(4).throws(); | ||
return bitbucketClient.prs.getCombined(); | ||
}) | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
requestGet.onCall(5).throws(); | ||
return bitbucketClient.prs.getCombined(); | ||
}) | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
requestGet.onCall(5).throws(); | ||
return bitbucketClient.prs.getCombined(); | ||
}) | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
done(); | ||
}); | ||
}); | ||
return bitbucketClient.prs.getCombined(); | ||
}) | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -8,137 +8,137 @@ var assert = require('assert'); | ||
describe('Repos', function () { | ||
var requestGet, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
var requestGet, bitbucketClient; | ||
var oauth = require('../mocks/oauth'); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', oauth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
afterEach(function () { | ||
request.get.restore(); | ||
}); | ||
afterEach(function () { | ||
request.get.restore(); | ||
}); | ||
it('should get list of repos for a project', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/repos.json'); | ||
it('should get list of repos for a project', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/repos.json'); | ||
requestGet.onCall(0) | ||
.returns(Promise.resolve(expected)); | ||
requestGet.onCall(1) | ||
.returns(Promise.resolve(expected)); | ||
requestGet.onCall(0) | ||
.returns(Promise.resolve(expected)); | ||
requestGet.onCall(1) | ||
.returns(Promise.resolve(expected)); | ||
// Test repos.get API. | ||
bitbucketClient.repos.get('PRJ') | ||
.then(function (repos) { | ||
assert.equal(repos.size, 1); | ||
assert.deepEqual(repos.values[0], expected.values[0]); | ||
assert.equal(requestGet.getCall(0).args[0].uri, 'http://localhost/projects/PRJ/repos?limit=1000'); | ||
// Test repos.get API. | ||
bitbucketClient.repos.get('PRJ') | ||
.then(function (repos) { | ||
assert.equal(repos.size, 1); | ||
assert.deepEqual(repos.values[ 0 ], expected.values[ 0 ]); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, 'http://localhost/projects/PRJ/repos?limit=1000'); | ||
// Test that getCombined proxies to normal get, when project key given. | ||
return bitbucketClient.repos.getCombined('PRJ'); | ||
}) | ||
.then(function (repos) { | ||
assert.equal(repos.size, 1); | ||
assert.deepEqual(repos.values[0], expected.values[0]); | ||
assert.equal(requestGet.getCall(1).args[0].uri, 'http://localhost/projects/PRJ/repos?limit=1000'); | ||
// Test that getCombined proxies to normal get, when project key given. | ||
return bitbucketClient.repos.getCombined('PRJ'); | ||
}) | ||
.then(function (repos) { | ||
assert.equal(repos.size, 1); | ||
assert.deepEqual(repos.values[ 0 ], expected.values[ 0 ]); | ||
assert.equal(requestGet.getCall(1).args[ 0 ].uri, 'http://localhost/projects/PRJ/repos?limit=1000'); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should get a combined list of repos for all projects', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
var expectedRepos = require('../mocks/repos.json'); | ||
it('should get a combined list of repos for all projects', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
var expectedRepos = require('../mocks/repos.json'); | ||
requestGet.onCall(0) | ||
.returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1) | ||
.returns(Promise.resolve(expectedRepos)); | ||
requestGet.onCall(0) | ||
.returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1) | ||
.returns(Promise.resolve(expectedRepos)); | ||
// Test repos.get API. | ||
bitbucketClient.repos.getCombined() | ||
.then(function (repos) { | ||
assert.deepEqual(repos.values[0], expectedRepos.values[0]); | ||
assert.equal(requestGet.getCall(0).args[0].uri, 'http://localhost/projects?limit=1000'); | ||
assert.equal(requestGet.getCall(1).args[0].uri, 'http://localhost/projects/PRJ/repos?limit=1000'); | ||
// Test repos.get API. | ||
bitbucketClient.repos.getCombined() | ||
.then(function (repos) { | ||
assert.deepEqual(repos.values[ 0 ], expectedRepos.values[ 0 ]); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, 'http://localhost/projects?limit=1000'); | ||
assert.equal(requestGet.getCall(1).args[ 0 ].uri, 'http://localhost/projects/PRJ/repos?limit=1000'); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should fail gracefully when getting repos', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
it('should fail gracefully when getting repos', function (done) { | ||
// Mock the HTTP Client get. | ||
var expectedProjects = require('../mocks/projects.json'); | ||
requestGet.onCall(0) | ||
.returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1).throws(); | ||
requestGet.onCall(0) | ||
.returns(Promise.resolve(expectedProjects)); | ||
requestGet.onCall(1).throws(); | ||
// Test error. | ||
bitbucketClient.repos.getCombined() | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
// Test error on 2nd call. | ||
requestGet.onCall(2).throws(); | ||
requestGet.onCall(3) | ||
.returns(expectedProjects); | ||
// Test error. | ||
bitbucketClient.repos.getCombined() | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
// Test error on 2nd call. | ||
requestGet.onCall(2).throws(); | ||
requestGet.onCall(3) | ||
.returns(expectedProjects); | ||
it('should get a single project', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/repo-single.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
// Test error. | ||
bitbucketClient.repos.getCombined() | ||
.then(function () { | ||
assert.fail(); | ||
}) | ||
.catch(function (e) { | ||
assert.equal(e.message, 'Error'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
bitbucketClient.repos.getRepo('PRJ', 'my-repo') | ||
.then(function (repos) { | ||
assert.deepEqual(repos, expected); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, 'http://localhost/projects/PRJ/repos/my-repo'); | ||
it('should get a single project', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/repo-single.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
done(); | ||
}); | ||
}); | ||
bitbucketClient.repos.getRepo('PRJ', 'my-repo') | ||
.then(function (repos) { | ||
assert.deepEqual(repos, expected); | ||
assert.equal(requestGet.getCall(0).args[0].uri, 'http://localhost/projects/PRJ/repos/my-repo'); | ||
it('should browse a repo', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/repo-browse.json'); | ||
done(); | ||
}); | ||
}); | ||
requestGet.returns(Promise.resolve(expected)); | ||
it('should browse a repo', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/repo-browse.json'); | ||
bitbucketClient.repos.browse('PRJ', 'my-repo') | ||
.then(function (browse) { | ||
assert.deepEqual(browse, expected); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, 'http://localhost/projects/PRJ/repos/my-repo/browse?limit=1000'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
return bitbucketClient.repos.browse('PRJ', 'my-repo', { path: '/my-path/foo.html' }); | ||
}) | ||
.then(function (browse) { | ||
var toCall = 'http://localhost/projects/PRJ/repos/my-repo/browse/my-path/foo.html?limit=1000'; | ||
assert.equal(requestGet.getCall(1).args[ 0 ].uri, toCall); | ||
bitbucketClient.repos.browse('PRJ', 'my-repo') | ||
.then(function (browse) { | ||
assert.deepEqual(browse, expected); | ||
assert.equal(requestGet.getCall(0).args[0].uri, 'http://localhost/projects/PRJ/repos/my-repo/browse?limit=1000'); | ||
// test that it will add the first slash in path if missing | ||
return bitbucketClient.repos.browse('PRJ', 'my-repo', { path: 'my-path/foo.html' }); | ||
}) | ||
.then(function (browse) { | ||
var toCall = 'http://localhost/projects/PRJ/repos/my-repo/browse/my-path/foo.html?limit=1000'; | ||
assert.equal(requestGet.getCall(2).args[ 0 ].uri, toCall); | ||
return bitbucketClient.repos.browse('PRJ', 'my-repo', {path: '/my-path/foo.html'}); | ||
}) | ||
.then(function (browse) { | ||
var toCall = 'http://localhost/projects/PRJ/repos/my-repo/browse/my-path/foo.html?limit=1000'; | ||
assert.equal(requestGet.getCall(1).args[0].uri, toCall); | ||
// test that it will add the first slash in path if missing | ||
return bitbucketClient.repos.browse('PRJ', 'my-repo', {path: 'my-path/foo.html'}); | ||
}) | ||
.then(function (browse) { | ||
var toCall = 'http://localhost/projects/PRJ/repos/my-repo/browse/my-path/foo.html?limit=1000'; | ||
assert.equal(requestGet.getCall(2).args[0].uri, toCall); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -8,38 +8,38 @@ var assert = require('assert'); | ||
describe('Settings', function () { | ||
var requestGet, bitbucketClient; | ||
var auth = require('../mocks/auth'); | ||
var requestGet, bitbucketClient; | ||
var auth = require('../mocks/auth'); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', auth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', auth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
afterEach(function () { | ||
requestGet.restore(); | ||
}); | ||
it('should get user\'s settings', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/settings'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
it('should get user\'s settings', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/settings'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
// Test prs.get API. | ||
bitbucketClient.settings.get('username') | ||
.then(function (settings) { | ||
assert.deepEqual(settings, expected); | ||
// Test prs.get API. | ||
bitbucketClient.settings.get('username') | ||
.then(function (settings) { | ||
assert.deepEqual(settings, expected); | ||
assert.equal( | ||
requestGet.getCall(0).args[0].uri, | ||
'http://localhost/users/username/settings' | ||
); | ||
assert.equal( | ||
requestGet.getCall(0).args[ 0 ].uri, | ||
'http://localhost/users/username/settings' | ||
); | ||
assert.equal( | ||
requestGet.getCall(0).args[0].auth, | ||
auth | ||
); | ||
assert.equal( | ||
requestGet.getCall(0).args[ 0 ].auth, | ||
auth | ||
); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -8,45 +8,45 @@ var assert = require('assert'); | ||
describe('Users', function () { | ||
var requestGet, bitbucketClient; | ||
var auth = require('../mocks/auth'); | ||
var requestGet, bitbucketClient; | ||
var auth = require('../mocks/auth'); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', auth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
beforeEach(function () { | ||
bitbucketClient = new BitbucketClient('http://localhost/', auth); | ||
requestGet = sinon.stub(request, 'get'); | ||
}); | ||
afterEach(function () { | ||
request.get.restore(); | ||
}); | ||
afterEach(function () { | ||
request.get.restore(); | ||
}); | ||
it('should get list of users', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/users.json'); | ||
it('should get list of users', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/users.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
requestGet.returns(Promise.resolve(expected)); | ||
// Test users.get API. | ||
bitbucketClient.users.get() | ||
.then(function (users) { | ||
assert.equal(users.size, 1); | ||
assert.deepEqual(users.values[0], expected.values[0]); | ||
assert.equal(requestGet.getCall(0).args[0].uri, 'http://localhost/users?limit=1000'); | ||
// Test users.get API. | ||
bitbucketClient.users.get() | ||
.then(function (users) { | ||
assert.equal(users.size, 1); | ||
assert.deepEqual(users.values[ 0 ], expected.values[ 0 ]); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, 'http://localhost/users?limit=1000'); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should get a single user', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/user-single.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
it('should get a single user', function (done) { | ||
// Mock the HTTP Client get. | ||
var expected = require('../mocks/user-single.json'); | ||
requestGet.returns(Promise.resolve(expected)); | ||
bitbucketClient.users.getUser('user-slug') | ||
.then(function (user) { | ||
assert.deepEqual(user, expected); | ||
assert.equal(requestGet.getCall(0).args[0].uri, 'http://localhost/users/user-slug'); | ||
bitbucketClient.users.getUser('user-slug') | ||
.then(function (user) { | ||
assert.deepEqual(user, expected); | ||
assert.equal(requestGet.getCall(0).args[ 0 ].uri, 'http://localhost/users/user-slug'); | ||
done(); | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
55
1606
194
138728