Skip to content

Commit

Permalink
Fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arielmtk committed Dec 18, 2024
1 parent 4eee43b commit e64baae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 39 deletions.
27 changes: 1 addition & 26 deletions modules/mobianRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 6 additions & 13 deletions test/spec/modules/mobianRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit e64baae

Please sign in to comment.