From bf6b42a040a2f0461e5ab855496a5a457d3f0c71 Mon Sep 17 00:00:00 2001 From: CodyGramlich Date: Wed, 10 Apr 2019 22:24:26 -0600 Subject: [PATCH 1/3] Use username arg for follow and unfollow requests. --- lib/User.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/User.js b/lib/User.js index 3f3b4bb6..3b5cb653 100644 --- a/lib/User.js +++ b/lib/User.js @@ -150,7 +150,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); } /** @@ -161,7 +161,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); } /** From 2072dc8e80fb544634d924d088dd4dd319f17bd0 Mon Sep 17 00:00:00 2001 From: CodyGramlich Date: Wed, 1 May 2019 22:43:23 -0600 Subject: [PATCH 2/3] Added tests for follow and unfollow. --- test/user.spec.js | 72 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/test/user.spec.js b/test/user.spec.js index 2296781c..e611ffee 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.json'; import {assertSuccessful, assertArray} from './helpers/callbacks'; @@ -61,14 +63,74 @@ describe('User', function() { user.listStarredRepos(assertArray(done)); }); - it('should follow user', function(done) { - user.follow('ingalls', assertSuccessful(done)); - }); + describe('following a user', function() { + const userToFollow = 'ingalls'; - it('should unfollow user', function(done) { - user.unfollow('ingalls', assertSuccessful(done)); + 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(); + })); + })); + }); }); + describe('following yourself', function() { + const userToFollow = testUser.USERNAME; + + before(function() { + return user.unfollow(userToFollow); + }) + + it('should attempt to follow yourself', 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 attempt to 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(); + })); + })); + }); + }) + + describe('unfollowing yourself', function(done) { + const userToUnfollow = testUser.USERNAME; + + before(function() { + return user.follow(userToUnfollow); + }) + + it('should attempt to unfollow yourself', 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) { user.getEmails(assertSuccessful(done)); }); From 4d3f0757333d718295a462d0440111bcf3901a7d Mon Sep 17 00:00:00 2001 From: CodyGramlich Date: Wed, 1 May 2019 22:53:42 -0600 Subject: [PATCH 3/3] Changed test names and removed a test. --- test/user.spec.js | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/test/user.spec.js b/test/user.spec.js index e611ffee..ee1b6e8e 100644 --- a/test/user.spec.js +++ b/test/user.spec.js @@ -87,7 +87,7 @@ describe('User', function() { return user.unfollow(userToFollow); }) - it('should attempt to follow yourself', function(done) { + 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(); @@ -104,24 +104,7 @@ describe('User', function() { return user.follow(userToUnfollow); }) - it('should attempt to 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(); - })); - })); - }); - }) - - describe('unfollowing yourself', function(done) { - const userToUnfollow = testUser.USERNAME; - - before(function() { - return user.follow(userToUnfollow); - }) - - it('should attempt to unfollow yourself', function(done) { + 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();