forked from jaredhanson/passport-facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.options.test.js
78 lines (63 loc) · 2.9 KB
/
strategy.options.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() {
describe('with profile URL option', function() {
var strategy = new FacebookStrategy({
clientID: 'ABC123',
clientSecret: 'secret',
profileURL: 'https://graph.facebook.com/me?fields=id,username'
},
function() {});
// mock
strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/me?fields=id,username') { 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');
});
});
});
describe('with profile fields mapped from portable contacts schema', function() {
var strategy = new FacebookStrategy({
clientID: 'ABC123',
clientSecret: 'secret',
profileFields: ['id', 'username', 'displayName', 'name', 'gender', 'profileUrl', 'emails', 'photos']
},
function() {});
// mock
strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/me?fields=id,username,name,last_name,first_name,middle_name,gender,link,email,picture') { 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');
});
});
});
});