forked from jaredhanson/passport-facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.profile.test.js
78 lines (62 loc) · 2.48 KB
/
strategy.profile.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var FacebookStrategy = require('../lib/strategy');
describe('Strategy#userProfile', function() {
var strategy = new FacebookStrategy({
clientID: 'ABC123',
clientSecret: 'secret'
},
function() {});
// mock
strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/me') { return callback(new Error('incorrect url argument')); }
if (accessToken != 'token') { return callback(new Error('incorrect token argument')); }
var body = '{"id":"500308595","name":"Jared Hanson","first_name":"Jared","last_name":"Hanson","link":"http:\\/\\/www.facebook.com\\/jaredhanson","username":"jaredhanson","gender":"male","email":"jaredhanson\\u0040example.com"}';
callback(null, body, undefined);
}
describe('loading profile', function() {
var profile;
before(function(done) {
strategy.userProfile('token', function(err, p) {
if (err) { return done(err); }
profile = p;
done();
});
});
it('should parse profile', function() {
expect(profile.provider).to.equal('facebook');
expect(profile.id).to.equal('500308595');
expect(profile.username).to.equal('jaredhanson');
expect(profile.displayName).to.equal('Jared Hanson');
expect(profile.name.familyName).to.equal('Hanson');
expect(profile.name.givenName).to.equal('Jared');
expect(profile.gender).to.equal('male');
expect(profile.profileUrl).to.equal('http://www.facebook.com/jaredhanson');
expect(profile.emails).to.have.length(1);
expect(profile.emails[0].value).to.equal('[email protected]');
expect(profile.photos).to.be.undefined;
});
it('should set raw property', function() {
expect(profile._raw).to.be.a('string');
});
it('should set json property', function() {
expect(profile._json).to.be.an('object');
});
});
describe('encountering an error', function() {
var err, profile;
before(function(done) {
strategy.userProfile('wrong-token', function(e, p) {
err = e;
profile = p;
done();
});
});
it('should error', function() {
expect(err).to.be.an.instanceOf(Error);
expect(err.constructor.name).to.equal('InternalOAuthError');
expect(err.message).to.equal('Failed to fetch user profile');
});
it('should not load profile', function() {
expect(profile).to.be.undefined;
});
});
});