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 getUserSyncs function in clickforceBidAdapter #2383

Merged
merged 6 commits into from
Apr 27, 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
13 changes: 13 additions & 0 deletions modules/clickforceBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ export const spec = {
});
});
return cfResponses;
},
getUserSyncs: function(syncOptions, serverResponses) {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: 'https://cdn.doublemax.net/js/capmapping.htm'
}]
} else if (syncOptions.pixelEnabled) {
return [{
type: 'image',
url: 'https://c.doublemax.net/cm'
}]
}
}
};
registerBidder(spec);
10 changes: 10 additions & 0 deletions modules/clickforceBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ joey@clickforce.com.tw (MR. Joey)
}]
}];
```
### Configuration

CLICKFORCE recommend the UserSync configuration below. It's can be optimize the CPM for the request.
```javascript
pbjs.setConfig({
userSync: {
iframeEnabled: true,
syncDelay: 1000
}});
```
127 changes: 127 additions & 0 deletions test/spec/modules/clickforceBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { expect } from 'chai';
import { spec } from 'modules/clickforceBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';

describe('ClickforceAdapter', () => {
const adapter = newBidder(spec);

describe('inherited functions', () => {
it('exists and is a function', () => {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});

describe('isBidRequestValid', () => {
let bid = {
'bidder': 'clickforce',
'params': {
'zone': '6682'
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475'
};

it('should return true when required params found', () => {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when required params are not passed', () => {
let bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
'someIncorrectParam': 0
};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequests', () => {
let bidRequests = [{
'bidder': 'clickforce',
'params': {
'zone': '6682'
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475'
}];

const request = spec.buildRequests(bidRequests);

it('sends bid request to our endpoint via POST', () => {
expect(request.method).to.equal('POST');
});
});

describe('interpretResponse', () => {
let response = [{
'cpm': 0.5,
'width': '300',
'height': '250',
'callback_uid': '220ed41385952a',
'type': 'Default Ad',
'tag': '<!-- test creative -->',
'creativeId': '1f99ac5c3ef10a4097499a5686b30aff-6682',
'requestId': '220ed41385952a',
'currency': 'USD',
'ttl': 60,
'netRevenue': true,
'zone': '6682'
}];

it('should get the correct bid response', () => {
let expectedResponse = [{
'requestId': '220ed41385952a',
'cpm': 0.5,
'width': '300',
'height': '250',
'creativeId': '1f99ac5c3ef10a4097499a5686b30aff-6682',
'currency': 'USD',
'netRevenue': true,
'ttl': 60,
'ad': '<!-- test creative -->'
}];

let bidderRequest;
let result = spec.interpretResponse({ body: response }, {bidderRequest});
expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0]));
});

it('handles empty bid response', () => {
let response = {
body: {}
};
let result = spec.interpretResponse(response);
expect(result.length).to.equal(0);
});
});

describe('getUserSyncs function', () => {
it('should register type is iframe', () => {
const syncOptions = {
'iframeEnabled': 'true'
}
let userSync = spec.getUserSyncs(syncOptions);
expect(userSync[0].type).to.equal('iframe');
expect(userSync[0].url).to.equal('https://cdn.doublemax.net/js/capmapping.htm');
});

it('should register type is image', () => {
const syncOptions = {
'pixelEnabled': 'true'
}
let userSync = spec.getUserSyncs(syncOptions);
expect(userSync[0].type).to.equal('image');
expect(userSync[0].url).to.equal('https://c.doublemax.net/cm');
});
});
});