-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP unit tests for instream tracking
- Loading branch information
Showing
3 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { expect } from 'chai'; | ||
import { trackInstreamDeliveredImpressions } from 'src/instreamTracking.js'; | ||
import { config } from '../../src/config.js'; | ||
|
||
const BIDDER_CODE = 'sampleBidder'; | ||
let sandbox; | ||
|
||
function mockPerformanceApi() { | ||
window.performance = window.performance || {}; | ||
sandbox.stub(window, 'performance').callsFake(() => { | ||
return { | ||
'getEntriesByType': () => undefined | ||
} | ||
}); | ||
} | ||
|
||
function enableInstreamTracking() { | ||
sandbox.stub(config, 'getConfig').callsFake(() => { | ||
return { | ||
'instreamTracking': { | ||
enabled: true, | ||
maxWindow: 1000 * 60, | ||
pollingFreq: 500 | ||
} | ||
} | ||
}); | ||
} | ||
|
||
describe('instream tracking', function () { | ||
beforeEach(function () { | ||
sandbox = sinon.sandbox.create(); | ||
}) | ||
|
||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('gaurd checks', function () { | ||
it('skip if tracking not enable', function () { | ||
expect(trackInstreamDeliveredImpressions([], [])).to.be.equal(false); | ||
}); | ||
|
||
it('run only if instream ad units are present', function () { | ||
enableInstreamTracking(); | ||
mockPerformanceApi(); | ||
expect(trackInstreamDeliveredImpressions([], [])).to.be.equal(false); | ||
}); | ||
|
||
it('skip if instream bids not present', function () { | ||
enableInstreamTracking(); | ||
mockPerformanceApi(); | ||
|
||
const adUnits = [{ | ||
code: 'banner', | ||
bids: [{ | ||
bidder: BIDDER_CODE, | ||
params: {placementId: 'id'} | ||
}] | ||
}]; | ||
const bidRecieved = [{ | ||
'bidderCode': BIDDER_CODE, | ||
'width': 300, | ||
'height': 250, | ||
'statusMessage': 'Bid available', | ||
'adId': '20372a557635064', | ||
'requestId': '16ee6b19daeb431', | ||
'mediaType': 'banner', | ||
'source': 'client', | ||
'no_bid': false, | ||
'cpm': 1.1495, | ||
'ad': "<div id=''></div>", | ||
'ttl': 180, | ||
'creativeId': '7C19U58N2DL-120340442-30-11', | ||
'netRevenue': true, | ||
'currency': 'USD', | ||
}] | ||
expect(trackInstreamDeliveredImpressions(adUnits, bidRecieved)).to.be.equal(false); | ||
}); | ||
}); | ||
}); |