Socialify

Folder ..

Viewing fake.unit.js
50 lines (42 loc) • 1.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
if (typeof module !== 'undefined') {
  var assert = require('assert');
  var sinon = require('sinon');
  var blaver = require('../index');
}

describe("fake.js", function () {
  describe("fake()", function () {
    it("replaces a token with a random value for a method with no parameters", function () {
      var name = blaver.fake('{{phone.phoneNumber}}');
      assert.ok(name.match(/\d/));
    });

    it("replaces multiple tokens with random values for methods with no parameters", function () {
      var name = blaver.fake('{{helpers.randomize}}{{helpers.randomize}}{{helpers.randomize}}');
      assert.ok(name.match(/[abc]{3}/));
    });

    it("replaces a token with a random value for a methods with a simple parameter", function () {
      var arr = ["one", "two", "three"];
      var random = blaver.fake('{{helpers.slugify("Will This Work")}}');
      assert.ok(random === "Will-This-Work");
    });

    it("replaces a token with a random value for a method with an array parameter", function () {
      var arr = ["one", "two", "three"];
      var random = blaver.fake('{{helpers.randomize(["one", "two", "three"])}}');
      assert.ok(arr.indexOf(random) > -1);
    });

    it("does not allow undefined parameters", function () {
      assert.throws(function () {
        blaver.fake()
      }, Error);
    });

    it("does not allow invalid module name", function () {
      assert.throws(function () {
        blaver.fake('{{foo.bar}}')
      }, Error);
    });

    it("does not allow invalid method name", function () {
      assert.throws(function () {
        blaver.fake('{{address.foo}}')
      }, Error);
    });


  });
});