Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cleanup #3238

Merged
merged 3 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions modules/justpremiumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ export const spec = {

}

export let pixel = {
fire(url) {
let img = document.createElement('img')
img.src = url
img.id = 'jp-pixel-track'
img.style.cssText = 'display:none !important;'
document.body.appendChild(img)
}
};

function track (data, payload, type) {
let pubUrl = ''

Expand All @@ -147,11 +157,7 @@ ru=${encodeURIComponent(pubUrl)}&tt=&siw=&sh=${payload.sh}&sw=${payload.sw}&wh=$
sd=&_c=&et=&aid=&said=&ei=&fc=&sp=&at=bidder&cid=&ist=&mg=&dl=&dlt=&ev=&vt=&zid=${payload.id}&dr=${duration}&di=&pr=&
cw=&ch=&nt=&st=&jp=${encodeURIComponent(JSON.stringify(jp))}&ty=${type}`

let img = document.createElement('img')
img.src = pixelUrl
img.id = 'jp-pixel-track'
img.style.cssText = 'display:none !important;'
document.body.appendChild(img)
pixel.fire(pixelUrl);
}

function findBid (params, bids) {
Expand Down
20 changes: 17 additions & 3 deletions test/spec/modules/justpremiumBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { expect } from 'chai'
import { spec } from 'modules/justpremiumBidAdapter'
import { spec, pixel } from 'modules/justpremiumBidAdapter'

describe('justpremium adapter', function () {
let sandbox;
let pixelStub;

beforeEach(function() {
sandbox = sinon.sandbox.create();
pixelStub = sandbox.stub(pixel, 'fire');
});

afterEach(function() {
sandbox.restore();
});

let adUnits = [
{
adUnitCode: 'div-gpt-ad-1471513102552-1',
Expand Down Expand Up @@ -132,7 +144,7 @@ describe('justpremium adapter', function () {
})

describe('onTimeout', function () {
it('onTimeout', (done) => {
it('onTimeout', function(done) {
spec.onTimeout([{
'bidId': '25cd3ec3fd6ed7',
'bidder': 'justpremium',
Expand All @@ -153,7 +165,9 @@ describe('justpremium adapter', function () {
'zone': 21521
}],
'timeout': 1
}])
}]);

expect(pixelStub.calledOnce).to.equal(true);

done()
})
Expand Down
75 changes: 35 additions & 40 deletions test/spec/modules/uolBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { expect } from 'chai';
import { spec } from 'modules/uolBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';

const ENDPOINT = 'https://prebid.adilligo.com/v1/prebid.json';

describe('UOL Bid Adapter', function () {
const adapter = newBidder(spec);
let sandbox;
let queryStub;
let getCurrentPositionStub;

beforeEach(function() {
sandbox = sinon.sandbox.create();
});

afterEach(function() {
sandbox.restore();
});

describe('isBidRequestValid', function () {
let bid = {
Expand Down Expand Up @@ -88,31 +97,6 @@ describe('UOL Bid Adapter', function () {
});

describe('buildRequests', function () {
let queryPermission;
let cleanup = function() {
navigator.permissions.query = queryPermission;
};
let grantTriangulation = function() {
queryPermission = navigator.permissions.query;
navigator.permissions.query = function(data) {
return new Promise((resolve, reject) => {
resolve({state: 'granted'});
});
}
};
let denyTriangulation = function() {
queryPermission = navigator.permissions.query;
navigator.permissions.query = function(data) {
return new Promise((resolve, reject) => {
resolve({state: 'prompt'});
});
}
};
let removeQuerySupport = function() {
queryPermission = navigator.permissions.query;
navigator.permissions.query = undefined;
}

let bidRequests = [
{
'bidder': 'uol',
Expand Down Expand Up @@ -173,31 +157,42 @@ describe('UOL Bid Adapter', function () {
describe('buildRequest geolocation param', function () { // shall only be tested if browser engine supports geolocation and permissions API.
let geolocation = { lat: 4, long: 3, timestamp: 123121451 };

it('should contain user coordinates if (i) DNT is off; (ii) browser supports implementation; (iii) localStorage contains geolocation history', function () {
beforeEach(function() {
getCurrentPositionStub = sandbox.stub(navigator.geolocation, 'getCurrentPosition');
queryStub = sandbox.stub(navigator.permissions, 'query');
});

it('should not contain user coordinates if browser doesnt support permission query', function () {
localStorage.setItem('uolLocationTracker', JSON.stringify(geolocation));
grantTriangulation();
navigator.permissions.query = undefined;
const requestObject = spec.buildRequests(bidRequests, bidderRequest);
const payload = JSON.parse(requestObject.data);
expect(payload.geolocation).to.exist.and.not.be.empty;
cleanup();
expect(payload.geolocation).to.not.exist;
})

it('should not contain user coordinates if localStorage is empty', function () {
localStorage.removeItem('uolLocationTracker');
denyTriangulation();
it('should contain user coordinates if (i) DNT is off; (ii) browser supports implementation; (iii) localStorage contains geolocation history', function (done) {
localStorage.setItem('uolLocationTracker', JSON.stringify(geolocation));
queryStub.callsFake(function() {
return new Promise((resolve, reject) => {
resolve({state: 'granted'});
});
});
getCurrentPositionStub.callsFake(() => done());
const requestObject = spec.buildRequests(bidRequests, bidderRequest);
const payload = JSON.parse(requestObject.data);
expect(payload.geolocation).to.not.exist;
cleanup();
expect(payload.geolocation).to.exist.and.not.be.empty;
})

it('should not contain user coordinates if browser doesnt support permission query', function () {
localStorage.setItem('uolLocationTracker', JSON.stringify(geolocation));
removeQuerySupport();
it('should not contain user coordinates if localStorage is empty', function () {
localStorage.removeItem('uolLocationTracker');
queryStub.callsFake(function() {
return new Promise((resolve, reject) => {
resolve({state: 'prompt'});
});
});
const requestObject = spec.buildRequests(bidRequests, bidderRequest);
const payload = JSON.parse(requestObject.data);
expect(payload.geolocation).to.not.exist;
cleanup();
})
})
}
Expand Down