diff --git a/lib/User.js b/lib/User.js index 4848a1c6..d6470324 100644 --- a/lib/User.js +++ b/lib/User.js @@ -187,7 +187,7 @@ class User extends Requestable { * @return {Promise} - the promise for the http request */ follow(username, cb) { - return this._request('PUT', `/user/following/${this.__user}`, null, cb); + return this._request('PUT', `/user/following/${username}`, null, cb); } /** @@ -198,7 +198,7 @@ class User extends Requestable { * @return {Promise} - the promise for the http request */ unfollow(username, cb) { - return this._request('DELETE', `/user/following/${this.__user}`, null, cb); + return this._request('DELETE', `/user/following/${username}`, null, cb); } /** diff --git a/package.json b/package.json index 6767a671..c42a3a49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-api", - "version": "3.2.1", + "version": "3.2.2", "license": "BSD-3-Clause-Clear", "description": "A higher-level wrapper around the Github API.", "main": "dist/components/GitHub.js", diff --git a/test/user.spec.js b/test/user.spec.js index c099181b..90184b2a 100644 --- a/test/user.spec.js +++ b/test/user.spec.js @@ -1,3 +1,5 @@ +import expect from 'must'; + import Github from '../lib/GitHub'; import testUser from './fixtures/user.js'; import {assertSuccessful, assertArray} from './helpers/callbacks'; @@ -76,12 +78,55 @@ describe('User', function() { user.listStarredGists(option, assertArray(done)); }); - it('should follow user', function(done) { - user.follow('ingalls', assertSuccessful(done)); + describe('following a user', function() { + const userToFollow = 'ingalls'; + + before(function() { + return user.unfollow(userToFollow); + }); + + it('should follow user', function(done) { + user.follow(userToFollow, assertSuccessful(done, function(err, resp) { + user._request('GET', '/user/following', null, assertSuccessful(done, function(err, following) { + expect((following.some((user) => user['login'] === userToFollow))).to.be.true(); + done(); + })); + })); + }); }); - it('should unfollow user', function(done) { - user.unfollow('ingalls', assertSuccessful(done)); + describe('following yourself', function() { + const userToFollow = testUser.USERNAME; + + before(function() { + return user.unfollow(userToFollow); + }); + + it('should not list yourself as one of your followers', function(done) { + user.follow(userToFollow, assertSuccessful(done, function(err, resp) { + user._request('GET', '/user/following', null, assertSuccessful(done, function(err, following) { + expect((following.some((user) => user['login'] === userToFollow))).to.be.false(); + done(); + })); + })); + }); + }); + + describe('unfollowing a user', function(done) { + const userToUnfollow = 'ingalls'; + + before(function() { + return user.follow(userToUnfollow); + }); + + it('should unfollow a user', function(done) { + user.unfollow(userToUnfollow, assertSuccessful(done, function(err, resp) { + user._request('GET', '/user/following', null, assertSuccessful(done, function(err, following) { + expect((following.some((user) => user['login'] === userToUnfollow))).to.be.false(); + done(); + })); + })); + }); }); it('should list the email addresses of the user', function(done) {