Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user sync for brainyAdapter #2666

Merged
merged 1 commit into from
Jun 6, 2018
Merged
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
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);
});
});
});