Skip to content

Commit

Permalink
Add user sync for brainyAdapter (prebid#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
brainymisio authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent 5fff8c7 commit 9a2e907
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
23 changes: 23 additions & 0 deletions modules/brainyBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ export const spec = {
});

return bidResponses;
},

/**
* SyncURLがある場合にレスポンスを解析してURLを返す
* @param {object} syncOptions Syncの設定
* @param {object} serverResponses SSPからのレスポンス
* @return {object} 表示タイプとURLが入ったオブジェクト
*/
getUserSyncs: function(syncOptions, serverResponses) {
const syncs = [];
if (syncOptions.pixelEnabled) {
const brainyResponseObj = serverResponses[0].body;
if (!brainyResponseObj) {
return [];
}
if (brainyResponseObj.syncUrl && brainyResponseObj.syncUrl != 'null' && brainyResponseObj.syncUrl.length > 0) {
syncs.push({
type: 'image',
url: brainyResponseObj.syncUrl
});
}
}
return syncs;
}
};
registerBidder(spec);
50 changes: 49 additions & 1 deletion test/spec/modules/brainyBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,39 @@ const bidReq = [{
const correctReq = {
accountID: '12345',
slotID: '12345'
}
};

const bidResponse = {
ad_id: '1036e9746c-d186-49ae-90cb-2796d0f9b223',
adm: '<img src=\'http://placehold.it/300x250/ffff6d/000000/?text=everrise300x250\'>',
syncUrl: '//testparm.com/ssp-sync/p/sync?uid=2110180601155125000059&buyer=2&slot=34',
cpm: 100,
height: 250,
width: 300
};

const bidSyncResponse = [{
body: {
ad_id: '1036e9746c-d186-49ae-90cb-2796d0f9b223',
adm: '<img src=\'http://placehold.it/300x250/ffff6d/000000/?text=everrise300x250\'>',
syncUrl: '//testparm.com/ssp-sync/p/sync?uid=2110180601155125000059&buyer=2&slot=34',
cpm: 100,
height: 250,
width: 300
}
}];

const invalidSyncBidResponse = [{
body: {
ad_id: '1036e9746c-d186-49ae-90cb-2796d0f9b223',
adm: '<img src=\'http://placehold.it/300x250/ffff6d/000000/?text=everrise300x250\'>',
syncUrl: 'null',
cpm: 100,
height: 250,
width: 300
}
}];

describe('brainy Adapter', () => {
describe('request', () => {
it('should validate bid request', () => {
Expand Down Expand Up @@ -77,4 +100,29 @@ describe('brainy Adapter', () => {
expect(bid.height).to.equal(bidResponse.height);
});
});

describe('spec.getUserSyncs', () => {
let syncOptions
beforeEach(() => {
syncOptions = {
enabledBidders: ['brainy'],
pixelEnabled: true
}
});
it('sucess with usersync url', () => {
const result = [];
result.push({type: 'image', url: '//testparm.com/ssp-sync/p/sync?uid=2110180601155125000059&buyer=2&slot=34'});
expect(spec.getUserSyncs(syncOptions, bidSyncResponse)).to.deep.equal(result);
});

it('sucess without usersync url', () => {
const result = [];
expect(spec.getUserSyncs(syncOptions, invalidSyncBidResponse)).to.deep.equal(result);
});
it('empty response', () => {
const serverResponse = [{body: {}}];
const result = [];
expect(spec.getUserSyncs(syncOptions, serverResponse)).to.deep.equal(result);
});
});
});

0 comments on commit 9a2e907

Please sign in to comment.