Socialify

Folder ..

Viewing company.unit.js
100 lines (84 loc) • 3.6 KB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
if (typeof module !== 'undefined') {
  var assert = require('assert');
  var sinon = require('sinon');
  var blaver = require('../index');
}

describe("company.js", function () {
  describe("companyName()", function () {

    it("sometimes returns three last names", function () {
      sinon.spy(blaver.name, 'lastName');
      sinon.stub(blaver.datatype, 'number').returns(2);
      var name = blaver.company.companyName();
      var parts = name.split(' ');

      assert.strictEqual(parts.length, 4); // account for word 'and'
      assert.ok(blaver.name.lastName.calledThrice);

      blaver.datatype.number.restore();
      blaver.name.lastName.restore();
    });

    it("sometimes returns two last names separated by a hyphen", function () {
      sinon.spy(blaver.name, 'lastName');
      sinon.stub(blaver.datatype, 'number').returns(1);
      var name = blaver.company.companyName();
      var parts = name.split('-');

      assert.ok(parts.length >= 2);
      assert.ok(blaver.name.lastName.calledTwice);

      blaver.datatype.number.restore();
      blaver.name.lastName.restore();
    });

    it("sometimes returns a last name with a company suffix", function () {
      sinon.spy(blaver.company, 'companySuffix');
      sinon.spy(blaver.name, 'lastName');
      sinon.stub(blaver.datatype, 'number').returns(0);
      var name = blaver.company.companyName();
      var parts = name.split(' ');

      assert.ok(parts.length >= 2);
      assert.ok(blaver.name.lastName.calledOnce);
      assert.ok(blaver.company.companySuffix.calledOnce);

      blaver.datatype.number.restore();
      blaver.name.lastName.restore();
      blaver.company.companySuffix.restore();
    });
  });

  describe("companySuffix()", function () {
    it("returns random value from company.suffixes array", function () {
      var suffix = blaver.company.companySuffix();
      assert.ok(blaver.company.suffixes().indexOf(suffix) !== -1);
    });
  });

  describe("catchPhrase()", function () {
    it("returns phrase comprising of a catch phrase adjective, descriptor, and noun", function () {
      sinon.spy(blaver.random, 'arrayElement');
      sinon.spy(blaver.company, 'catchPhraseAdjective');
      sinon.spy(blaver.company, 'catchPhraseDescriptor');
      sinon.spy(blaver.company, 'catchPhraseNoun');
      var phrase = blaver.company.catchPhrase();

      assert.ok(phrase.split(' ').length >= 3);
      assert.ok(blaver.random.arrayElement.calledThrice);
      assert.ok(blaver.company.catchPhraseAdjective.calledOnce);
      assert.ok(blaver.company.catchPhraseDescriptor.calledOnce);
      assert.ok(blaver.company.catchPhraseNoun.calledOnce);

      blaver.random.arrayElement.restore();
      blaver.company.catchPhraseAdjective.restore();
      blaver.company.catchPhraseDescriptor.restore();
      blaver.company.catchPhraseNoun.restore();
    });
  });

  describe("bs()", function () {
    it("returns phrase comprising of a BS buzz, adjective, and noun", function () {
      sinon.spy(blaver.random, 'arrayElement');
      sinon.spy(blaver.company, 'bsBuzz');
      sinon.spy(blaver.company, 'bsAdjective');
      sinon.spy(blaver.company, 'bsNoun');
      var bs = blaver.company.bs();

      assert.ok(typeof bs === 'string');
      assert.ok(blaver.random.arrayElement.calledThrice);
      assert.ok(blaver.company.bsBuzz.calledOnce);
      assert.ok(blaver.company.bsAdjective.calledOnce);
      assert.ok(blaver.company.bsNoun.calledOnce);

      blaver.random.arrayElement.restore();        
      blaver.company.bsBuzz.restore();
      blaver.company.bsAdjective.restore();
      blaver.company.bsNoun.restore();
    });
  });
});