-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
47 lines (38 loc) · 1.35 KB
/
test.js
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
var assert = require('assert');
var sinon = require('sinon');
var unique = require('./index.js');
var PluginApi = require('gardr-core-plugin').PluginApi;
function createContainer () {
var c = document.createElement('span');
c.id = 'gardr';
return c;
}
describe('unique-token-ext', function () {
var pluginApi, now, clock, params;
beforeEach(function () {
params = {
id: 'test123',
url: 'http://external.com/script.js?q=1&m=GARDR_UNIQUE_ID&m2=GARDR_UNIQUE_ID'
};
pluginApi = new PluginApi();
sinon.spy(pluginApi, 'on');
now = new Date().getTime();
clock = sinon.useFakeTimers(now);
});
afterEach(function () {
clock.restore();
});
it('should be a function', function () {
assert.equal(typeof unique, 'function');
});
it('should replace GARDR_UNIQUE_ID in the url with timestamp + id', function() {
unique(pluginApi);
pluginApi.trigger('params:parsed', params);
assert(params.url.indexOf('m=' + now + params.id) >= 0, 'Should contain timestamp + id');
});
it('should replace all occurrences of GARDR_UNIQUE_ID', function() {
unique(pluginApi);
pluginApi.trigger('params:parsed', params);
assert(params.url.indexOf('GARDR_UNIQUE_ID') == -1, 'Should not contain GARDR_UNIQUE_ID');
});
});