Skip to content

Commit

Permalink
improving kargo unit tests for currency handling (prebid#3106)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelhorwitz authored and Pedro López Jiménez committed Mar 18, 2019
1 parent 94e3392 commit c4fac91
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ describe('kargo adapter tests', function () {
});

describe('build request', function() {
var bids, cookies = [], localStorageItems = [];
var bids, undefinedCurrency, noAdServerCurrency, cookies = [], localStorageItems = [];

beforeEach(function () {
undefinedCurrency = false;
noAdServerCurrency = false;
sandbox.stub(config, 'getConfig').callsFake(function(key) {
if (key === 'currency') {
return 'USD';
if (undefinedCurrency) {
return undefined;
}
if (noAdServerCurrency) {
return {};
}
return {adServerCurrency: 'USD'};
}
throw new Error(`Config stub incomplete! Missing key "${key}"`)
});
Expand Down Expand Up @@ -109,6 +117,16 @@ describe('kargo adapter tests', function () {
return sandbox.stub(localStorage, 'getItem').throws();
}

function simulateNoCurrencyObject() {
undefinedCurrency = true;
noAdServerCurrency = false;
}

function simulateNoAdServerCurrency() {
undefinedCurrency = false;
noAdServerCurrency = true;
}

function initializeKruxUser() {
setLocalStorageItem('kxkar_user', 'rsgr9pnij');
}
Expand Down Expand Up @@ -308,6 +326,24 @@ describe('kargo adapter tests', function () {
initializeInvalidKrgCrbType3();
testBuildRequests(getExpectedKrakenParams({crb: true}, undefined, getInvalidKrgCrbType3()));
});

it('handles a non-existant currency object on the config', function() {
simulateNoCurrencyObject();
initializeKruxUser();
initializeKruxSegments();
initializeKrgUid();
initializeKrgCrb();
testBuildRequests(getExpectedKrakenParams(undefined, undefined, getKrgCrb()));
});

it('handles no ad server currency being set on the currency object in the config', function() {
simulateNoAdServerCurrency();
initializeKruxUser();
initializeKruxSegments();
initializeKrgUid();
initializeKrgCrb();
testBuildRequests(getExpectedKrakenParams(undefined, undefined, getKrgCrb()));
});
});

describe('response handler', function() {
Expand Down

0 comments on commit c4fac91

Please sign in to comment.