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

Improving kargo unit tests for currency handling #3106

Merged
merged 1 commit into from
Sep 24, 2018
Merged
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
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