Skip to content

Commit

Permalink
Unit test fixes (prebid#2301)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiminpanchal27 authored and dluxemburg committed Jul 17, 2018
1 parent e104731 commit 9f04e78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
22 changes: 11 additions & 11 deletions test/spec/modules/audienceNetworkBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { expect } from 'chai';

import { spec } from 'modules/audienceNetworkBidAdapter';
import * as utils from 'src/utils';

const {
code,
Expand Down Expand Up @@ -117,6 +118,15 @@ describe('AudienceNetwork adapter', () => {
});

describe('buildRequests', () => {
let isSafariBrowserStub;
before(() => {
isSafariBrowserStub = sinon.stub(utils, 'isSafariBrowser');
});

after(() => {
isSafariBrowserStub.restore();
});

it('can build URL for IAB unit', () => {
expect(buildRequests([{
bidder,
Expand Down Expand Up @@ -191,23 +201,13 @@ describe('AudienceNetwork adapter', () => {
});

it('can build URL on Safari that includes a cachebuster param', () => {
const { userAgent } = navigator;
Object.defineProperty(navigator, 'userAgent', {
value: 'safari',
writable: true
});

isSafariBrowserStub.returns(true);
expect(buildRequests([{
bidder,
bidId: requestId,
sizes: [[300, 250]],
params: { placementId }
}])[0].data).to.contain('&cb=');

Object.defineProperty(navigator, 'userAgent', {
value: userAgent,
writable: false
});
});
});

Expand Down
15 changes: 9 additions & 6 deletions test/spec/modules/eplanningAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import eplAnalyticsAdapter from 'modules/eplanningAnalyticsAdapter';
import includes from 'core-js/library/fn/array/includes';
import { expect } from 'chai';
import {parse as parseURL} from 'src/url';
let adaptermanager = require('src/adaptermanager');
let events = require('src/events');
let constants = require('src/constants.json');
Expand Down Expand Up @@ -112,16 +114,17 @@ describe('eplanning analytics adapter', () => {
events.emit(constants.EVENTS.AUCTION_END, {auctionId: pauctionId});

// Step 7: Find the request data sent (filtering other hosts)
requests = requests.filter(req => req.url.includes(initOptions.host));

requests = requests.filter(req => {
return req.url.indexOf(initOptions.host) > -1;
});
expect(requests.length).to.equal(1);

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

let info = requests[0].url;
let purl = new URL(info);
let eplData = JSON.parse(decodeURIComponent(purl.searchParams.get('d')));
let purl = parseURL(info);
let eplData = JSON.parse(decodeURIComponent(purl.search.d));

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

0 comments on commit 9f04e78

Please sign in to comment.