<commit_before>var assert = require('proclaim');
var JSON2 = require('JSON2');

var Keen = require('../../../lib/browser');
var config = require('../helpers/client-config');

// Keen.debug = true;

describe('.recordEvent(s) methods (browser)', function() {

  describe('.recordEvent', function() {

    beforeEach(function() {
      this.client = new Keen({
        projectId: config.projectId,
        writeKey: config.writeKey,
        requestType: 'xhr',
        host: config.host,
        protocol: config.protocol
      });
      this.postUrl = this.client.url(this.client.writePath() + '/' + encodeURIComponent(config.collection));

      // Hack for IE9 request shim
      if ('undefined' !== typeof document && document.all) {
        this.postUrl = this.postUrl.replace('https', 'http');
      }
    });

    it('should not send events if set to \'false\'', function(){
      Keen.enabled = false;
      this.client.recordEvent('not-going', { test: 'data' }, function(err, res){
        assert.isNotNull(err);
        assert.isNull(res);
      });
      Keen.enabled = true;
    });

    it('should return an error message if event collection is omitted', function(){
      this.client.recordEvent(null, { test: 'data' }, function(err, res){
        assert.isNotNull(err);
        assert.isNull(res);
      });
    });

    describe('via XHR/CORS (if supported)', function(){

      it('should send a POST request to the API using XHR', function() {
        var count = 0;
        var headers = {
          'Content-Type': 'application/json'
        };
        this.client.recordEvent(config.collection + '_succeed', config.properties, function(err, res){
          count++;
          assert.isNull(err);
          assert.isNotNull(res);
          assert.equal(count, 1);<commit_msg>Log out error to investigate travis failure<commit_after>var assert = require('proclaim');
var JSON2 = require('JSON2');

var Keen = require('../../../lib/browser');
var config = require('../helpers/client-config');

// Keen.debug = true;

describe('.recordEvent(s) methods (browser)', function() {

  describe('.recordEvent', function() {

    beforeEach(function() {
      this.client = new Keen({
        projectId: config.projectId,
        writeKey: config.writeKey,
        requestType: 'xhr',
        host: config.host,
        protocol: config.protocol
      });
      this.postUrl = this.client.url(this.client.writePath() + '/' + encodeURIComponent(config.collection));

      // Hack for IE9 request shim
      if ('undefined' !== typeof document && document.all) {
        this.postUrl = this.postUrl.replace('https', 'http');
      }
    });

    it('should not send events if set to \'false\'', function(){
      Keen.enabled = false;
      this.client.recordEvent('not-going', { test: 'data' }, function(err, res){
        assert.isNotNull(err);
        assert.isNull(res);
      });
      Keen.enabled = true;
    });

    it('should return an error message if event collection is omitted', function(){
      this.client.recordEvent(null, { test: 'data' }, function(err, res){
        assert.isNotNull(err);
        assert.isNull(res);
      });
    });

    describe('via XHR/CORS (if supported)', function(){

      it('should send a POST request to the API using XHR', function() {
        var count = 0;
        var headers = {
          'Content-Type': 'application/json'
        };
        this.client.recordEvent(config.collection + '_succeed', config.properties, function(err, res){
          count++;
          console.log(err, res);
          assert.isNull(err);
          assert.isNotNull(res);
          assert.equal(count, 1);
{'fraction_non_alphanumeric': 0.15711543734576364, 'fraction_numerical': 0.002741979709350151, 'mean_word_length': 2.583497053045187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '927186', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1039, 'n_words': 249}