Skip to content

Commit 8aec362

Browse files
Unit test fixes (#2301)
1 parent 4fbf447 commit 8aec362

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

test/spec/modules/audienceNetworkBidAdapter_spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { expect } from 'chai';
55

66
import { spec } from 'modules/audienceNetworkBidAdapter';
7+
import * as utils from 'src/utils';
78

89
const {
910
code,
@@ -117,6 +118,15 @@ describe('AudienceNetwork adapter', () => {
117118
});
118119

119120
describe('buildRequests', () => {
121+
let isSafariBrowserStub;
122+
before(() => {
123+
isSafariBrowserStub = sinon.stub(utils, 'isSafariBrowser');
124+
});
125+
126+
after(() => {
127+
isSafariBrowserStub.restore();
128+
});
129+
120130
it('can build URL for IAB unit', () => {
121131
expect(buildRequests([{
122132
bidder,
@@ -191,23 +201,13 @@ describe('AudienceNetwork adapter', () => {
191201
});
192202

193203
it('can build URL on Safari that includes a cachebuster param', () => {
194-
const { userAgent } = navigator;
195-
Object.defineProperty(navigator, 'userAgent', {
196-
value: 'safari',
197-
writable: true
198-
});
199-
204+
isSafariBrowserStub.returns(true);
200205
expect(buildRequests([{
201206
bidder,
202207
bidId: requestId,
203208
sizes: [[300, 250]],
204209
params: { placementId }
205210
}])[0].data).to.contain('&cb=');
206-
207-
Object.defineProperty(navigator, 'userAgent', {
208-
value: userAgent,
209-
writable: false
210-
});
211211
});
212212
});
213213

test/spec/modules/eplanningAnalyticsAdapter_spec.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import eplAnalyticsAdapter from 'modules/eplanningAnalyticsAdapter';
2+
import includes from 'core-js/library/fn/array/includes';
23
import { expect } from 'chai';
4+
import {parse as parseURL} from 'src/url';
35
let adaptermanager = require('src/adaptermanager');
46
let events = require('src/events');
57
let constants = require('src/constants.json');
@@ -112,16 +114,17 @@ describe('eplanning analytics adapter', () => {
112114
events.emit(constants.EVENTS.AUCTION_END, {auctionId: pauctionId});
113115

114116
// Step 7: Find the request data sent (filtering other hosts)
115-
requests = requests.filter(req => req.url.includes(initOptions.host));
116-
117+
requests = requests.filter(req => {
118+
return req.url.indexOf(initOptions.host) > -1;
119+
});
117120
expect(requests.length).to.equal(1);
118121

119-
expect(requests[0].url.includes(initOptions.host + initOptions.ci));
120-
expect(requests[0].url.includes('https://ads.ar.e-planning.net/hba/1/12345?d='));
122+
expect(includes([initOptions.host + initOptions.ci], requests[0].url));
123+
expect(includes(['https://ads.ar.e-planning.net/hba/1/12345?d='], requests[0].url));
121124

122125
let info = requests[0].url;
123-
let purl = new URL(info);
124-
let eplData = JSON.parse(decodeURIComponent(purl.searchParams.get('d')));
126+
let purl = parseURL(info);
127+
let eplData = JSON.parse(decodeURIComponent(purl.search.d));
125128

126129
// Step 8 check that 6 events were sent
127130
expect(eplData.length).to.equal(6);

0 commit comments

Comments
 (0)