From bb75f42e4654f5a157c7766de47c589c29aad24c Mon Sep 17 00:00:00 2001 From: Sebastien Robert Date: Wed, 28 Sep 2022 16:51:07 +0200 Subject: [PATCH 1/2] Keywords have to be an array of string --- modules/beopBidAdapter.js | 16 +++++++++- test/spec/modules/beopBidAdapter_spec.js | 39 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/modules/beopBidAdapter.js b/modules/beopBidAdapter.js index f8a53a293de..982a0ee5777 100644 --- a/modules/beopBidAdapter.js +++ b/modules/beopBidAdapter.js @@ -40,6 +40,19 @@ 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 { + if (kwdsFromRequest.indexOf(",") != -1) { + keywords = kwdsFromRequest.split(","); + } else { + keywords.push(kwdsFromRequest); + } + } + } const payloadObject = { at: new Date().toString(), nid: firstSlot.nid, @@ -47,12 +60,13 @@ export const spec = { 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', diff --git a/test/spec/modules/beopBidAdapter_spec.js b/test/spec/modules/beopBidAdapter_spec.js index c6001c3ba2e..5de75c470b2 100644 --- a/test/spec/modules/beopBidAdapter_spec.js +++ b/test/spec/modules/beopBidAdapter_spec.js @@ -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"]); }); From abcae5a7bbfd349c73a7e6bc112785227d676ed5 Mon Sep 17 00:00:00 2001 From: Sebastien Robert Date: Fri, 7 Oct 2022 09:05:52 +0200 Subject: [PATCH 2/2] Last check if isStr --- modules/beopBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/beopBidAdapter.js b/modules/beopBidAdapter.js index 982a0ee5777..277ee0fb54c 100644 --- a/modules/beopBidAdapter.js +++ b/modules/beopBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isArray, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js'; +import { deepAccess, isArray, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter, isStr } from '../src/utils.js'; import { getRefererInfo } from '../src/refererDetection.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; @@ -45,7 +45,7 @@ export const spec = { if (kwdsFromRequest) { if (isArray(kwdsFromRequest)) { keywords = kwdsFromRequest; - } else { + } else if (isStr(kwdsFromRequest)) { if (kwdsFromRequest.indexOf(",") != -1) { keywords = kwdsFromRequest.split(","); } else {