Skip to content

Commit

Permalink
resolved merge config issue (prebid#8791)
Browse files Browse the repository at this point in the history
Co-authored-by: pm-azhar-mulla <azhar@L1119.local>
  • Loading branch information
2 people authored and JacobKlein26 committed Feb 8, 2023
1 parent c748f22 commit edaa499
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,11 @@ export function newConfig() {
option = Object.assign({}, defaults[topic], option);
}

topicalConfig[topic] = config[topic] = option;
try {
topicalConfig[topic] = config[topic] = option;
} catch (e) {
logWarn(`Cannot set config for property ${topic} : `, e)
}
});

callSubscribers(topicalConfig);
Expand Down Expand Up @@ -525,11 +529,7 @@ export function newConfig() {
return;
}

const mergedConfig = Object.keys(obj).reduce((accum, key) => {
const prevConf = _getConfig()[key] || {};
accum[key] = mergeDeep(prevConf, obj[key]);
return accum;
}, {});
const mergedConfig = mergeDeep(_getConfig(), obj);

setConfig({ ...mergedConfig });
return mergedConfig;
Expand Down
4 changes: 4 additions & 0 deletions test/spec/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ describe('config API', function () {
}

setConfig({
bidderTimeout: 2000,
ortb2: {
user: {
data: [userObj1, userObj2]
Expand All @@ -609,6 +610,7 @@ describe('config API', function () {
});

const rtd = {
bidderTimeout: 3000,
ortb2: {
user: {
data: [userObj1]
Expand All @@ -623,11 +625,13 @@ describe('config API', function () {
mergeConfig(rtd);

let ortb2Config = getConfig('ortb2');
let bidderTimeout = getConfig('bidderTimeout');

expect(ortb2Config.user.data).to.deep.include.members([userObj1, userObj2]);
expect(ortb2Config.site.content.data).to.deep.include.members([siteObj1]);
expect(ortb2Config.user.data).to.have.lengthOf(2);
expect(ortb2Config.site.content.data).to.have.lengthOf(1);
expect(bidderTimeout).to.equal(3000);
});

it('should not corrupt global configuration with bidder configuration', () => {
Expand Down

0 comments on commit edaa499

Please sign in to comment.