Skip to content

Commit

Permalink
More test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 4, 2016
1 parent 9e52e51 commit 8a6c4a5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -2,7 +2,7 @@ include node_modules/make-node/main.mk


SOURCES = lib/*.js lib/**/*.js
TESTS = test/*.test.js
TESTS = test/*.test.js test/**/*.test.js

LCOVFILE = ./reports/coverage/lcov.info

Expand Down
12 changes: 12 additions & 0 deletions lib/profile/openid.js
@@ -1,6 +1,18 @@
/**
* Parse profile.
*
* Parses user profiles as fetched from Google's OpenID Connect-compatible user
* info endpoint.
*
* The amount of detail in the profile varies based on the scopes granted by the
* user. The following scope values add additional data:
*
* `profile` - basic profile information
* `email` - email address
*
* References:
* - https://developers.google.com/identity/protocols/OpenIDConnect
*
* @param {object|string} json
* @return {object}
* @access public
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -43,6 +43,6 @@
"node": ">= 0.4.0"
},
"scripts": {
"test": "node_modules/.bin/mocha --require test/bootstrap/node test/*.test.js"
"test": "node_modules/.bin/mocha --require test/bootstrap/node test/*.test.js test/**/*.test.js"
}
}
8 changes: 8 additions & 0 deletions test/fixtures/userinfo/userinfo-with-profile.json
@@ -0,0 +1,8 @@
{
"sub": "111111111111111111111",
"name": "Jared Hanson",
"given_name": "Jared",
"family_name": "Hanson",
"picture": "https://lh3.googleusercontent.com/-XxXXxxXxXXX/AAAAAAAAAAI/AAAAAAAAAAA/0000xxxxx0X/photo.jpg",
"locale": "en"
}
29 changes: 29 additions & 0 deletions test/profile/openid.test.js
@@ -0,0 +1,29 @@
var Profile = require('../../lib/profile/openid')
, fs = require('fs')


describe('OpenIDProfile.parse', function() {

describe('profile with profile scope', function() {
var profile;

before(function(done) {
fs.readFile('test/fixtures/userinfo/userinfo-with-profile.json', 'utf8', function(err, data) {
if (err) { return done(err); }
profile = Profile.parse(data);
done();
});
});

it('should parse profile', function() {
expect(profile.id).to.equal('111111111111111111111');
expect(profile.displayName).to.equal('Jared Hanson');
expect(profile.name.familyName).to.equal('Hanson');
expect(profile.name.givenName).to.equal('Jared');
expect(profile.photos).to.have.length(1);
expect(profile.emails).to.be.undefined;
expect(profile.photos[0].value).to.equal('https://lh3.googleusercontent.com/-XxXXxxXxXXX/AAAAAAAAAAI/AAAAAAAAAAA/0000xxxxx0X/photo.jpg');
});
});

});

0 comments on commit 8a6c4a5

Please sign in to comment.