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

Keywords have to be an array of string #9

Merged
merged 2 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 15 additions & 1 deletion modules/beopBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,33 @@ export const spec = {
const pageUrl = getPageUrl(bidderRequest.refererInfo, window);
const gdpr = bidderRequest.gdprConsent;
const firstSlot = slots[0];
const kwdsFromRequest = bidderRequest.ortb2?.site?.keywords;
let keywords = [];
if (kwdsFromRequest) {
if (isArray(kwdsFromRequest)) {
keywords = kwdsFromRequest;
} else {
Copy link

@remitbri remitbri Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess for this whole block 48-54 (both the if and the else), you could paranoia-check isStr(kwdsFromRequest) first, so that you're not pushing functions or numbers or else to keywords

if (kwdsFromRequest.indexOf(",") != -1) {
keywords = kwdsFromRequest.split(",");
} else {
keywords.push(kwdsFromRequest);
}
}
}
const payloadObject = {
at: new Date().toString(),
nid: firstSlot.nid,
nptnid: firstSlot.nptnid,
pid: firstSlot.pid,
url: pageUrl,
lang: (window.navigator.language || window.navigator.languages[0]),
kwds: bidderRequest.ortb2?.site?.keywords || [],
kwds: keywords,
dbg: false,
slts: slots,
is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'),
tc_string: (gdpr && gdpr.gdprApplies) ? gdpr.consentString : null,
};

const payloadString = JSON.stringify(payloadObject);
return {
method: 'POST',
Expand Down
39 changes: 39 additions & 0 deletions test/spec/modules/beopBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,43 @@ describe('BeOp Bid Adapter tests', () => {
expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('pid=5a8af500c9e77c00017e4cad');
});
});

describe("Ensure keywords is always array of string", function () {
let bidRequests = [];
bidRequests.push(validBid);

it("should work with keywords as an array", function () {
config.setConfig({
currency: { adServerCurrency: "USD" },
ortb: { site: { keywords: ["a", "b"] } },
});
const request = spec.buildRequests(bidRequests, {});
const payload = JSON.parse(request.data);
const url = request.url;
expect(payload.kwd).to.exist;
expect(payload.kwd).to.equal(["a", "b"]);
});

it("should work with keywords as a string", function () {
config.setConfig({
currency: { adServerCurrency: "USD" },
ortb: { site: { keywords: "list of keywords" } },
});
const request = spec.buildRequests(bidRequests, {});
const payload = JSON.parse(request.data);
const url = request.url;
expect(payload.kwd).to.exist;
expect(payload.kwd).to.equal(["list of keywords"]);
});

it("should work with keywords as a string containing a comma", function () {
config.setConfig({
currency: { adServerCurrency: "USD" },
ortb: { site: { keywords: "list, of, keywords" } },
});
const request = spec.buildRequests(bidRequests, {});
const payload = JSON.parse(request.data);
const url = request.url;
expect(payload.kwd).to.exist;
expect(payload.kwd).to.equal(["list", "of", "keywords"]);
});