<commit_before>describe('Client', function() {
  var Client   = require('client'),
      Tracking = require('tracking'),
      Tracker  = Tracking.Tracker,
      Promise  = window.Promise || require('../vendor/native-promise-only'),
      sandbox  = sinon.sandbox.create(),
      origin   = 'https://foo.zendesk.com',
      appGuid  = 'ABC123',
      version  = require('version'),
      subject,
      source,
      trackerStub,
      callback;

  beforeEach(function() {
    trackerStub = sandbox.stub(Tracker.prototype, 'setup');
    sandbox.stub(window, 'addEventListener');
    sandbox.stub(window, 'postMessage');
    source = { postMessage: sandbox.stub() };
    subject = new Client({ origin: origin, appGuid: appGuid, source: source });
  });

  afterEach(function() {
    sandbox.restore();
  });

  function triggerEvent(client, name, data) {
    var evt = {
      origin: client._origin,
      source: client._source,
      data: {
        key: 'zaf.' + name,
        message: data,
        instanceGuid: client._instanceGuid
      }
    };

    window.addEventListener.callArgWith(1, evt);
  }

  describe('isOriginValid', function() {
    it('instantiates the client when the domain is valid', function() {
      var validDomains = [
        'http://127.0.0.1',
        'http://localhost',
        'http://localhost:1234',
        'https://localhost:1234',
        'https://sub1.zendesk.com',
        'https://sub-1.zendesk.com',
        'https://sub_1.zendesk.com',
        'https://sub1.zd-staging.com',
        'https://sub1.zendesk-staging.com',
        'https://sub1.zd-master.com',
        'https://dashboard.zopim.com',
        'https://hoanglocal.zopim.com:8080',
        'https://dashboard.zopim.org'
      ];

      validDomains.forEach(function(domain) {
        var validOriginClient = new Client({
          origin: domain,
          appGuid: 'appGuid',
          source: source
        });

        expect(validOriginClient).to.exist;
      });
    });

    it('throws when domain is invalid', function() {
      var invalidDomains = [
        'https://localhost.com',
        'http://fakelocalhost',
        'http://fakelocalhost:1234',
        'https://sub1.fakezendesk.com',
        'https://sub1.fakezd-staging.com',
        'https://sub1.fakezendesk-staging.com',
        'https://sub1.fakezd-master.com',
        'https://dashboard.fakezopim.com',
        'https://dashboard.fakezopim.org'
      ];

      invalidDomains.forEach(function(domain) {
        expect(function() {
          new Client({
            origin: domain,
            appGuid: 'appGuid',
            source: source
          });
        }).to.throw(Error);<commit_msg>Fix test<commit_after>describe('Client', function() {
  var Client   = require('client'),
      Tracking = require('tracking'),
      Tracker  = Tracking.Tracker,
      Promise  = window.Promise || require('../vendor/native-promise-only'),
      sandbox  = sinon.sandbox.create(),
      origin   = 'https://foo.zendesk.com',
      appGuid  = 'ABC123',
      version  = require('version'),
      subject,
      source,
      trackerStub,
      callback;

  beforeEach(function() {
    trackerStub = sandbox.stub(Tracker.prototype, 'setup');
    sandbox.stub(window, 'addEventListener');
    sandbox.stub(window, 'postMessage');
    source = { postMessage: sandbox.stub() };
    subject = new Client({ origin: origin, appGuid: appGuid, source: source });
  });

  afterEach(function() {
    sandbox.restore();
  });

  function triggerEvent(client, name, data) {
    var evt = {
      origin: client._origin,
      source: client._source,
      data: {
        key: 'zaf.' + name,
        message: data,
        instanceGuid: client._instanceGuid
      }
    };

    window.addEventListener.callArgWith(1, evt);
  }

  describe('isOriginValid', function() {
    beforeEach(function() {
      sandbox.stub(console, 'error');
    });

    it('instantiates the client when the domain is valid', function() {
      var validDomains = [
        'http://127.0.0.1',
        'http://localhost',
        'http://localhost:1234',
        'https://localhost:1234',
        'https://sub1.zendesk.com',
        'https://sub-1.zendesk.com',
        'https://sub_1.zendesk.com',
        'https://sub1.zd-staging.com',
        'https://sub1.zendesk-staging.com',
        'https://sub1.zd-master.com',
        'https://dashboard.zopim.com',
        'https://hoanglocal.zopim.com:8080',
        'https://dashboard.zopim.org'
      ];

      validDomains.forEach(function(domain) {
        var validOriginClient = new Client({
          origin: domain,
          appGuid: 'appGuid',
          source: source
        });

        expect(validOriginClient).to.exist;
      });
    });

    it('throws when domain is invalid', function() {
      var invalidDomains = [
        'https://localhost.com',
        'http://fakelocalhost',
        'http://fakelocalhost:1234',
        'https://sub1.fakezendesk.com',
        'https://sub1.fakezd-staging.com',
        'https://sub1.fakezendesk-staging.com',
        'https://sub1.fakezd-master.com',
        'https://dashboard.fakezopim.com',
        'https://dashboard.fakezopim.org'
      ];

      invalidDomains.forEach(function(domain) {
        new Client({
          origin: domain,
          appGuid: 'appGuid',
          source: source
        });
        expect(console.error).to.have.been.calledWith('Invalid domain: ' + domain);
{'fraction_non_alphanumeric': 0.159550975340449, 'fraction_numerical': 0.013249907986750091, 'mean_word_length': 2.242840095465394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 36, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2182328', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1673, 'n_words': 268}