Skip to content

Following users #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
53 changes: 49 additions & 4 deletions test/user.spec.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy