Skip to content

Commit 2072dc8

Browse files
committed
Added tests for follow and unfollow.
1 parent bf6b42a commit 2072dc8

File tree

1 file changed

+67
-5
lines changed

1 file changed

+67
-5
lines changed

test/user.spec.js

Lines changed: 67 additions & 5 deletions
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.json';
35
import {assertSuccessful, assertArray} from './helpers/callbacks';
@@ -61,14 +63,74 @@ describe('User', function() {
6163
user.listStarredRepos(assertArray(done));
6264
});
6365

64-
it('should follow user', function(done) {
65-
user.follow('ingalls', assertSuccessful(done));
66-
});
66+
describe('following a user', function() {
67+
const userToFollow = 'ingalls';
6768

68-
it('should unfollow user', function(done) {
69-
user.unfollow('ingalls', assertSuccessful(done));
69+
before(function() {
70+
return user.unfollow(userToFollow);
71+
})
72+
73+
it('should follow user', function(done) {
74+
user.follow(userToFollow, assertSuccessful(done, function(err, resp) {
75+
user._request('GET', `/user/following`, null, assertSuccessful(done, function(err, following) {
76+
expect((following.some(user => user['login'] === userToFollow))).to.be.true();
77+
done();
78+
}));
79+
}));
80+
});
7081
});
7182

83+
describe('following yourself', function() {
84+
const userToFollow = testUser.USERNAME;
85+
86+
before(function() {
87+
return user.unfollow(userToFollow);
88+
})
89+
90+
it('should attempt to follow yourself', function(done) {
91+
user.follow(userToFollow, assertSuccessful(done, function(err, resp) {
92+
user._request('GET', `/user/following`, null, assertSuccessful(done, function(err, following) {
93+
expect((following.some(user => user['login'] === userToFollow))).to.be.false();
94+
done();
95+
}));
96+
}));
97+
});
98+
})
99+
100+
describe('unfollowing a user', function(done) {
101+
const userToUnfollow = 'ingalls';
102+
103+
before(function() {
104+
return user.follow(userToUnfollow);
105+
})
106+
107+
it('should attempt to unfollow a user', function(done) {
108+
user.unfollow(userToUnfollow, assertSuccessful(done, function(err, resp) {
109+
user._request('GET', `/user/following`, null, assertSuccessful(done, function(err, following) {
110+
expect((following.some(user => user['login'] === userToUnfollow))).to.be.false();
111+
done();
112+
}));
113+
}));
114+
});
115+
})
116+
117+
describe('unfollowing yourself', function(done) {
118+
const userToUnfollow = testUser.USERNAME;
119+
120+
before(function() {
121+
return user.follow(userToUnfollow);
122+
})
123+
124+
it('should attempt to unfollow yourself', function(done) {
125+
user.unfollow(userToUnfollow, assertSuccessful(done, function(err, resp) {
126+
user._request('GET', `/user/following`, null, assertSuccessful(done, function(err, following) {
127+
expect((following.some(user => user['login'] === userToUnfollow))).to.be.false();
128+
done();
129+
}));
130+
}));
131+
});
132+
})
133+
72134
it('should list the email addresses of the user', function(done) {
73135
user.getEmails(assertSuccessful(done));
74136
});

0 commit comments

Comments
 (0)
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