<commit_before>var vows = require('vows');
var assert = require('assert');
var util = require('util');
var OdeskStrategy = require('./../lib/passport-odesk').Strategy;

vows.describe('OdeskStrategy').addBatch({
  
  'strategy': {
    topic: function() {
      return new OdeskStrategy({
        consumerKey: 'ABC123',
        consumerSecret: 'secret'
      },
      function() {});
    },
    
    'should be named odesk': function (strategy) {
      assert.equal(strategy.name, 'odesk');
    }
  },
  

  'strategy when loading user profile': {
    topic: function() {
      var strategy = new OdeskStrategy({
        consumerKey: 'ABC123',
        consumerSecret: 'secret'
      },
      function() {});
      
      // mock
      strategy._oauth.get = function(url, token, tokenSecret, callback) {
          var body = '{' +
              '"server_time":"1367492929", ' +
              '"auth_user": ' +
              '          { ' +
              '              "first_name":"John", ' +
              '              "last_name":"Doe", ' +
              '              "uid":"John_Doe", ' +
              '              "mail":"<EMAIL>", ' +
              '              "messenger_id":"", ' +
              '              "messenger_type":"", ' +
              '              "timezone":"Europe\/Klin", ' +
              '              "timezone_offset":"14400" ' +
              '         }, ' +
              '"info": ' +
              '          { ' +
              '              "portrait_50_img":"https:\/\/odesk-prod-portraits.s3.amazonaws.com\/Users:romanov_klin:PortraitUrl_50?AWSAccessKeyId=<KEY>&Expires=2147483647&Signature=P7XYYyZr9c%2Bvv%2F25voKeTg92eFc%3D", ' +
              '              "ref":"3603850", ' +
              '              "portrait_32_img":"https:\/\/odesk-prod-portraits.s3.amazonaws.com\/Users:romanov_klin:PortraitUrl_32?AWSAccessKeyId=<KEY>&Expires=2147483647&Signature=IZROy3xeRt260AJ3oPp3M9nJP8g%3D",' +
              '              "has_agency":"0",' +
              '              "portrait_100_img":"https:\/\/odesk-prod-portraits.s3.amazonaws.com\/Users:romanov_klin:PortraitUrl_100?AWSAccessKeyId=<KEY>&Expires=2147483647&Signature=lOzpO2SN%2BEqwB30YsBeHz1wHMsk%3D", ' +
              '              "company_url":"http://example.com", ' +
              '              "capacity":{"provider":"yes","buyer":"yes","affiliate_manager":"no"}, ' +
              '              "location":{"city":"Klin","state":"","country":"Russia"}, ' +
              '              "profile_url":"https:\/\/www.odesk.com\/users\/~johnDoe"} ' +
              '          } ' +
              '';

          callback(null, body, undefined);
      }
      
      return strategy;
    },
    
    'when told to load user profile': {
      topic: function(strategy) {
        var self = this;
        function done(err, profile) {
          self.callback(err, profile);
        }
        
        process.nextTick(function () {
          strategy.userProfile('token', 'token-secret', {}, done);
        });
      },
      
      'should not error' : function(err, req) {
        assert.isNull(err);
      },
      'should load profile' : function(err, profile) {
        assert.equal(profile.provider, 'odesk');
        assert.equal(profile.displayName, '<NAME>');
        assert.equal(profile.img, 'https://odesk-prod-portraits.s3.amazonaws.com/Users:romanov_klin:PortraitUrl_50?AWSAccessKeyId=<KEY>&Expires=2147483647&Signature=P7XYYyZr9c%2Bvv%2F25voKeTg92eFc%3D');
        assert.equal(profile.country, 'Russia');
        assert.equal(profile.profile, 'https://www.odesk.com/users/~johnDoe');
        assert.notStrictEqual(profile.emails, [{"value":"<EMAIL>",type:"work"}]);
        assert.equal(profile.timezone, 'Europe/Klin');
        assert.equal(profile.timezone_offset, '14400');
        assert.notStrictEqual(profile.location, {"city":"Klin","state":"","country":"Russia"});
        assert.equal(profile.company_url, 'http://example.com');
      }
    }
  },
  
  'strategy when loading user profile and encountering an error': {
    topic: function() {
      var strategy = new OdeskStrategy({
        consumerKey: 'ABC123',
        consumerSecret: 'secret'
      },
      function() {});
      
      // mock
      strategy._oauth.get = function(url, token, tokenSecret, callback) {<commit_msg>test for name<commit_after>var vows = require('vows');
var assert = require('assert');
var util = require('util');
var OdeskStrategy = require('./../lib/passport-odesk').Strategy;

vows.describe('OdeskStrategy').addBatch({
  
  'strategy': {
    topic: function() {
      return new OdeskStrategy({
        consumerKey: 'ABC123',
        consumerSecret: 'secret'
      },
      function() {});
    },
    
    'should be named odesk': function (strategy) {
      assert.equal(strategy.name, 'odesk');
    }
  },
  

  'strategy when loading user profile': {
    topic: function() {
      var strategy = new OdeskStrategy({
        consumerKey: 'ABC123',
        consumerSecret: 'secret'
      },
      function() {});
      
      // mock
      strategy._oauth.get = function(url, token, tokenSecret, callback) {
          var body = '{' +
              '"server_time":"1367492929", ' +
              '"auth_user": ' +
              '          { ' +
              '              "first_name":"John", ' +
              '              "last_name":"Doe", ' +
              '              "uid":"John_Doe", ' +
              '              "mail":"<EMAIL>", ' +
              '              "messenger_id":"", ' +
              '              "messenger_type":"", ' +
              '              "timezone":"Europe\/Klin", ' +
              '              "timezone_offset":"14400" ' +
              '         }, ' +
              '"info": ' +
              '          { ' +
              '              "portrait_50_img":"https:\/\/odesk-prod-portraits.s3.amazonaws.com\/Users:romanov_klin:PortraitUrl_50?AWSAccessKeyId=<KEY>&Expires=2147483647&Signature=P7XYYyZr9c%2Bvv%2F25voKeTg92eFc%3D", ' +
              '              "ref":"3603850", ' +
              '              "portrait_32_img":"https:\/\/odesk-prod-portraits.s3.amazonaws.com\/Users:romanov_klin:PortraitUrl_32?AWSAccessKeyId=<KEY>&Expires=2147483647&Signature=IZROy3xeRt260AJ3oPp3M9nJP8g%3D",' +
              '              "has_agency":"0",' +
              '              "portrait_100_img":"https:\/\/odesk-prod-portraits.s3.amazonaws.com\/Users:romanov_klin:PortraitUrl_100?AWSAccessKeyId=<KEY>&Expires=2147483647&Signature=lOzpO2SN%2BEqwB30YsBeHz1wHMsk%3D", ' +
              '              "company_url":"http://example.com", ' +
              '              "capacity":{"provider":"yes","buyer":"yes","affiliate_manager":"no"}, ' +
              '              "location":{"city":"Klin","state":"","country":"Russia"}, ' +
              '              "profile_url":"https:\/\/www.odesk.com\/users\/~johnDoe"} ' +
              '          } ' +
              '';

          callback(null, body, undefined);
      }
      
      return strategy;
    },
    
    'when told to load user profile': {
      topic: function(strategy) {
        var self = this;
        function done(err, profile) {
          self.callback(err, profile);
        }
        
        process.nextTick(function () {
          strategy.userProfile('token', 'token-secret', {}, done);
        });
      },
      
      'should not error' : function(err, req) {
        assert.isNull(err);
      },
      'should load profile' : function(err, profile) {
        assert.equal(profile.provider, 'odesk');
        assert.equal(profile.displayName, '<NAME>');
        assert.notStrictEqual(profile.name, {"familyName": 'Doe', "givenName": 'John'});
        assert.equal(profile.img, 'https://odesk-prod-portraits.s3.amazonaws.com/Users:romanov_klin:PortraitUrl_50?AWSAccessKeyId=<KEY>&Expires=2147483647&Signature=P7XYYyZr9c%2Bvv%2F25voKeTg92eFc%3D');
        assert.equal(profile.country, 'Russia');
        assert.equal(profile.profile, 'https://www.odesk.com/users/~johnDoe');
        assert.notStrictEqual(profile.emails, [{"value":"<EMAIL>",type:"work"}]);
        assert.equal(profile.timezone, 'Europe/Klin');
        assert.equal(profile.timezone_offset, '14400');
        assert.notStrictEqual(profile.location, {"city":"Klin","state":"","country":"Russia"});
        assert.equal(profile.company_url, 'http://example.com');
      }
    }
  },
  
  'strategy when loading user profile and encountering an error': {
    topic: function() {
      var strategy = new OdeskStrategy({
        consumerKey: 'ABC123',
        consumerSecret: 'secret'
      },
      function() {});
      
      // mock
      strategy._oauth.get = function(url, token, tokenSecret, callback) {
{'fraction_non_alphanumeric': 0.16424734255343468, 'fraction_numerical': 0.029717682020802376, 'mean_word_length': 1.9986291980808772, 'pattern_counts': {'":': 62, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4188706', 'n_tokens_mistral': 2891, 'n_tokens_neox': 2723, 'n_words': 323}