From e64baaed743eca169e1b2c3036528466a7a3409f Mon Sep 17 00:00:00 2001 From: Ariel <155993606+arielmtk@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:20:14 -0300 Subject: [PATCH] Fixes tests --- modules/mobianRtdProvider.js | 27 +-------------------- test/spec/modules/mobianRtdProvider_spec.js | 19 +++++---------- 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/modules/mobianRtdProvider.js b/modules/mobianRtdProvider.js index 1b16f6ea6ca..e5772d489e2 100644 --- a/modules/mobianRtdProvider.js +++ b/modules/mobianRtdProvider.js @@ -84,32 +84,7 @@ export const getContextData = makeMemoizedFetch(); const entriesToObjectReducer = (acc, [key, value]) => ({ ...acc, [key]: value }); -/** - * @param {MobianConfig} config - * @param {MobianContextData} contextData - * @returns {Object} - */ -export function contextDataToKeyValues(config, contextData) { - const { prefix } = config; - const keyValues = CONTEXT_KEYS.reduce((acc, key) => { - const newAcc = { ...acc }; - if (key === AP_VALUES) { - AP_KEYS.forEach((apKey) => { - if (!contextData[key]?.[apKey]?.length) return; - newAcc[`${prefix}_ap_${apKey}`] = contextData[key][apKey] - }); - return newAcc; - } - - if (contextData[key]?.length) { - newAcc[`${prefix}_${key}`] = contextData[key]; - } - return newAcc; - }, {}); - return keyValues; -} - -function makeContextDataToKeyValuesReducer(config) { +export function makeContextDataToKeyValuesReducer(config) { const { prefix } = config; return function contextDataToKeyValuesReducer(keyValues, [key, value]) { if (key === AP_VALUES) { diff --git a/test/spec/modules/mobianRtdProvider_spec.js b/test/spec/modules/mobianRtdProvider_spec.js index 9d52cd1c128..5e45d427c7a 100644 --- a/test/spec/modules/mobianRtdProvider_spec.js +++ b/test/spec/modules/mobianRtdProvider_spec.js @@ -4,11 +4,11 @@ import * as ajax from 'src/ajax.js'; import * as gptUtils from 'libraries/gptUtils/gptUtils.js'; import { CONTEXT_KEYS, - contextDataToKeyValues, extendBidRequestConfig, fetchContextData, getConfig, getContextData, + makeContextDataToKeyValuesReducer, makeDataFromResponse, setTargeting, } from 'modules/mobianRtdProvider.js'; @@ -259,26 +259,19 @@ describe('Mobian RTD Submodule', function () { }); }); - describe('contextDataToKeyValues', function () { + describe('makeContextDataToKeyValuesReducer', function () { it('should format context data to key-value pairs', function () { const config = getConfig({ name: 'mobianBrandSafety', params: { - prefix: 'mobiantest', + prefix: 'mobian', publisherTargeting: true, advertiserTargeting: true, } }); - const mockKeyValues = { - 'mobiantest_ap_a1': [2313, 12], - 'mobiantest_ap_p0': [1231231, 212], - 'mobiantest_ap_p1': [231, 419], - 'mobiantest_emotions': ['affection'], - 'mobiantest_risk': 'low', - 'mobiantest_sentiment': 'positive', - }; - const keyValues = contextDataToKeyValues(config, mockContextData); - expect(keyValues).to.deep.equal(mockKeyValues); + const keyValues = Object.entries(mockContextData).reduce(makeContextDataToKeyValuesReducer(config), []); + const keyValuesObject = Object.fromEntries(keyValues); + expect(keyValuesObject).to.deep.equal(mockKeyValues); }); }); });