Skip to content

Commit

Permalink
fix emily tests (prebid#1482)
Browse files Browse the repository at this point in the history
* fix emily tests

* really fix emily tests
  • Loading branch information
harpere authored and philipwatson committed Sep 18, 2017
1 parent ca07aa2 commit 80504d1
Showing 1 changed file with 45 additions and 47 deletions.
92 changes: 45 additions & 47 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ describe('the rubicon adapter', () => {
describe('user sync', () => {
let bids;
let server;
let clock;
let addBidResponseAction;
let rubiconAdapter;
const emilyUrl = 'https://tap-secure.rubiconproject.com/partner/scripts/rubicon/emily.html?rtb_ext=1';
Expand All @@ -1039,6 +1040,7 @@ describe('the rubicon adapter', () => {
bids = [];

server = sinon.fakeServer.create();
clock = sinon.useFakeTimers();

sandbox.stub(bidManager, 'addBidResponse', (elemId, bid) => {
bids.push(bid);
Expand All @@ -1048,8 +1050,6 @@ describe('the rubicon adapter', () => {
}
});

sinon.spy(window, 'setTimeout');

server.respondWith(JSON.stringify({
'status': 'ok',
'account_id': 14062,
Expand Down Expand Up @@ -1097,97 +1097,95 @@ describe('the rubicon adapter', () => {

afterEach(() => {
server.restore();
window.setTimeout.restore();
clock.restore();
window.pbjs.getConfig = origGetConfig;
});

it('should add the Emily iframe by default', (done) => {
it('should add the Emily iframe by default', () => {
sinon.stub(window.pbjs, 'getConfig', (key) => {
var config = { rubicon: {
userSync: {delay: 0} // Use 0 so we don't have to wait in our tests
userSync: {delay: 10}
}};
return config[key];
});

rubiconAdapter.callBids(bidderRequest);
server.respond();

setTimeout(() => {
let iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(1);
done();
}, 0);
// move clock to just before the usersync delay, should be no iframe
clock.tick(9);
let iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(0);
// move clock to usersync delay, iframe should have been added
clock.tick(1);
iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(1);
});

it('should add the Emily iframe when enabled', (done) => {
it('should add the Emily iframe when enabled', () => {
sinon.stub(window.pbjs, 'getConfig', (key) => {
var config = { rubicon: {
userSync: {enabled: true, delay: 0}
userSync: {enabled: true, delay: 20}
}};
return config[key];
});
rubiconAdapter.callBids(bidderRequest);

server.respond();
setTimeout(() => {
let iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(1);
done();
}, 0);

// move clock to just before the usersync delay, should be no iframe
clock.tick(19);
let iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(0);
// move clock to usersync delay, iframe should have been added
clock.tick(1);
iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(1);
});

it('should not fire more than once', (done) => {
it('should not fire more than once', () => {
sinon.stub(window.pbjs, 'getConfig', (key) => {
var config = { rubicon: {
userSync: {enabled: true, delay: 0}
userSync: {enabled: true, delay: 100}
}};
return config[key];
});
rubiconAdapter.callBids(bidderRequest);

server.respond();
// move clock to just before the usersync delay, should be no iframe
clock.tick(99);
let iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(0);
// move clock to usersync delay, iframe should have been added
clock.tick(1);
iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(1);

// Fire again
rubiconAdapter.callBids(bidderRequest);
server.respond();

setTimeout(() => {
let iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(1);
done();
}, 0);
// move clock to usersync delay, new iframe should not have been added
clock.tick(100);
iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(1);
});

it('should not add the Emily iframe when disabled', (done) => {
it('should not add the Emily iframe when disabled', () => {
sinon.stub(window.pbjs, 'getConfig', (key) => {
var config = { rubicon: {
userSync: {enabled: false, delay: 0}
userSync: {enabled: false, delay: 50}
}};
return config[key];
});
rubiconAdapter.callBids(bidderRequest);

server.respond();

setTimeout(() => {
let iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(0);
done();
}, 0);
});

it('should delay adding Emily based on config', () => {
sinon.stub(window.pbjs, 'getConfig', (key) => {
var config = { rubicon: {
userSync: {
enabled: true,
delay: 999
}
}};
return config[key];
});
rubiconAdapter.callBids(bidderRequest);
server.respond();
expect(window.setTimeout.getCall(0).args[1]).to.equal(999);
// move clock to usersync delay, iframe should have been added
clock.tick(50);
let iframes = document.querySelectorAll('[src="' + emilyUrl + '"]');
expect(iframes.length).to.equal(0);
});
});
});
Expand Down

0 comments on commit 80504d1

Please sign in to comment.