forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathairgridRtdProvider_spec.js
More file actions
93 lines (80 loc) · 2.78 KB
/
airgridRtdProvider_spec.js
File metadata and controls
93 lines (80 loc) · 2.78 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
import { config } from 'src/config.js';
import { deepAccess } from 'src/utils.js';
import * as agRTD from 'modules/airgridRtdProvider.js';
import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js';
const MATCHED_AUDIENCES = ['travel', 'sport'];
const RTD_CONFIG = {
auctionDelay: 250,
dataProviders: [
{
name: 'airgrid',
waitForIt: true,
params: {
apiKey: 'key123',
accountId: 'sdk',
publisherId: 'pub123',
bidders: ['pubmatic'],
},
},
],
};
describe('airgrid RTD Submodule', function () {
let getDataFromLocalStorageStub;
beforeEach(function () {
config.resetConfig();
getDataFromLocalStorageStub = sinon.stub(
agRTD.storage,
'getDataFromLocalStorage'
);
});
afterEach(function () {
getDataFromLocalStorageStub.restore();
});
describe('Initialise module', function () {
it('should initialise and return true', function () {
expect(agRTD.airgridSubmodule.init(RTD_CONFIG.dataProviders[0])).to.equal(
true
);
expect(loadExternalScriptStub.called).to.be.true
});
it('should attach script to DOM with correct config', function () {
agRTD.attachScriptTagToDOM(RTD_CONFIG);
expect(window.edktInitializor.invoked).to.be.true;
expect(window.edktInitializor.apiKey).to.equal(
RTD_CONFIG.dataProviders[0].params.apiKey
);
expect(window.edktInitializor.accountId).to.equal(
RTD_CONFIG.dataProviders[0].params.accountId
);
expect(window.edktInitializor.publisherId).to.equal(
RTD_CONFIG.dataProviders[0].params.publisherId
);
});
});
describe('Get matched audiences', function () {
it('gets matched audiences from local storage', function () {
getDataFromLocalStorageStub
.withArgs(agRTD.AG_AUDIENCE_IDS_KEY)
.returns(JSON.stringify(MATCHED_AUDIENCES));
const audiences = agRTD.getMatchedAudiencesFromStorage();
expect(audiences).to.have.members(MATCHED_AUDIENCES);
});
});
describe('Add matched audiences', function () {
it('sets bidder specific ORTB2 config', function () {
getDataFromLocalStorageStub
.withArgs(agRTD.AG_AUDIENCE_IDS_KEY)
.returns(JSON.stringify(MATCHED_AUDIENCES));
const audiences = agRTD.getMatchedAudiencesFromStorage();
const bidderOrtb2 = {};
agRTD.setAudiencesAsBidderOrtb2({ ortb2Fragments: { bidder: bidderOrtb2 } }, RTD_CONFIG.dataProviders[0], audiences);
const bidders = RTD_CONFIG.dataProviders[0].params.bidders
bidders.forEach((bidder) => {
const ortb2 = bidderOrtb2[bidder];
MATCHED_AUDIENCES.forEach((audience) => {
expect(ortb2.user.data[0].segment.find(segment => segment.id === audience)).to.exist;
})
});
});
});
});