Skip to content

Commit

Permalink
Cwire Bid Adapter: fix cwcreative parameter conversion (#8544)
Browse files Browse the repository at this point in the history
* Remove Id from cwcreative variables

* Change cwcreative from number to string as expected by the endpoint, update doc

* Add tests covering cwcreative type
  • Loading branch information
espen-j authored Jun 9, 2022
1 parent ee8ab7b commit 2eee11d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
10 changes: 8 additions & 2 deletions modules/cwireBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getValue,
isArray,
isNumber,
isStr,
logError,
logWarn,
parseSizesInput,
Expand Down Expand Up @@ -129,6 +130,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 @@ -177,7 +183,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 @@ -198,7 +204,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

0 comments on commit 2eee11d

Please sign in to comment.