From bf6b42a040a2f0461e5ab855496a5a457d3f0c71 Mon Sep 17 00:00:00 2001 From: CodyGramlich Date: Wed, 10 Apr 2019 22:24:26 -0600 Subject: [PATCH 1/5] 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/5] 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/5] 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(); From 52e0f99630f58e442385d446046f670497a295d2 Mon Sep 17 00:00:00 2001 From: j-rewerts Date: Mon, 17 Jun 2019 14:29:45 -0600 Subject: [PATCH 4/5] Fixed linting. --- test/user.spec.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/user.spec.js b/test/user.spec.js index dc320539..90184b2a 100644 --- a/test/user.spec.js +++ b/test/user.spec.js @@ -83,12 +83,12 @@ describe('User', function() { 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(); + user._request('GET', '/user/following', null, assertSuccessful(done, function(err, following) { + expect((following.some((user) => user['login'] === userToFollow))).to.be.true(); done(); })); })); @@ -100,34 +100,34 @@ describe('User', function() { 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(); + 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(); + 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 1932d2d6910fa74738b9029450594c3284f0143e Mon Sep 17 00:00:00 2001 From: j-rewerts Date: Mon, 17 Jun 2019 14:31:34 -0600 Subject: [PATCH 5/5] Incremented version to v3.2.2. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",