Permalink
Browse files

Port test cases to mocha.

  • Loading branch information...
1 parent 1a2450d commit 825e0175d3119dc712abd6fc7d65c8d677632d63 @jaredhanson committed Mar 9, 2014
Showing with 61 additions and 0 deletions.
  1. +3 −0 test/strategy-test.js
  2. +58 −0 test/strategy.options.test.js
View
@@ -73,6 +73,7 @@ vows.describe('GitHubStrategy').addBatch({
},
},
+ // OK
'strategy when loading user profile': {
topic: function() {
var strategy = new GitHubStrategy({
@@ -127,6 +128,7 @@ vows.describe('GitHubStrategy').addBatch({
},
},
+ // OK
'strategy when loading user profile from custom URL': {
topic: function() {
var strategy = new GitHubStrategy({
@@ -182,6 +184,7 @@ vows.describe('GitHubStrategy').addBatch({
},
},
+ // OK
'strategy when loading user profile and encountering an error': {
topic: function() {
var strategy = new GitHubStrategy({
@@ -0,0 +1,58 @@
+/* global describe, it, expect, before */
+/* jshint expr: true */
+
+var GitHubStrategy = require('../lib/strategy');
+
+
+describe('Strategy#userProfile', function() {
+
+ describe('loading profile using custom URL', function() {
+ var strategy = new GitHubStrategy({
+ clientID: 'ABC123',
+ clientSecret: 'secret',
+ userProfileURL: 'https://github.corpDomain/api/v3/user'
+ },
+ function() {});
+
+ // mock
+ strategy._oauth2.get = function(url, accessToken, callback) {
+ if (url != 'https://github.corpDomain/api/v3/user') { return callback(new Error('wrong url argument')); }
+ if (accessToken != 'token') { return callback(new Error('wrong token argument')); }
+
+ var body = '{ "login": "octocat", "id": 1, "name": "monalisa octocat", "email": "octocat@github.com", "html_url": "https://github.com/octocat" }';
+
+ callback(null, body, undefined);
+ };
+
+
+ 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('github');
+
+ expect(profile.id).to.equal('1');
+ expect(profile.username).to.equal('octocat');
+ expect(profile.displayName).to.equal('monalisa octocat');
+ expect(profile.profileUrl).to.equal('https://github.com/octocat');
+ expect(profile.emails).to.have.length(1);
+ expect(profile.emails[0].value).to.equal('octocat@github.com');
+ });
+
+ 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');
+ });
+ });
+
+});

0 comments on commit 825e017

Please sign in to comment.