forked from jaredhanson/passport-facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
564d4b8
commit 614b540
Showing
9 changed files
with
202 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var chai = require('chai'); | ||
|
||
global.expect = chai.expect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var strategy = require('..'); | ||
|
||
describe('passport-facebook', function() { | ||
|
||
it('should export Strategy constructor directly from package', function() { | ||
expect(strategy).to.be.a('function'); | ||
expect(strategy).to.equal(strategy.Strategy); | ||
}); | ||
|
||
it('should export Strategy constructor', function() { | ||
expect(strategy.Strategy).to.be.a('function'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.getProtectedResource = 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.getProtectedResource = 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'); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
var FacebookStrategy = require('../lib/strategy'); | ||
|
||
|
||
describe('Strategy#userProfile', function() { | ||
|
||
var strategy = new FacebookStrategy({ | ||
clientID: 'ABC123', | ||
clientSecret: 'secret' | ||
}, | ||
function() {}); | ||
|
||
// mock | ||
strategy._oauth2.getProtectedResource = 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; | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var FacebookStrategy = require('../lib/strategy'); | ||
|
||
|
||
describe('Strategy', function() { | ||
|
||
var strategy = new FacebookStrategy({ | ||
clientID: 'ABC123', | ||
clientSecret: 'secret' | ||
}, | ||
function() {}); | ||
|
||
it('should be named facebook', function() { | ||
expect(strategy.name).to.equal('facebook'); | ||
}); | ||
|
||
}); |