UserApiTest.js
5.49 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* Copyright 2010 Ajax.org B.V.
*
* This product includes software developed by
* Ajax.org B.V. (http://www.ajax.org/).
*
* Author: Fabian Jaokbs <fabian@ajax.org>
*/
var sys = require("sys");
var GitHubApi = require("../lib/github").GitHubApi;
var async_testing = require('../vendor/node-async-testing/async_testing');
var suite = exports.suite = new async_testing.TestSuite();
var username = 'fjakobstest';
var token = 'b98166e45acf66df70a992e2de56b92a';
suite.setup(function() {
this.github = new GitHubApi(true);
this.userApi = this.github.getUserApi();
});
suite.addTests({
"test: search users" : function(assert, finished) {
this.userApi.search(username, function(err, users) {
assert.equal(users.length, 1);
assert.equal(users[0].name, username);
finished();
});
},
"test: show a user" : function(assert, finished) {
this.userApi.show(username, function(err, user) {
assert.equal(user.login, username);
finished();
});
},
"test: show a non existing user" : function(assert, finished) {
this.userApi.show('this-user-probably-doesnt-exist', function(err, user) {
assert.notEqual(err, undefined);
finished();
});
},
"test: get following users" : function(assert, finished) {
this.userApi.getFollowing('fjakobs', function(err, following) {
assert.ok(following.length > 0);
finished();
});
},
"test: get follower users" : function(assert, finished) {
this.userApi.getFollowers('fjakobs', function(err, followers) {
assert.ok(followers.length > 0);
finished();
});
},
"test: authenticate user and update location to Argentinia" : function(assert, finished, test) {
test.github.authenticate(username, token);
test.userApi.update(username, {location: "Argentinia"}, function(err) {
test.userApi.show(username, function(err, user) {
assert.equal(user.location, "Argentinia");
finished();
});
});
},
"test: authenticate user and update location to France" : function(assert, finished, test) {
test.github.authenticate(username, token);
test.userApi.update(username, {location: "France"}, function(err) {
test.userApi.show(username, function(err, user) {
assert.equal(user.location, "France");
finished();
});
});
},
"test: follow and unfollow fjakobs" : function(assert, finished, test) {
test.github.authenticate(username, token);
test.userApi.follow("fjakobs", function(err) {
test.userApi.getFollowing(username, function(err, following) {
assert.ok(following.indexOf("fjakobs") !== -1);
test.userApi.unFollow("fjakobs", function(err) {
test.userApi.getFollowing(username, function(err, following) {
assert.ok(following.indexOf("fjakobs") === -1);
finished();
});
});
});
});
},
"test: get watched repos" : function(assert, finished, test) {
test.userApi.getWatchedRepos("fjakobs", function(err, repos) {
assert.ok(repos.length > 0);
assert.ok(repos[0].homepage !== undefined);
finished();
});
},
"test: get emails" : function(assert, finished, test) {
test.github.authenticate(username, token);
test.userApi.getEmails(function(err, mails) {
assert.ok(mails.indexOf("fabian@ajax.org") !== -1);
finished();
});
},
"test: add and remove email" : function(assert, finished, test) {
test.github.authenticate(username, token);
test.userApi.addEmail("juhu@ajax.org", function(err, mails) {
assert.ok(mails.indexOf("juhu@ajax.org") !== -1);
test.userApi.removeEmail("juhu@ajax.org", function(err, mails) {
assert.ok(mails.indexOf("juhu@ajax.org") === -1);
finished();
});
});
},
"test: get ssh keys" : function(assert, finished, test) {
test.github.authenticate(username, token);
test.userApi.getKeys(function(err, keys) {
assert.ok(keys[0].title !== undefined);
finished();
});
},
"test: add and remove ssh keys" : function(assert, finished, test) {
var sshKey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq3iNw6EbjbV7M+Y74bMaRJ2V4fhGbpCPf4r5LziRlbkwZ2odG3Zkxzvhgg6EGxh6M4PWwiTF/gK/2nk81aAGN8iKvqS8b8TML/0RHrYyvR2Okug+CR5LbLVO+yM23nAixadhrZqTreqqgjJvqF4ffD0rsfVyqaYAsNxDoqvLFaEyMqh0+gNsO20M1jRLjQqeA4gzvQhjMWSnzOzBpCorCECjhl9o7iqitDaTzUWPLB4V0jnuyG15nbDOrCmzA8l9wIrqSjI6Kglx2aZWRKcsEaCUPHD5n4F63og+8aHRPMaEvNCvKj/21a0/zhEtdh1Vd3etmfe38Rh4WmOyuv5L+Q== test@ajax.org";
test.github.authenticate(username, token);
test.userApi.addKey("test2", sshKey, function(err, keys) {
var key = keys.filter(function(key) { return key.title == "test2"; })[0];
assert.equal(key.key, sshKey.replace(" test@ajax.org", ""));
test.userApi.removeKey(key.id, function(err, keys) {
var key = keys.filter(function(key) { return key.title == "test2"; })[0];
assert.equal(key, undefined);
finished();
});
});
}
});
if (module === require.main) {
async_testing.runSuites({UserApi: suite});
}