Skip to content

Commit bf3a408

Browse files
authored
Merge pull request #572 from github-tools/following-users
Following users
2 parents 1ba01ed + 1932d2d commit bf3a408

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

lib/User.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class User extends Requestable {
187187
* @return {Promise} - the promise for the http request
188188
*/
189189
follow(username, cb) {
190-
return this._request('PUT', `/user/following/${this.__user}`, null, cb);
190+
return this._request('PUT', `/user/following/${username}`, null, cb);
191191
}
192192

193193
/**
@@ -198,7 +198,7 @@ class User extends Requestable {
198198
* @return {Promise} - the promise for the http request
199199
*/
200200
unfollow(username, cb) {
201-
return this._request('DELETE', `/user/following/${this.__user}`, null, cb);
201+
return this._request('DELETE', `/user/following/${username}`, null, cb);
202202
}
203203

204204
/**

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-api",
3-
"version": "3.2.1",
3+
"version": "3.2.2",
44
"license": "BSD-3-Clause-Clear",
55
"description": "A higher-level wrapper around the Github API.",
66
"main": "dist/components/GitHub.js",

test/user.spec.js

+49-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import expect from 'must';
2+
13
import Github from '../lib/GitHub';
24
import testUser from './fixtures/user.js';
35
import {assertSuccessful, assertArray} from './helpers/callbacks';
@@ -76,12 +78,55 @@ describe('User', function() {
7678
user.listStarredGists(option, assertArray(done));
7779
});
7880

79-
it('should follow user', function(done) {
80-
user.follow('ingalls', assertSuccessful(done));
81+
describe('following a user', function() {
82+
const userToFollow = 'ingalls';
83+
84+
before(function() {
85+
return user.unfollow(userToFollow);
86+
});
87+
88+
it('should follow user', function(done) {
89+
user.follow(userToFollow, assertSuccessful(done, function(err, resp) {
90+
user._request('GET', '/user/following', null, assertSuccessful(done, function(err, following) {
91+
expect((following.some((user) => user['login'] === userToFollow))).to.be.true();
92+
done();
93+
}));
94+
}));
95+
});
8196
});
8297

83-
it('should unfollow user', function(done) {
84-
user.unfollow('ingalls', assertSuccessful(done));
98+
describe('following yourself', function() {
99+
const userToFollow = testUser.USERNAME;
100+
101+
before(function() {
102+
return user.unfollow(userToFollow);
103+
});
104+
105+
it('should not list yourself as one of your followers', function(done) {
106+
user.follow(userToFollow, assertSuccessful(done, function(err, resp) {
107+
user._request('GET', '/user/following', null, assertSuccessful(done, function(err, following) {
108+
expect((following.some((user) => user['login'] === userToFollow))).to.be.false();
109+
done();
110+
}));
111+
}));
112+
});
113+
});
114+
115+
describe('unfollowing a user', function(done) {
116+
const userToUnfollow = 'ingalls';
117+
118+
before(function() {
119+
return user.follow(userToUnfollow);
120+
});
121+
122+
it('should unfollow a user', function(done) {
123+
user.unfollow(userToUnfollow, assertSuccessful(done, function(err, resp) {
124+
user._request('GET', '/user/following', null, assertSuccessful(done, function(err, following) {
125+
expect((following.some((user) => user['login'] === userToUnfollow))).to.be.false();
126+
done();
127+
}));
128+
}));
129+
});
85130
});
86131

87132
it('should list the email addresses of the user', function(done) {

0 commit comments

Comments
 (0)