Skip to content

Commit 9d4a6a4

Browse files
author
不四
committed
update tests
1 parent df556ef commit 9d4a6a4

12 files changed

+203
-115
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ TIMEOUT = 16000
44
MOCHA_OPTS =
55

66
install:
7-
@npm install
7+
@npm install --registry=https://registry.npm.taobao.org
88

99
test: install
1010
@NODE_ENV=test ./node_modules/.bin/mocha \
1111
--reporter $(REPORTER) \
1212
--timeout $(TIMEOUT) \
13+
--bail \
1314
$(MOCHA_OPTS) \
1415
$(TESTS)
1516

@@ -26,7 +27,7 @@ test-coveralls: test
2627
test-all: test test-cov
2728

2829
autod: install
29-
@./node_modules/.bin/autod -w --prefix "~"
30+
@./node_modules/.bin/autod -w --prefix "~" -k should
3031
@$(MAKE) install
3132

3233
contributors: install

lib/branch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* gitlab - lib/branch.js
2+
* gitlab lib/branch.js
33
* Copyright(c) 2014 dead_horse <[email protected]>
44
* MIT Licensed
55
*/

lib/gitlab.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var User = require('./user');
2323
var Repository = require('./repository');
2424
var MergeRequest = require('./merge_request');
2525
var RepositoryFile = require('./repository_file');
26+
var Branch = require('./branch');
2627

