forked from octokit/octokit.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserApiTest.js
160 lines (137 loc) · 5.63 KB
/
UserApiTest.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* Copyright 2010 Ajax.org B.V.
*
* This product includes software developed by
* Ajax.org B.V. (http://www.ajax.org/).
*
* Author: Fabian Jaokbs <[email protected]>
*/
"use strict";
var assert = require("assert");
var GitHubApi = require("../github").GitHubApi;
var username = 'fjakobstest';
var token = 'b98166e45acf66df70a992e2de56b92a';
var test = module.exports = {
setUp: function() {
this.github = new GitHubApi(true);
this.userApi = this.github.getUserApi();
},
"test: search users" : function(finished) {
this.userApi.search(username, function(err, users) {
assert.equal(err, null);
assert.ok(users.length);
assert.equal(users[0].login, username);
finished();
});
},
"test: show a user" : function(finished) {
this.userApi.show(username, function(err, user) {
assert.equal(err, null);
assert.equal(user.login, username);
finished();
});
},
"test: show a non existing user" : function(finished) {
this.userApi.show('this-user-probably-doesnt-exist', function(err, user) {
assert.notEqual(err, undefined);
finished();
});
},
"test: get following users" : function(finished) {
this.userApi.getFollowing('fjakobs', function(err, following) {
assert.equal(err, null);
assert.ok(following.length > 0);
finished();
});
},
"test: get follower users" : function(finished) {
this.userApi.getFollowers('fjakobs', function(err, followers) {
assert.equal(err, null);
assert.ok(followers.length > 0);
finished();
});
},
"test: authenticate user and update location to Argentinia" : function(finished) {
test.github.authenticateToken(username, token);
test.userApi.update(username, {location: "Argentinia"}, function(err) {
assert.equal(err, null);
test.userApi.show(username, function(err, user) {
assert.equal(user.location, "Argentinia");
finished();
});
});
},
"test: authenticate user and update location to France" : function(finished) {
test.github.authenticateToken(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(finished) {
test.github.authenticateToken(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(finished) {
test.userApi.getWatchedRepos("fjakobs", function(err, repos) {
assert.equal(err, null);
assert.ok(repos.length > 0);
assert.ok(repos[0].homepage !== undefined);
finished();
});
},
"test: get emails" : function(finished) {
test.github.authenticateToken(username, token);
test.userApi.getEmails(function(err, mails) {
assert.equal(err, null);
assert.ok(mails.indexOf("[email protected]") !== -1);
finished();
});
},
"test: add and remove email" : function(finished) {
test.github.authenticateToken(username, token);
test.userApi.addEmail("[email protected]", function(err, mails) {
assert.equal(err, null);
assert.ok(mails.indexOf("[email protected]") !== -1);
test.userApi.removeEmail("[email protected]", function(err, mails) {
assert.ok(mails.indexOf("[email protected]") === -1);
finished();
});
});
},
"test: get ssh keys" : function(finished) {
test.github.authenticateToken(username, token);
test.userApi.getKeys(function(err, keys) {
assert.equal(err, null);
assert.ok(keys[0].title !== undefined);
finished();
});
},
"test: add and remove ssh keys" : function(finished) {
var sshKey = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq3iNw6EbjbV7M+Y74bMaRJ2V4fhGbpCPf4r5LziRlbkwZ2odG3Zkxzvhgg6EGxh6M4PWwiTF/gK/2nk81aAGN8iKvqS8b8TML/0RHrYyvR2Okug+CR5LbLVO+yM23nAixadhrZqTreqqgjJvqF4ffD0rsfVyqaYAsNxDoqvLFaEyMqh0+gNsO20M1jRLjQqeA4gzvQhjMWSnzOzBpCorCECjhl9o7iqitDaTzUWPLB4V0jnuyG15nbDOrCmzA8l9wIrqSjI6Kglx2aZWRKcsEaCUPHD5n4F63og+8aHRPMaEvNCvKj/21a0/zhEtdh1Vd3etmfe38Rh4WmOyuv5L+Q== [email protected]";
test.github.authenticateToken(username, token);
test.userApi.addKey("test2", sshKey, function(err, keys) {
assert.equal(err, null);
var key = keys.filter(function(key) { return key.title == "test2"; })[0];
assert.equal(key.key, sshKey.replace(" [email protected]", ""));
test.userApi.removeKey(key.id, function(err, keys) {
var key = keys.filter(function(key) { return key.title == "test2"; })[0];
assert.equal(key, undefined);
finished();
});
});
}
};
!module.parent && require("asyncjs").test.testcase(module.exports).exec();