var assert = require('chai').assert,
    GooglePlusTokenStrategy = require('../'),
    fakeProfile = JSON.stringify(require('./fixtures/profile.json'));

describe('GooglePlusTokenStrategy', function () {
    it('Should properly export Strategy constructor', function () {
        assert.equal(typeof GooglePlusTokenStrategy, 'function');
        assert.equal(typeof GooglePlusTokenStrategy.Strategy, 'function');
        assert.equal(GooglePlusTokenStrategy, GooglePlusTokenStrategy.Strategy);
    });

    it('Should properly initialize', function () {
        var strategy = new GooglePlusTokenStrategy({
            clientID: '123',
            clientSecret: '123'
        }, function () {
        });

        assert.equal(strategy.name, 'google-plus-token');
        assert(strategy._oauth2._useAuthorizationHeaderForGET);
    });

    it('Should properly parse request in authenticate', function (done) {
        var strategy = new GooglePlusTokenStrategy({
            clientID: '123',
            clientSecret: '123'
        }, function (accessToken, refreshToken, profile, next) {
            next(null, profile, null);
            done();
        });

        //strategy.authenticate({
        //    headers: {
        //        access_token: '',
        //        refresh_token: ''
        //    }
        //}, {});
        done();
    });

    it('Should properly fetch profile', function (done) {
        var strategy = new GooglePlusTokenStrategy({
            clientID: '123',
            clientSecret: '123'
        }, function (accessToken, refreshToken, profile, next) {
            next(null, profile, null);
        });

        strategy._oauth2.get = function (url, accessToken, next) {
            next(null, fakeProfile, null);
        };

        strategy.userProfile('accessToken', function (error, profile) {
            if (error) return done(error);

            assert.equal(profile.provider, 'google-plus');
            assert.equal(profile.id, '103819813774047251222');
            assert.equal(profile.displayName, 'Andrew Orel');
            assert.equal(profile.name.familyName, 'Orel');
            assert.equal(profile.name.givenName, 'Andrew');
            assert.deepEqual(profile.emails, []);
            assert.equal(profile.photos[0].value, 'https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50');
            assert.equal(typeof profile._raw, 'string');
            assert.equal(typeof profile._json, 'object');

            done();
        });
    });

    it('Should properly handle exception on fetching profile', function (done) {
        var strategy = new GooglePlusTokenStrategy({
            clientID: '123',
            clientSecret: '123'
        }, function () {
        });

        strategy._oauth2.get = function (url, accessToken, done) {
            done(null, 'not a JSON', null);
        };

        strategy.userProfile('accessToken', function (error, profile) {
            assert(error instanceof SyntaxError);
            assert.equal(typeof profile, 'undefined');
            done();
        });
    });
});

@@ -1,18 +1,16 @@
 var 
-assert
+chai
  = requi
@@ -19,16 +19,35 @@
 ('chai')
+,%0A    assert = chai
 .assert,
@@ -855,60 +855,145 @@
     
-it('Should properly parse request in authenticate', 
+describe('GooglePlusTokenStrategy:authenticate', function () %7B%0A        var strategy,%0A            user,%0A            info;%0A%0A        before(
 func
@@ -1006,35 +1006,35 @@
 done) %7B%0A        
+   
-var
  strategy = new 
@@ -1063,32 +1063,36 @@
 y(%7B%0A            
+    
 clientID: '123',
@@ -1096,32 +1096,36 @@
 3',%0A            
+ 
+   
 clientSecret: '1
@@ -1120,32 +1120,36 @@
 ntSecret: '123'%0A
+    
         %7D, funct
@@ -1201,32 +1201,135 @@
 ) %7B%0A            
+    if (accessToken == 'access_token' && refreshToken == 'refresh_token') %7B%0A                    return 
 next(null, profi
@@ -1324,36 +1324,45 @@
 (null, profile, 
-null
+%7Binfo: 'foo'%7D
 );%0A            d
@@ -1352,37 +1352,84 @@
 %7D);%0A            
-done(
+    %7D%0A%0A                return next(null, false, null
 );%0A        %7D);%0A%0A
@@ -1415,32 +1415,36 @@
  null);%0A        
+ 
+   
 %7D);%0A%0A        //s
@@ -1440,18 +1440,20 @@
         
-//
+    
 strategy
@@ -1457,45 +1457,382 @@
 egy.
+_o
 auth
-enticate(%7B%0A        //    
+2.get = function (url, accessToken, done) %7B%0A                done(null, fakeProfile, null);%0A            %7D;%0A%0A            chai.passport.use(strategy)%0A                .success(function (u, i) %7B%0A                    user = u;%0A                    info = i;%0A                    done();%0A                %7D)%0A                .req(function (req) %7B%0A                    req.
 headers
-:
+ =
  %7B%0A 
@@ -1830,34 +1830,40 @@
 ers = %7B%0A        
+ 
-//
+       
         access_t
@@ -1869,27 +1869,42 @@
 token: '
-',%0A
+access_token',%0A   
         
 //      
@@ -1891,26 +1891,29 @@
 %0A           
-//
+     
         refr
@@ -1924,16 +1924,29 @@
 token: '
+refresh_token
 '%0A      
@@ -1947,18 +1947,24 @@
         
-//
+        
     %7D%0A  
@@ -1973,31 +1973,278 @@
     
-//%7D, %7B%7D);%0A        done(
+        %7D)%0A                .authenticate(%7B%7D);%0A        %7D);%0A%0A        it('Should properly respond with profile', function () %7B%0A            assert.typeOf(user, 'object');%0A            assert.typeOf(info, 'object');%0A            assert.deepEqual(info, %7Binfo: 'foo'%7D);%0A        %7D
 );%0A 

Add test for authenticate