forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patha1MediaRtdProvider_spec.js
More file actions
105 lines (95 loc) · 2.89 KB
/
a1MediaRtdProvider_spec.js
File metadata and controls
105 lines (95 loc) · 2.89 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
102
103
104
105
import { subModuleObj } from 'modules/a1MediaRtdProvider.js';
import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js';
import { A1_AUD_KEY, A1_SEG_KEY, getStorageData, storage } from '../../../modules/a1MediaRtdProvider.js';
import { expect } from 'chai';
const configWithParams = {
name: 'a1Media',
waitForIt: true,
params: {
tagId: 'lb4test.min.js',
},
};
const configWithoutParams = {
name: 'a1Media',
waitForIt: true,
params: {
},
};
const reqBidsConfigObj = {
ortb2Fragments: {
global: {}
}
};
const a1TestOrtbObj = {
user: {
data: [
{
name: 'a1mediagroup.com',
ext: {
segtax: 900
},
segment: [{id: 'test'}]
}
],
ext: {
eids: [
{
source: 'a1mediagroup.com',
uids: [
{
id: 'tester',
atype: 1
}
]
}
]
}
}
};
describe('a1MediaRtdProvider', function() {
describe('init', function() {
describe('initialize with expected params', function() {
it('successfully initialize with load script', function() {
expect(subModuleObj.init(configWithParams)).to.be.true;
expect(window.linkback.l).to.be.true;
expect(loadExternalScriptStub.called).to.be.true;
expect(loadExternalScriptStub.args[0][0]).to.deep.equal('https://linkback.contentsfeed.com/src/lb4test.min.js');
})
it('successfully initialize but script is already exist', function() {
const linkback = { l: true };
expect(subModuleObj.init(configWithParams)).to.be.true;
expect(loadExternalScriptStub.called).to.be.false;
})
});
describe('initialize without expected params', function() {
afterEach(function() {
storage.setCookie(A1_SEG_KEY, '', 0);
})
it('successfully initialize when publisher side segment is exist in cookie', function() {
storage.setCookie(A1_SEG_KEY, 'test');
expect(subModuleObj.init(configWithoutParams)).to.be.true;
expect(getStorageData(A1_SEG_KEY)).to.not.equal('');
})
it('fails to initialize when publisher side segment does not exist', function() {
expect(subModuleObj.init(configWithoutParams)).to.be.false;
expect(getStorageData(A1_SEG_KEY)).to.equal('');
})
})
});
describe('alterBidRequests', function() {
const callback = sinon.stub();
before(function() {
storage.setCookie(A1_SEG_KEY, 'test');
storage.setDataInLocalStorage(A1_AUD_KEY, 'tester');
})
after(function() {
storage.setCookie(A1_SEG_KEY, '', 0);
storage.removeDataFromLocalStorage(A1_AUD_KEY);
})
it('alterBidRequests', function() {
subModuleObj.getBidRequestData(reqBidsConfigObj, callback);
expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.include(a1TestOrtbObj);
expect(callback.calledOnce).to.be.true;
})
});
})