forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddefendBidAdapter_spec.js
More file actions
185 lines (159 loc) · 5.59 KB
/
addefendBidAdapter_spec.js
File metadata and controls
185 lines (159 loc) · 5.59 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { expect } from 'chai';
import { spec } from 'modules/addefendBidAdapter.js';
import { getGlobal } from '../../../src/prebidGlobal.js';
describe('addefendBidAdapter', () => {
const defaultBidRequest = {
bidId: 'd66fa86787e0b0ca900a96eacfd5f0bb',
auctionId: 'ccc4c7cdfe11cfbd74065e6dd28413d8',
transactionId: 'd58851660c0c4461e4aa06344fc9c0c6',
sizes: [[300, 250], [300, 600]],
params: {
pageId: 'stringid1',
placementId: 'stringid2'
}
};
const deepClone = function (val) {
return JSON.parse(JSON.stringify(val));
};
const buildRequest = (buildRequest, bidderRequest) => {
if (!Array.isArray(buildRequest)) {
buildRequest = [buildRequest];
}
return spec.buildRequests(buildRequest, {
...bidderRequest || {},
refererInfo: {
page: 'https://referer.example.com'
}
})[0];
};
describe('isBidRequestValid', () => {
it('should return true when required params found', () => {
const bidRequest = deepClone(defaultBidRequest);
expect(spec.isBidRequestValid(bidRequest)).to.equal(true);
});
it('pageId performs type checking', () => {
const bidRequest = deepClone(defaultBidRequest);
bidRequest.params.pageId = 1; // supposed to be a string
expect(spec.isBidRequestValid(bidRequest)).to.equal(false);
});
it('placementId performs type checking', () => {
const bidRequest = deepClone(defaultBidRequest);
bidRequest.params.placementId = 1; // supposed to be a string
expect(spec.isBidRequestValid(bidRequest)).to.equal(false);
});
it('should return false when required params are not passed', () => {
const bidRequest = deepClone(defaultBidRequest);
delete bidRequest.params;
expect(spec.isBidRequestValid(bidRequest)).to.equal(false);
});
});
describe('buildRequests', () => {
const bidRequest = deepClone(defaultBidRequest);
const request = buildRequest(bidRequest);
it('sends bid request to endpoint via https using post', () => {
expect(request.method).to.equal('POST');
expect(request.url.indexOf('https://')).to.equal(0);
expect(request.url).to.equal(`${spec.hostname}/bid`);
});
it('contains prebid version parameter', () => {
expect(request.data.v).to.equal(getGlobal().version);
});
it('contains correct referer', () => {
expect(request.data.referer).to.equal('https://referer.example.com');
});
it('contains auctionId', () => {
expect(request.data.auctionId).to.equal('ccc4c7cdfe11cfbd74065e6dd28413d8');
});
it('contains pageId', () => {
expect(request.data.pageId).to.equal('stringid1');
});
it('sends correct bid parameters', () => {
const bidRequest = deepClone(defaultBidRequest);
expect(request.data.bids).to.deep.equal([{
bidId: bidRequest.bidId,
placementId: bidRequest.params.placementId,
sizes: ['300x250', '300x600'],
transactionId: 'd58851660c0c4461e4aa06344fc9c0c6'
}]);
});
it('handles empty gdpr object', () => {
const bidRequest = deepClone(defaultBidRequest);
const request = buildRequest(bidRequest, {
gdprConsent: {}
});
expect(request.data.gdpr_consent).to.be.equal('');
});
it('handles non-existent gdpr object', () => {
const bidRequest = deepClone(defaultBidRequest);
const request = buildRequest(bidRequest, {
gdprConsent: null
});
expect(request.data.gdpr_consent).to.be.equal('');
});
it('handles properly filled gdpr string', () => {
const bidRequest = deepClone(defaultBidRequest);
const consentString = 'GDPR_CONSENT_STRING';
const request = buildRequest(bidRequest, {
gdprConsent: {
gdprApplies: true,
consentString: consentString
}
});
expect(request.data.gdpr_consent).to.be.equal(consentString);
});
});
describe('interpretResponse', () => {
it('should get correct bid response', () => {
const serverResponse = [
{
'width': 300,
'height': 250,
'creativeId': '29681110',
'ad': '<!-- Creative -->',
'cpm': 0.5,
'requestId': 'ccc4c7cdfe11cfbd74065e6dd28413d8',
'ttl': 120,
'netRevenue': true,
'currency': 'EUR',
'advertiserDomains': ['advertiser.example.com']
}
];
const expectedResponse = [
{
'requestId': 'ccc4c7cdfe11cfbd74065e6dd28413d8',
'cpm': 0.5,
'creativeId': '29681110',
'width': 300,
'height': 250,
'ttl': 120,
'currency': 'EUR',
'ad': '<!-- Creative -->',
'netRevenue': true,
'advertiserDomains': ['advertiser.example.com']
}
];
const result = spec.interpretResponse({ body: serverResponse });
expect(result.length).to.equal(expectedResponse.length);
Object.keys(expectedResponse[0]).forEach((key) => {
expect(result[0][key]).to.deep.equal(expectedResponse[0][key]);
});
});
it('handles incomplete server response', () => {
const serverResponse = [
{
'ad': '<!-- Creative -->',
'cpm': 0.5,
'requestId': 'ccc4c7cdfe11cfbd74065e6dd28413d8',
'ttl': 60
}
];
const result = spec.interpretResponse({ body: serverResponse });
expect(result.length).to.equal(0);
});
it('handles nobid responses', () => {
const serverResponse = [];
const result = spec.interpretResponse({ body: serverResponse });
expect(result.length).to.equal(0);
});
});
});