2728
/**
2829
* Create a gitlab API client.
@@ -45,6 +46,7 @@ function Gitlab(options) {
4546
this.issues = new Issue(this);
4647
this.users = new User(this);
4748
this.merge_requests = this.mergeRequests = new MergeRequest(this);
49+
this.branches = new Branch(this);
4850

4951
this.addResources({
5052
projects: Project,

test/client.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,53 @@ var gitlab = require('../');
22

33
var client = gitlab.create(require('./config'));
44

5-
module.exports = client;
5+
client.createProject = function (callback) {
6+
client._list(function (err) {
7+
if (err) {
8+
return client._create(callback);
9+
}
10+
callback();
11+
});
12+
};
13+
14+
client._list = function (callback) {
15+
client.request('get', '/projects', {}, function (err, repos) {
16+
if (err) {
17+
return callback(err);
18+
}
19+
for (var i = 0; i < repos.length; i++) {
20+
if (repos[i].name === 'node-gitlab-test') {
21+
client.id = repos[i].id;
22+
return callback();
23+
}
24+
}
25+
return callback(new Error('not found'));
26+
});
27+
};
28+
29+
client._create = function(callback) {
30+
client.projects.create({
31+
name: 'node-gitlab-test',
32+
issues_enabled: true,
33+
merge_requests_enabled: true,
34+
public: true
35+
}, function (err, data) {
36+
if (err) {
37+
return callback(err);
38+
}
39+
client.id = data.id;
40+
callback(err, data);
41+
});
42+
};
43+
44+
client.removeProject = function (callback) {
45+
client.projects.remove({
46+
id: client.id
47+
}, callback);
48+
}
49+
50+
module.exports = client;
51+
52+
// client.request('get', '/users', {}, function () {
53+
// console.log(arguments);
54+
// })

test/hook.test.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,26 @@
1313
var client = require('./client');
1414
var should = require('should');
1515

16+
var hookId;
1617
describe('hook.test.js', function () {
17-
18+
before(function (done) {
19+
client.createProject(function (err) {
20+
client.hooks.create({id: client.id, url: 'http://gitlab.alibaba-inc.com/help/api'}, function (err, data) {
21+
if (err) {
22+
return done(err);
23+
}
24+
hookId = data.id;
25+
done();
26+
});
27+
});
28+
});
29+
after(client.removeProject);
1830
describe('client.hooks.get()', function () {
19-
2031
it('should return a hook', function (done) {
21-
client.hooks.get({id: 223, hook_id: 142}, function (err, hook) {
32+
client.hooks.get({id: client.id, hook_id: hookId}, function (err, hook) {
2233
should.not.exists(err);
23-
hook.id.should.equal(142);
24-
hook.should.have.keys('id', 'url', 'created_at');
34+
hook.id.should.equal(hookId);
35+
hook.should.have.keys('id', 'url', 'created_at', 'project_id', 'push_events', 'issues_events', 'merge_requests_events');
2536
done();
2637
});
2738
});
@@ -31,11 +42,11 @@ describe('hook.test.js', function () {
3142
describe('client.hooks.list()', function () {
3243

3344
it('should return hooks', function (done) {
34-
client.hooks.list({id: 223}, function (err, hooks) {
45+
client.hooks.list({id: client.id}, function (err, hooks) {
3546
should.not.exists(err);
3647
hooks.length.should.above(0);
3748
var hook = hooks[0];
38-
hook.should.have.keys('id', 'url', 'created_at');
49+
hook.should.have.keys('id', 'url', 'created_at', 'project_id', 'push_events', 'issues_events', 'merge_requests_events');
3950
done();
4051
});
4152
});
@@ -44,10 +55,10 @@ describe('hook.test.js', function () {
4455

4556
describe('client.hooks.create(), update(), remove()', function () {
4657
it('should create, update, remove a hook', function (done) {
47-
client.hooks.create({id: 223, url: 'http://gitlab.alibaba-inc.com/help/api'}, function (err, hook) {
58+
client.hooks.create({id: client.id, url: 'http://gitlab.alibaba-inc.com/help/api'}, function (err, hook) {
4859
should.not.exists(err);
4960
hook.url.should.equal('http://gitlab.alibaba-inc.com/help/api');
50-
client.hooks.update({id: 223, hook_id: hook.id, url: hook.url + '/update'}, function (err, hook) {
61+
client.hooks.update({id: client.id, hook_id: hook.id, url: hook.url + '/update'}, function (err, hook) {
5162
should.not.exists(err);
5263
hook.url.should.equal('http://gitlab.alibaba-inc.com/help/api/update');
5364
done();
@@ -60,10 +71,10 @@ describe('hook.test.js', function () {
6071
// done();
6172
// });
6273
// });
63-
74+
6475
});
6576
});
6677
});
6778
});
6879

69-
});
80+
});

test/issue.test.js

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,47 @@
1313
var client = require('./client');
1414
var should = require('should');
1515

16+
var issueId;
1617
describe('issue.test.js', function () {
18+
before(function (done) {
19+
client.createProject(function (err) {
20+
client.issues.create({
21+
id: client.id,
22+
title: 'test title ' + new Date(),
23+
description: '测试 `markdown` \n [abc](/abc)',
24+
labels: 'test,gitlabapi'
25+
}, function (err, data) {
26+
if (err) {
27+
return done(err);
28+
}
29+
issueId = data.id;
30+
done();
31+
});
32+
});
33+
});
1734

35+
after(client.removeProject);
1836
describe('client.issues.get()', function () {
19-
2037
it('should return a issue', function (done) {
21-
client.issues.get({id: 223, issue_id: 1098}, function (err, row) {
38+
client.issues.get({id: client.id, issue_id: issueId}, function (err, row) {
2239
should.not.exists(err);
23-
row.id.should.equal(1098);
24-
row.should.have.keys('id', 'project_id', 'title', 'description', 'labels',
40+
row.id.should.equal(issueId);
41+
row.should.have.keys('id', 'iid', 'project_id', 'title', 'description', 'labels',
2542
'milestone', 'assignee', 'author', 'state',
2643
'updated_at', 'created_at');
2744
done();
2845
});
2946
});
30-
3147
});
3248

3349
describe('client.issues.list()', function () {
3450

3551
it('should return issues', function (done) {
36-
client.issues.list({id: 223}, function (err, issues) {
52+
client.issues.list({id: client.id}, function (err, issues) {
3753
should.not.exists(err);
3854
issues.length.should.above(0);
3955
var row = issues[0];
40-
row.should.have.keys('id', 'project_id', 'title', 'description', 'labels',
56+
row.should.have.keys('id', 'iid', 'project_id', 'title', 'description', 'labels',
4157
'milestone', 'assignee', 'author', 'state',
4258
'updated_at', 'created_at');
4359
done();
@@ -49,18 +65,18 @@ describe('issue.test.js', function () {
4965
describe('client.issues.create(), update()', function () {
5066
it('should create, update a issue', function (done) {
5167
client.issues.create({
52-
id: 223,
68+
id: client.id,
5369
title: 'test title ' + new Date(),
5470
description: '测试 `markdown` \n [abc](/abc)',
5571
assignee_id: 142,
5672
milestone_id: 117,
5773
labels: 'test,gitlabapi'
5874
}, function (err, row) {
5975
should.not.exists(err);
60-
row.project_id.should.equal(223);
76+
row.project_id.should.equal(client.id);
6177
row.state.should.equal('opened');
6278
client.issues.update({
63-
id: 223,
79+
id: client.id,
6480
issue_id: row.id,
6581
title: row.title + ' update',
6682
state_event: 'close',
@@ -75,16 +91,16 @@ describe('issue.test.js', function () {
7591

7692
it('should update a close, reopen and close issue', function (done) {
7793
client.issues.update({
78-
id: 223,
79-
issue_id: 1385,
94+
id: client.id,
95+
issue_id: issueId,
8096
description: 'need to be closed!',
8197
state_event: 'close',
8298
}, function (err, row) {
8399
should.not.exists(err);
84100
row.state.should.equal('closed');
85101
client.issues.update({
86-
id: 223,
87-
issue_id: 1385,
102+
id: client.id,
103+
issue_id: issueId,
88104
description: 'need to be reopen!',
89105
state_event: 'reopen',
90106
}, function (err, row) {
@@ -99,7 +115,7 @@ describe('issue.test.js', function () {
99115

100116
describe('client.issues.listNotes()', function () {
101117
it('should return issue\'s notes', function (done) {
102-
client.issues.listNotes({id: 223, issue_id: 1098}, function (err, rows) {
118+
client.issues.listNotes({id: client.id, issue_id: issueId}, function (err, rows) {
103119
should.not.exists(err);
104120
rows.length.should.above(0);
105121
var row = rows[0];
@@ -112,7 +128,7 @@ describe('issue.test.js', function () {
112128
describe('client.issues.createNote()', function () {
113129
it('should create to note', function (done) {
114130
client.issues.createNote({
115-
id: 223, issue_id: 1098, body: '# h1 哈哈\n fixed #1098, fix #1098 fixes #1098'
131+
id: client.id, issue_id: issueId, body: '# h1 哈哈\n fixed #1098, fix #1098 fixes #1098'
116132
}, done);
117133
});
118134
});

test/member.test.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,33 @@
1212

1313
var client = require('./client');
1414
var should = require('should');
15+
var pedding = require('pedding');
1516

1617
describe('member.test.js', function () {
17-
18+
before(function (done) {
19+
done = pedding(2, done);
20+
client.createProject(function (err) {
21+
if (err) {
22+
return done(err);
23+
}
24+
client.members.create({
25+
id: client.id,
26+
user_id: 5,
27+
access_level: 10
28+
}, done);
29+
client.members.create({
30+
id: client.id,
31+
user_id: 6,
32+
access_level: 10
33+
}, done);
34+
});
35+
});
36+
after(client.removeProject);
1837
describe('client.members.get()', function () {
19-
2038
it('should return a member', function (done) {
21-
client.members.get({id: 223, user_id: 142}, function (err, member) {
39+
client.members.get({id: client.id, user_id: 5}, function (err, member) {
2240
should.not.exists(err);
23-
member.should.have.keys('id', 'username', 'email', 'name', 'state', 'created_at', 'access_level');
41+
member.should.have.keys('id', 'username', 'name', 'state', 'access_level', 'avatar_url');
2442
done();
2543
});
2644
});
@@ -30,15 +48,15 @@ describe('member.test.js', function () {
3048
describe('client.members.list()', function () {
3149

3250
it('should return members', function (done) {
33-
client.members.list({id: 365, per_page: 5}, function (err, members) {
51+
client.members.list({id: client.id, per_page: 2}, function (err, members) {
3452
should.not.exists(err);
35-
members.should.length(5);
53+
members.should.length(2);
3654
var member = members[0];
37-
member.should.have.keys('id', 'username', 'email', 'name', 'state', 'created_at', 'access_level');
55+
member.should.have.keys('id', 'username', 'name', 'state', 'access_level', 'avatar_url');
3856
done();
3957
});
4058
});
4159

4260
});
4361

44-
});
62+
});

test/merge_request.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)