<commit_before>'use strict';

var assert = require('assert');
var watson = require('../lib/index');
var nock   = require('nock');
var extend = require('extend');

describe('personality_insights', function() {

  var noop = function() {};

  var service_request = {
    text: 'IBM Watson Developer Cloud'
  };

  var payload = {
    contentItems: [{
      userid: 'dummy',
      id: 'dummyUuid',
      sourceid: 'freetext',
      contenttype: 'text/plain',
      language: 'en',
      content: service_request.text
    }]
  };
  var service_response = {
    tree: {}
  };

  var service_path = '/v2/profile';

  var service = {
    username: 'batman',
    password: '<PASSWORD>',
    url: 'http://ibm.com:80',
    version: 'v2'
  };

  before(function() {
    nock.disableNetConnect();
    nock(service.url)
      .persist()
      .post(service_path, payload)
      .reply(200, service_response)
      .post(service_path + '?include_raw=true', payload)
      .reply(200, service_response)
      .post(service_path, '"'+ service_request.text + '"')
      .reply(200, service_response);
  });

  after(function() {
    nock.cleanAll();
  });

  var personality_insights = watson.personality_insights(service);

  var missingParameter = function(err) {
    assert.ok((err instanceof Error) && /required parameters/.test(err));
  };

  it('should check no parameters provided', function() {
    personality_insights.profile({}, missingParameter);
    personality_insights.profile(null, missingParameter);
    personality_insights.profile(undefined, missingParameter);
  });

  it('should generate a valid payload with text', function() {
      var req = personality_insights.profile(service_request, noop);
      var body = new Buffer(req.body).toString('ascii');
      assert.equal(req.uri.href, service.url + service_path);
      assert.equal(body, '"' + service_request.text + '"');
      assert.equal(req.method, 'POST');
      assert.equal(req.headers['Content-type'], 'text/plain');
  });

  it('should generate a valid payload with contentItems', function() {
      var req = personality_insights.profile(payload, noop);
      var body = new Buffer(req.body).toString('ascii');
      assert.equal(req.uri.href, service.url + service_path);
      assert.equal(body, JSON.stringify(payload));
      assert.equal(req.method, 'POST');
      assert.equal(req.headers['Content-type'], 'application/json');
  });

  it('should generate a valid payload with html', function() {
      var html_req = { text:'<div>test</div>' };
      var req = personality_insights.profile(html_req, noop);
      var body = new Buffer(req.body).toString('ascii');
      assert.equal(req.uri.href, service.url + service_path);
      assert.equal(body, JSON.stringify(html_req.text));
      assert.equal(req.method, 'POST');
      assert.equal(req.headers['Content-type'], 'text/html');
  });

  it('should generate a valid payload with include_raw, language and acceptLanguage', function() {
    var params = extend({ language: 'es', acceptLanguage: 'es', include_raw: true}, payload);

      var req = personality_insights.profile(params, noop);
      var body = new Buffer(req.body).toString('ascii');
      assert.equal(req.uri.href, service.url + service_path + '?include_raw=true');
      assert.equal(body, JSON.stringify(payload));
      assert.equal(req.method, 'POST');
      assert.equal(req.headers['Content-type'], 'application/json');
      assert.equal(req.headers['Content-language'], 'es');
      assert.equal(req.headers['Accept-language'], 'es');
  });

  it('should format the response', function(done) {
    personality_insights.profile(service_request, function(err, response) {
      if (err)
        done(err);
      else {
        assert.equal(JSON.stringify(response), JSON.stringify(service_response));
        done();
      }
    });
  });<commit_msg>update test case<commit_after>'use strict';

var assert = require('assert');
var watson = require('../lib/index');
var nock   = require('nock');
var extend = require('extend');

describe('personality_insights', function() {

  var noop = function() {};

  var service_request = {
    text: 'IBM Watson Developer Cloud'
  };

  var payload = {
    contentItems: [{
      userid: 'dummy',
      id: 'dummyUuid',
      sourceid: 'freetext',
      contenttype: 'text/plain',
      language: 'en',
      content: service_request.text
    }]
  };
  var service_response = {
    tree: {}
  };

  var service_path = '/v2/profile';

  var service = {
    username: 'batman',
    password: '<PASSWORD>',
    url: 'http://ibm.com:80',
    version: 'v2'
  };

  before(function() {
    nock.disableNetConnect();
    nock(service.url)
      .persist()
      .post(service_path, payload)
      .reply(200, service_response)
      .post(service_path + '?include_raw=true', payload)
      .reply(200, service_response)
      .post(service_path, '"'+ service_request.text + '"')
      .reply(200, service_response);
  });

  after(function() {
    nock.cleanAll();
  });

  var personality_insights = watson.personality_insights(service);

  var missingParameter = function(err) {
    assert.ok((err instanceof Error) && /required parameters/.test(err));
  };

  it('should check no parameters provided', function() {
    personality_insights.profile({}, missingParameter);
    personality_insights.profile(null, missingParameter);
    personality_insights.profile(undefined, missingParameter);
  });

  it('should generate a valid payload with text', function() {
      var req = personality_insights.profile(service_request, noop);
      var body = new Buffer(req.body).toString('ascii');
      assert.equal(req.uri.href, service.url + service_path);
      assert.equal(body, '"' + service_request.text + '"');
      assert.equal(req.method, 'POST');
      assert.equal(req.headers['Content-type'], 'text/plain');
  });

  it('should generate a valid payload with contentItems', function() {
      var req = personality_insights.profile(payload, noop);
      var body = new Buffer(req.body).toString('ascii');
      assert.equal(req.uri.href, service.url + service_path);
      assert.equal(body, JSON.stringify(payload));
      assert.equal(req.method, 'POST');
      assert.equal(req.headers['Content-type'], 'application/json');
  });

  it('should generate a valid payload with html', function() {
      var html_req = { text:'<div>test</div>' };
      var req = personality_insights.profile(html_req, noop);
      var body = new Buffer(req.body).toString('ascii');
      assert.equal(req.uri.href, service.url + service_path);
      assert.equal(body, JSON.stringify(html_req.text));
      assert.equal(req.method, 'POST');
      assert.equal(req.headers['Content-type'], 'text/html');
  });

  it('should generate a valid payload with include_raw, language and accept_language', function() {
    var params = extend({ language: 'es', accept_language: 'es', include_raw: true}, payload);

      var req = personality_insights.profile(params, noop);
      var body = new Buffer(req.body).toString('ascii');
      assert.equal(req.uri.href, service.url + service_path + '?include_raw=true');
      assert.equal(body, JSON.stringify(payload));
      assert.equal(req.method, 'POST');
      assert.equal(req.headers['Content-type'], 'application/json');
      assert.equal(req.headers['Content-language'], 'es');
      assert.equal(req.headers['Accept-language'], 'es');
  });

  it('should format the response', function(done) {
    personality_insights.profile(service_request, function(err, response) {
      if (err)
        done(err);
      else {
        assert.equal(JSON.stringify(response), JSON.stringify(service_response));
        done();
      }
    });
  });
{'fraction_non_alphanumeric': 0.1584749059784723, 'fraction_numerical': 0.003371806510180262, 'mean_word_length': 3.5768545994065284, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '393533', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2300, 'n_words': 472}