forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappierBidAdapter_spec.js
More file actions
178 lines (151 loc) · 5.18 KB
/
appierBidAdapter_spec.js
File metadata and controls
178 lines (151 loc) · 5.18 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
import { expect } from 'chai';
import { spec, API_SERVERS_MAP, ADAPTER_VERSION } from 'modules/appierBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { config } from 'src/config.js';
describe('AppierAdapter', function () {
const adapter = newBidder(spec);
describe('inherited functions', function () {
it('exists and is a function', function () {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});
describe('isBidRequestValid', function () {
const bid = {
'bidder': 'appier',
'params': {
'hzid': 'abcd'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};
it('should return true when required params zoneId found', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});
it('should return false when required param zoneId is missing', function () {
const invalidBid = Object.assign({}, bid);
invalidBid.params = {};
expect(spec.isBidRequestValid(invalidBid)).to.equal(false);
});
it('should return false when required param zoneId has wrong type', function () {
const invalidBid = Object.assign({}, bid);
invalidBid.params = {
'hzid': null
};
expect(spec.isBidRequestValid(invalidBid)).to.equal(false);
});
});
describe('buildRequests', function() {
it('should return an empty list when there are no bid requests', function() {
const fakeBidRequests = [];
const fakeBidderRequest = {};
expect(spec.buildRequests(fakeBidRequests, fakeBidderRequest)).to.be.an('array').that.is.empty;
});
it('should generate a POST bid request with method, url, and data fields', function() {
const bid = {
'bidder': 'appier',
'params': {
'hzid': 'abcd'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};
const fakeBidRequests = [bid];
const fakeBidderRequest = {
refererInfo: {
legacy: {
'referer': 'fakeReferer',
'reachedTop': true,
'numIframes': 1,
'stack': []
}
}
};
const builtRequests = spec.buildRequests(fakeBidRequests, fakeBidderRequest);
expect(builtRequests.length).to.equal(1);
expect(builtRequests[0].method).to.equal('POST');
expect(builtRequests[0].url).match(/v1\/prebid\/bid/);
expect(builtRequests[0].data).deep.equal({
'bids': fakeBidRequests,
'refererInfo': fakeBidderRequest.refererInfo.legacy,
'version': ADAPTER_VERSION
});
});
});
describe('interpretResponse', function() {
const bid = {
'bidder': 'appier',
'params': {
'hzid': 'abcd'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};
const fakeBidRequests = [bid];
it('should return an empty aray to indicate no valid bids', function() {
const fakeServerResponse = {};
const bidResponses = spec.interpretResponse(fakeServerResponse, fakeBidRequests);
expect(bidResponses).is.an('array').that.is.empty;
});
it('should generate correct response array for bidder', function() {
const fakeBidResult = {
'requestId': '30b31c1838de1e',
'cpm': 0.0029346001,
'creativeId': 'Idl0P0d5S3Ca5kVWcia-wQ',
'width': 300,
'height': 250,
'currency': 'USD',
'netRevenue': true,
'ttl': 300,
'ad': '<div>fake html</div>',
'appierParams': {
'hzid': 'test_hzid'
}
};
const fakeServerResponse = {
headers: [],
body: [fakeBidResult]
};
const bidResponses = spec.interpretResponse(fakeServerResponse, fakeBidRequests);
expect(bidResponses).deep.equal([fakeBidResult]);
});
});
describe('getApiServer', function() {
it('should use the server specified by setConfig(appier.server)', function() {
config.setConfig({
'appier': {'server': 'fake_server'}
});
const server = spec.getApiServer();
expect(server).equals('fake_server');
});
it('should retrieve a farm specific hostname if server is not specpfied', function() {
config.setConfig({
'appier': {'farm': 'tw'}
});
const server = spec.getApiServer();
expect(server).equals(API_SERVERS_MAP['tw']);
});
it('if farm is not recognized, use the default farm', function() {
config.setConfig({
'appier': {'farm': 'no_this_farm'}
});
const server = spec.getApiServer();
expect(server).equals(API_SERVERS_MAP['default']);
});
it('if farm is not specified, use the default farm', function() {
config.setConfig({
'appier': {}
});
const server = spec.getApiServer();
expect(server).equals(API_SERVERS_MAP['default']);
});
});
});