Skip to content

Commit

Permalink
added onBidWon event (#5679)
Browse files Browse the repository at this point in the history
* added onBidWon event

* luponmedia onBidWon event + test

* luponmedia onbidwon event + unit test

* luponmedia onbidwon event + test

* luponmedia onbidwon + unit testing

* luponmedia onbidwon event + unit tests

* luponmedia onbidwon event ajax

* package-log revert
  • Loading branch information
adxpremium authored Sep 16, 2020
1 parent fd9a0d4 commit a3aa5f4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/luponmediaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
import {BANNER} from '../src/mediaTypes.js';
import { ajax } from '../src/ajax.js';

const BIDDER_CODE = 'luponmedia';
const ENDPOINT_URL = 'https://rtb.adxpremium.services/openrtb2/auction';
Expand Down Expand Up @@ -113,6 +114,19 @@ export const spec = {
hasSynced = true;
return allUserSyncs;
},
onBidWon: bid => {
const bidString = JSON.stringify(bid);
spec.sendWinningsToServer(bidString);
},
sendWinningsToServer: data => {
let mutation = `mutation {createWin(input: {win: {eventData: "${window.btoa(data)}"}}) {win {createTime } } }`;
let dataToSend = JSON.stringify({ query: mutation });

ajax('https://analytics.adxpremium.services/graphql', null, dataToSend, {
contentType: 'application/json',
method: 'POST'
});
}
};

function newOrtbBidRequest(bidRequest, bidderRequest, currentImps) {
Expand Down
45 changes: 45 additions & 0 deletions test/spec/modules/luponmediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,49 @@ describe('luponmediaBidAdapter', function () {
expect(checkSchain).to.equal(false);
});
});

describe('onBidWon', function () {
const bidWonEvent = {
'bidderCode': 'luponmedia',
'width': 300,
'height': 250,
'statusMessage': 'Bid available',
'adId': '105bbf8c54453ff',
'requestId': '934b8752185955',
'mediaType': 'banner',
'source': 'client',
'cpm': 0.364,
'creativeId': '443801010',
'currency': 'USD',
'netRevenue': false,
'ttl': 300,
'referrer': '',
'ad': '',
'auctionId': '926a8ea3-3dd4-4bf2-95ab-c85c2ce7e99b',
'responseTimestamp': 1598527728026,
'requestTimestamp': 1598527727629,
'bidder': 'luponmedia',
'adUnitCode': 'div-gpt-ad-1533155193780-5',
'timeToRespond': 397,
'size': '300x250',
'status': 'rendered'
};

let ajaxStub;

beforeEach(() => {
ajaxStub = sinon.stub(spec, 'sendWinningsToServer')
})

afterEach(() => {
ajaxStub.restore()
})

it('calls luponmedia\'s callback endpoint', () => {
const result = spec.onBidWon(bidWonEvent);
expect(result).to.equal(undefined);
expect(ajaxStub.calledOnce).to.equal(true);
expect(ajaxStub.firstCall.args[0]).to.deep.equal(JSON.stringify(bidWonEvent));
});
});
});

0 comments on commit a3aa5f4

Please sign in to comment.