Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions src_new/idhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ window.IHPWT.getUserIds = function(){
return util.getUserIds();
};

window.IHPWT.deepMerge = function(target,source,key){
return util.deepMerge(target, source, key);
};

window.IHPWT.versionDetails = util.getOWConfig();

controller.init(window);
41 changes: 37 additions & 4 deletions src_new/util.idhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ var refThis = this;
var pbNameSpace = CONFIG.isIdentityOnly() ? CONSTANTS.COMMON.IH_NAMESPACE : CONSTANTS.COMMON.PREBID_NAMESPACE;
refThis.idsAppendedToAdUnits = false;

function isA(object, testForType) {
exports.isA = function(object, testForType) {
return toString.call(object) === "[object " + testForType + "]";
}

/* start-test-block */
exports.isA = isA;
/* end-test-block */
// /* start-test-block */
// exports.isA = isA;
// /* end-test-block */

exports.isFunction = function (object) {
return refThis.isA(object, typeFunction);
Expand Down Expand Up @@ -678,3 +678,36 @@ exports.getOWConfig = function(){
};
return obj;
};

exports.deepMerge = function(target, source, keyName) {
var keyName = keyName ? keyName: "source";
if (refThis.isArray(target) && refThis.isArray(source)) {
var mergedArr = [].concat(target);
source.forEach(function(item2){
var found = false;
mergedArr.forEach(function(item1, index){
if (item1[keyName] === item2[keyName]) {
mergedArr[index] = refThis.deepMerge(item1, item2);
found = true;
}
});
if (!found) {
mergedArr.push(item2);
}
});
return mergedArr;
}

if (refThis.isObject(target) && refThis.isObject(source)) {
var mergedObj = Object.assign({}, target);
Object.keys(source).forEach(function(key){
if (mergedObj[key] && typeof mergedObj[key] === 'object' && typeof source[key] === 'object') {
mergedObj[key] = refThis.deepMerge(mergedObj[key], source[key]);
} else {
mergedObj[key] = source[key];
}
});
return mergedObj;
}
return source;
}
8 changes: 4 additions & 4 deletions src_new/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ var mediaTypeConfigPerSlot = {};
exports.mediaTypeConfig = mediaTypeConfigPerSlot;
var pbNameSpace = parseInt(conf[CONSTANTS.CONFIG.COMMON][CONSTANTS.COMMON.IDENTITY_ONLY] || CONSTANTS.CONFIG.DEFAULT_IDENTITY_ONLY) ? CONSTANTS.COMMON.IH_NAMESPACE : CONSTANTS.COMMON.PREBID_NAMESPACE;
exports.pbNameSpace = pbNameSpace;
function isA(object, testForType) {
exports.isA = function(object, testForType) {
return toString.call(object) === "[object " + testForType + "]";
}

/* start-test-block */
exports.isA = isA;
/* end-test-block */
// /* start-test-block */
// exports.isA = isA;
// /* end-test-block */

exports.isFunction = function (object) {
return refThis.isA(object, typeFunction);
Expand Down
49 changes: 38 additions & 11 deletions test/util.idhub.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ describe('IDHUBUTIL', function() {
'ecpm':'10.00'
}
sinon.stub(IDHUBUTIL,'getUserIds').returns({id:1})
sinon.stub(IDHUBUTIL,'getUserIdsAsEids').returns([{"source":"myId",id:1}])
sinon.stub(IDHUBUTIL,'getUserIdsAsEids').returns([{"source":"myId",uids:[{ "id": "idhub-id"}]}])
done();
});

Expand All @@ -1195,31 +1195,31 @@ describe('IDHUBUTIL', function() {
});

it('should add UserId in bid if userIds is not present', function(done){
var expectedResult = {"ecpm":"10.00","userId":{"id":1},"userIdAsEids":[{"source":"myId","id":1}]}
var expectedResult = {"ecpm":"10.00","userId":{"id":1},"userIdAsEids":[{"source":"myId",uids:[{ "id": "idhub-id"}]}]}
IDHUBUTIL.updateUserIds(bid)
bid.should.be.deep.equal(expectedResult);
done();
})

// TODO: UnComment Below Test Cases once PhantomJs is replaced by ChromeHeadless in build.sh production and test mode
xit('should update UserID in bid if userIds is present',function(done){
var expectedResult = {"ecpm":"10.00","userId":{"existingId":2,"id":1},"userIdAsEids":[{"source":"myId","id":1},{"source":"existingMyId","existingId":2}]}
it('should update(or merge) UserID in bid if userIds is present',function(done){
var expectedResult = {"ecpm":"10.00","userId":{"existingId":2,"id":1},"userIdAsEids":[{"source":"existingMyId","uids": [{"id": "prebid-id"}]},{"source":"myId",uids:[{ "id": "idhub-id"}]}]}
bid['userId'] = {"existingId":2}
bid['userIdAsEids'] = [{"source":"existingMyId","existingId":2}]
bid['userIdAsEids'] = [{"source":"existingMyId","uids": [{"id": "prebid-id"}]}]
IDHUBUTIL.updateUserIds(bid)
bid.should.be.deep.equal(expectedResult);
done();
})
// TODO: UnComment Below Test Cases once PhantomJs is replaced by ChromeHeadless in build.sh production and test mode
xit('should update with IH values if same id is present', function(done){
var expectedResult = {"ecpm":"10.00","userId":{"id":1},"userIdAsEids":[{"source":"myId","id":1}]}

it('should update or pass prebid ID instead of IH ID in bid if same id is present', function(done){
var expectedResult = {"ecpm":"10.00","userId":{"id":1},"userIdAsEids":[{"source":"myId","uids": [{"id": "prebid-id"}]}]}
bid['userId'] = {"id":2}
bid['userIdAsEids'] = [{"source":"myId","id":2}]
bid['userIdAsEids'] = [{"source":"myId","uids": [{"id": "prebid-id"}]}]
IDHUBUTIL.updateUserIds(bid);
bid.should.be.deep.equal(expectedResult);
done();
})
})
});

describe('#applyDataTypeChangesIfApplicable', function() {
var params;
beforeEach(function(done) {
Expand Down Expand Up @@ -1334,6 +1334,33 @@ describe('IDHUBUTIL', function() {
});
});

describe('#deepMerge', function(done) {
var idhubIds={hadronId:"0001yum0eak8dl8gdh96b9g6jgf7ckk7j8eja6ejc8abackkc2jl",id5id:{uid:"ID5*sKxFKbOtatCNM50_3IIRVMQ--jSt4JanBGfijnL1DXJHmX8g3-OyEFpze85ZUpb9R5rh8w3TLhT22sPBINYpmw",ext:{linkType:2}},lotamePanoramaId:"eec2b20f00590e28df32d1fe971da9fb927a4c9289cc4feaf6f0446d73d314f6",pubcid:"8577d672-7ea8-409f-9fbf-f0cf5b8fbf6b",tdid:"427f59e4-4b0e-478c-a6a7-ca5e6446da6f"};
var prebidIds={hadronId:"test-hardon-id",id5id:{uid:"test-id5id-id",ext:{linkType:2}}};
var expectedIdsResult={hadronId:"test-hardon-id",id5id:{uid:"test-id5id-id",ext:{linkType:2}},lotamePanoramaId:"eec2b20f00590e28df32d1fe971da9fb927a4c9289cc4feaf6f0446d73d314f6",pubcid:"8577d672-7ea8-409f-9fbf-f0cf5b8fbf6b",tdid:"427f59e4-4b0e-478c-a6a7-ca5e6446da6f"};
var idhubEids=[{source:"audigent.com",uids:[{id:"0001yum0eak8dl8gdh96b9g6jgf7ckk7j8eja6ejc8abackkc2jl",atype:1}]},{source:"id5-sync.com",uids:[{id:"ID5*sKxFKbOtatCNM50_3IIRVMQ--jSt4JanBGfijnL1DXJHmX8g3-OyEFpze85ZUpb9R5rh8w3TLhT22sPBINYpmw",atype:1,ext:{linkType:2}}]},{source:"crwdcntrl.net",uids:[{id:"eec2b20f00590e28df32d1fe971da9fb927a4c9289cc4feaf6f0446d73d314f6",atype:1}]},{source:"pubcid.org",uids:[{id:"8577d672-7ea8-409f-9fbf-f0cf5b8fbf6b",atype:1}]},{source:"adserver.org",uids:[{id:"427f59e4-4b0e-478c-a6a7-ca5e6446da6f",atype:1,ext:{rtiPartner:"TDID"}}]}];
var prebidEids=[{source:"audigent.com",uids:[{id:"prebid-id-audigent",atype:1}]},{source:"adserver.org",uids:[{id:"prebid-id-adserver.org",atype:1,ext:{rtiPartner:"TDID"}}]}];
var expectedResult=[{source:"audigent.com",uids:[{id:"prebid-id-audigent",atype:1}]},{source:"id5-sync.com",uids:[{id:"ID5*sKxFKbOtatCNM50_3IIRVMQ--jSt4JanBGfijnL1DXJHmX8g3-OyEFpze85ZUpb9R5rh8w3TLhT22sPBINYpmw",atype:1,ext:{linkType:2}}]},{source:"crwdcntrl.net",uids:[{id:"eec2b20f00590e28df32d1fe971da9fb927a4c9289cc4feaf6f0446d73d314f6",atype:1}]},{source:"pubcid.org",uids:[{id:"8577d672-7ea8-409f-9fbf-f0cf5b8fbf6b",atype:1}]},{source:"adserver.org",uids:[{id:"prebid-id-adserver.org",atype:1,ext:{rtiPartner:"TDID"}}]}];
beforeEach(function(done) {
done();
});
afterEach(function(done) {
done();
});

it('should merge the IDHUB ids with PREBID ids and not override them', function(done) {
var resultIds = IDHUBUTIL.deepMerge(idhubIds,prebidIds);
resultIds.should.deep.equal(expectedIdsResult);
done();
});

it('should merge the IDHUB eids with PREBID eids and not override them', function(done) {
var result = IDHUBUTIL.deepMerge(idhubEids,prebidEids);
result.should.deep.equal(expectedResult);
done();
});
});

// describe('#deleteCustomParams', function() {
// var paramsForLiverampV2;
// beforeEach(function(done) {
Expand Down