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

Cwire Bid Adapter: fix cwcreative parameter conversion #8544

Merged
merged 3 commits into from
Jun 9, 2022
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
10 changes: 8 additions & 2 deletions modules/cwireBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getValue,
isArray,
isNumber,
isStr,
logError,
logWarn,
parseSizesInput,
Expand Down Expand Up @@ -130,6 +131,11 @@ export const spec = {
isBidRequestValid: function(bid) {
bid.params = bid.params || {};

if (bid.params.cwcreative && !isStr(bid.params.cwcreative)) {
logError('cwcreative must be of type string!');
return false;
}

if (!bid.params.placementId || !isNumber(bid.params.placementId)) {
logError('placementId not provided or invalid');
return false;
Expand Down Expand Up @@ -178,7 +184,7 @@ export const spec = {

let refgroups = [];

const cwCreativeId = parseInt(getQueryVariable(CW_CREATIVE_QUERY), 10) || null;
const cwCreative = getQueryVariable(CW_CREATIVE_QUERY) || null;
const cwCreativeIdFromConfig = this.getFirstValueOrNull(slots, 'cwcreative');
const refGroupsFromConfig = this.getFirstValueOrNull(slots, 'refgroups');
const cwApiKeyFromConfig = this.getFirstValueOrNull(slots, 'cwapikey');
Expand All @@ -199,7 +205,7 @@ export const spec = {
const payload = {
cwid: localStorageCWID,
refgroups,
cwcreative: cwCreativeId || cwCreativeIdFromConfig,
cwcreative: cwCreative || cwCreativeIdFromConfig,
slots: slots,
cwapikey: cwApiKeyFromConfig,
httpRef: referer || '',
Expand Down
6 changes: 3 additions & 3 deletions modules/cwireBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Connects to C-WIRE demand source to fetch bids.

Below, the list of C-WIRE params and where they can be set.

| Param name | Global config | AdUnit config | Type | Required |
| ---------- | ------------- | ------------- | ---- | ---------|
| Param name | Global config | AdUnit config | Type | Required |
| ---------- | ------------- | ------------- |--------| ---------|
| pageId | | x | number | YES |
| placementId | | x | number | YES |
| refgroups | | x | string | NO |
| cwcreative | | x | integer | NO |
| cwcreative | | x | string | NO |
| cwapikey | | x | string | NO |


Expand Down
35 changes: 24 additions & 11 deletions test/spec/modules/cwireBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ describe('C-WIRE bid adapter', () => {
bid01.params.pageId = '3320';
expect(spec.isBidRequestValid(bid01)).to.equal(false);
});

it('should fail if cwcreative of type number', function () {
const bid01 = new BidRequestBuilder().withParams().build();
delete bid01.params.cwcreative;
bid01.params.cwcreative = 3320;
expect(spec.isBidRequestValid(bid01)).to.equal(false);
});

it('should pass with valid cwcreative of type string', function () {
const bid01 = new BidRequestBuilder().withParams().build();
bid01.params.cwcreative = 'i-am-a-string';
expect(spec.isBidRequestValid(bid01)).to.equal(true);
});
});

describe('C-WIRE - buildRequests()', function () {
Expand All @@ -131,7 +144,7 @@ describe('C-WIRE bid adapter', () => {
}
}
}).withParams({
cwcreative: 54321,
cwcreative: '54321',
cwapikey: 'xxx-xxx-yyy-zzz-uuid',
refgroups: 'group_1',
}).build();
Expand All @@ -144,7 +157,7 @@ describe('C-WIRE bid adapter', () => {
expect(requests.data.cwid).to.be.null;
expect(requests.data.cwid).to.be.null;
expect(requests.data.slots[0].sizes[0]).to.equal('1x1');
expect(requests.data.cwcreative).to.equal(54321);
expect(requests.data.cwcreative).to.equal('54321');
expect(requests.data.cwapikey).to.equal('xxx-xxx-yyy-zzz-uuid');
expect(requests.data.refgroups[0]).to.equal('group_1');
});
Expand All @@ -159,7 +172,7 @@ describe('C-WIRE bid adapter', () => {
}
}
}).withParams({
cwcreative: 1234,
cwcreative: '1234',
cwapikey: 'api_key_5',
refgroups: 'group_5',
}).build();
Expand All @@ -171,22 +184,22 @@ describe('C-WIRE bid adapter', () => {
expect(requests.data.slots.length).to.equal(2);
expect(requests.data.cwid).to.be.null;
expect(requests.data.cwid).to.be.null;
expect(requests.data.cwcreative).to.equal(1234);
expect(requests.data.cwcreative).to.equal('1234');
expect(requests.data.cwapikey).to.equal('api_key_5');
expect(requests.data.refgroups[0]).to.equal('group_5');
});

it('creates a valid request - read debug params from first bid, ignore second', function () {
const bid01 = new BidRequestBuilder()
.withParams({
cwcreative: 33,
cwcreative: '33',
cwapikey: 'api_key_33',
refgroups: 'group_33',
}).build();

const bid02 = new BidRequestBuilder()
.withParams({
cwcreative: 1234,
cwcreative: '1234',
cwapikey: 'api_key_5',
refgroups: 'group_5',
}).build();
Expand All @@ -198,15 +211,15 @@ describe('C-WIRE bid adapter', () => {
expect(requests.data.slots.length).to.equal(2);
expect(requests.data.cwid).to.be.null;
expect(requests.data.cwid).to.be.null;
expect(requests.data.cwcreative).to.equal(33);
expect(requests.data.cwcreative).to.equal('33');
expect(requests.data.cwapikey).to.equal('api_key_33');
expect(requests.data.refgroups[0]).to.equal('group_33');
});

it('creates a valid request - read debug params from 3 different slots', function () {
const bid01 = new BidRequestBuilder()
.withParams({
cwcreative: 33,
cwcreative: '33',
}).build();

const bid02 = new BidRequestBuilder()
Expand All @@ -225,7 +238,7 @@ describe('C-WIRE bid adapter', () => {
expect(requests.data.slots.length).to.equal(3);
expect(requests.data.cwid).to.be.null;
expect(requests.data.cwid).to.be.null;
expect(requests.data.cwcreative).to.equal(33);
expect(requests.data.cwcreative).to.equal('33');
expect(requests.data.cwapikey).to.equal('api_key_5');
expect(requests.data.refgroups[0]).to.equal('group_5');
});
Expand All @@ -244,7 +257,7 @@ describe('C-WIRE bid adapter', () => {
}
}
}).withParams({
cwcreative: 54321,
cwcreative: '54321',
cwapikey: 'xxx-xxx-yyy-zzz',
refgroups: 'group_1',
}).build();
Expand All @@ -257,7 +270,7 @@ describe('C-WIRE bid adapter', () => {
expect(requests.data.cwid).to.be.null;
expect(requests.data.cwid).to.be.null;
expect(requests.data.slots[0].sizes[0]).to.equal('1x1');
expect(requests.data.cwcreative).to.equal(654321);
expect(requests.data.cwcreative).to.equal('654321');
expect(requests.data.cwapikey).to.equal('xxx-xxx-yyy-zzz');
expect(requests.data.refgroups[0]).to.equal('group_2');
});
Expand Down