Skip to content

Commit 4f9c025

Browse files
authored
update: Remove the outdated publisher ID field and the code responsible for macro replacement. (#12) (prebid#12905)
fixed test (#13) clean up
1 parent 895c052 commit 4f9c025

2 files changed

Lines changed: 2 additions & 175 deletions

File tree

modules/mobkoiBidAdapter.js

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
22
import { registerBidder } from '../src/adapters/bidderFactory.js';
33
import { BANNER } from '../src/mediaTypes.js';
4-
import { _each, replaceMacros, deepAccess, deepSetValue, logError } from '../src/utils.js';
4+
import { deepAccess, deepSetValue, logError } from '../src/utils.js';
55

66
const BIDDER_CODE = 'mobkoi';
77
const GVL_ID = 898;
@@ -13,18 +13,9 @@ const PUBLISHER_PARAMS = {
1313
* The name of the parameter that the publisher can use to specify the ad server endpoint.
1414
*/
1515
PARAM_NAME_AD_SERVER_BASE_URL: 'adServerBaseUrl',
16-
PARAM_NAME_PUBLISHER_ID: 'publisherId',
1716
PARAM_NAME_PLACEMENT_ID: 'placementId',
1817
}
1918

20-
/**
21-
* The list of ORTB response fields that are used in the macros. Field
22-
* replacement is self-implemented in the adapter. Use dot-notated path for
23-
* nested fields. For example, 'ad.ext.adomain'. For more information, visit
24-
* https://www.npmjs.com/package/dset and https://www.npmjs.com/package/dlv.
25-
*/
26-
const ORTB_RESPONSE_FIELDS_SUPPORT_MACROS = ['adm', 'nurl', 'lurl'];
27-
2819
export const converter = ortbConverter({
2920
context: {
3021
netRevenue: true,
@@ -35,7 +26,6 @@ export const converter = ortbConverter({
3526
const prebidBidRequest = context.bidRequests[0];
3627

3728
ortbRequest.id = utils.getOrtbId(prebidBidRequest);
38-
deepSetValue(ortbRequest, 'site.publisher.id', utils.getPublisherId(prebidBidRequest));
3929
deepSetValue(ortbRequest, 'site.publisher.ext.adServerBaseUrl', utils.getAdServerEndpointBaseUrl(prebidBidRequest));
4030
// We only support one impression per request.
4131
deepSetValue(ortbRequest, 'imp.0.tagid', utils.getPlacementId(prebidBidRequest));
@@ -44,8 +34,6 @@ export const converter = ortbConverter({
4434
return ortbRequest;
4535
},
4636
bidResponse(buildPrebidBidResponse, ortbBidResponse, context) {
47-
utils.replaceAllMacrosInPlace(ortbBidResponse, context);
48-
4937
const prebidBid = buildPrebidBidResponse(ortbBidResponse, context);
5038
utils.addCustomFieldsToPrebidBidResponse(prebidBid, ortbBidResponse);
5139
return prebidBid;
@@ -61,16 +49,6 @@ export const spec = {
6149
* Determines whether or not the given bid request is valid.
6250
*/
6351
isBidRequestValid(bid) {
64-
if (
65-
!deepAccess(bid, `params.${PUBLISHER_PARAMS.PARAM_NAME_PUBLISHER_ID}`) &&
66-
!deepAccess(bid, 'ortb2.site.publisher.id')
67-
) {
68-
logError(`The ${PUBLISHER_PARAMS.PARAM_NAME_PUBLISHER_ID} field is required in the bid request. ` +
69-
'Please follow the setup guideline to set the publisher ID field.'
70-
);
71-
return false;
72-
}
73-
7452
if (
7553
!deepAccess(bid, `params.${PUBLISHER_PARAMS.PARAM_NAME_PLACEMENT_ID}`)
7654
) {
@@ -176,43 +154,6 @@ export const utils = {
176154
return placementId;
177155
},
178156

179-
/**
180-
* !IMPORTANT: Make sure the implementation of this function matches utils.getPublisherId in
181-
* both adapters.
182-
* Extract the publisher ID from the given object.
183-
* @param {*} prebidBidRequestOrOrtbBidRequest
184-
* @returns string
185-
* @throws {Error} If the publisher ID is not found in the given object.
186-
*/
187-
getPublisherId: function (prebidBidRequestOrOrtbBidRequest) {
188-
// Fields that would be automatically set if the publisher set it
189-
// via pbjs.setBidderConfig.
190-
const ortbPath = 'site.publisher.id';
191-
const prebidPath = `ortb2.${ortbPath}`;
192-
193-
// Fields that would be set by the publisher in the bid
194-
// configuration object in ad unit.
195-
const paramPath = 'params.publisherId';
196-
const bidRequestFirstBidParam = `bids.0.${paramPath}`;
197-
198-
const publisherId =
199-
deepAccess(prebidBidRequestOrOrtbBidRequest, paramPath) ||
200-
deepAccess(prebidBidRequestOrOrtbBidRequest, bidRequestFirstBidParam) ||
201-
deepAccess(prebidBidRequestOrOrtbBidRequest, prebidPath) ||
202-
deepAccess(prebidBidRequestOrOrtbBidRequest, ortbPath);
203-
204-
if (!publisherId) {
205-
throw new Error(
206-
'Failed to obtain publisher ID from the given object. ' +
207-
`Please set it via the "${prebidPath}" field with pbjs.setBidderConfig.\n` +
208-
'Given object:\n' +
209-
JSON.stringify({functionParam: prebidBidRequestOrOrtbBidRequest}, null, 3)
210-
);
211-
}
212-
213-
return publisherId;
214-
},
215-
216157
/**
217158
* !IMPORTANT: Make sure the implementation of this function matches utils.getOrtbId in
218159
* mobkoiAnalyticsAdapter.js.
@@ -254,29 +195,4 @@ export const utils = {
254195
prebidBidResponse.ortbBidResponse = ortbBidResponse;
255196
prebidBidResponse.ortbId = ortbBidResponse.id;
256197
},
257-
258-
replaceAllMacrosInPlace(ortbBidResponse, context) {
259-
const macros = {
260-
// ORTB macros
261-
AUCTION_PRICE: ortbBidResponse.price,
262-
AUCTION_IMP_ID: ortbBidResponse.impid,
263-
AUCTION_CURRENCY: ortbBidResponse.cur,
264-
AUCTION_BID_ID: context.bidderRequest.auctionId,
265-
266-
// Custom macros
267-
BIDDING_API_BASE_URL: utils.getAdServerEndpointBaseUrl(context.bidderRequest),
268-
CREATIVE_ID: ortbBidResponse.crid,
269-
CAMPAIGN_ID: ortbBidResponse.cid,
270-
ORTB_ID: ortbBidResponse.id,
271-
PUBLISHER_ID: utils.getPublisherId(context.bidderRequest),
272-
};
273-
274-
_each(ORTB_RESPONSE_FIELDS_SUPPORT_MACROS, ortbField => {
275-
deepSetValue(
276-
ortbBidResponse,
277-
ortbField,
278-
replaceMacros(deepAccess(ortbBidResponse, ortbField), macros)
279-
);
280-
});
281-
},
282198
}

test/spec/modules/mobkoiBidAdapter_spec.js

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
describe('Mobkoi bidding Adapter', function () {
88
const testAdServerBaseUrl = 'http://test.adServerBaseUrl.com';
99
const testRequestId = 'test-request-id';
10-
const testPublisherId = 'mobkoiPublisherId';
1110
const testPlacementId = 'mobkoiPlacementId';
1211
const testBidId = 'test-bid-id';
1312
const bidderCode = 'mobkoi';
@@ -18,7 +17,6 @@ describe('Mobkoi bidding Adapter', function () {
1817
const getOrtb2 = () => ({
1918
site: {
2019
publisher: {
21-
id: testPublisherId,
2220
ext: { adServerBaseUrl: testAdServerBaseUrl }
2321
}
2422
}
@@ -34,7 +32,6 @@ describe('Mobkoi bidding Adapter', function () {
3432
auctionId: testAuctionId,
3533
ortb2: getOrtb2(),
3634
params: {
37-
publisherId: testPublisherId,
3835
adServerBaseUrl: testAdServerBaseUrl,
3936
placementId: testPlacementId
4037
}
@@ -102,36 +99,14 @@ describe('Mobkoi bidding Adapter', function () {
10299
bid = getBidderRequest().bids[0];
103100
});
104101

105-
it('should return true when publisher id only exists in ortb2', function () {
106-
delete bid.params.publisherId;
107-
expect(spec.isBidRequestValid(bid)).to.equal(true);
108-
});
109-
110102
it('should return true when placement id exist in ad unit params', function () {
111103
expect(spec.isBidRequestValid(bid)).to.equal(true);
112104
});
113105

114-
it('should return true when publisher ID only exists in ad unit params', function () {
115-
delete bid.ortb2.site.publisher.id;
116-
expect(spec.isBidRequestValid(bid)).to.equal(true);
117-
});
118-
119-
it('should return false when publisher id is missing both in ad unit params and ortb2', function () {
120-
delete bid.ortb2.site.publisher.id;
121-
delete bid.params.publisherId;
122-
expect(spec.isBidRequestValid(bid)).to.equal(false);
123-
});
124-
125106
it('should return false when placement id is missing in ad unit params', function () {
126107
delete bid.params.placementId;
127108
expect(spec.isBidRequestValid(bid)).to.equal(false);
128109
});
129-
130-
it('should return false when publisher id is empty in ad unit params and ortb2', function () {
131-
bid.ortb2.site.publisher.id = '';
132-
bid.params.publisherId = '';
133-
expect(spec.isBidRequestValid(bid)).to.equal(false);
134-
});
135110
});
136111

137112
describe('buildRequests', function () {
@@ -147,18 +122,9 @@ describe('Mobkoi bidding Adapter', function () {
147122
const ortbData = request.data;
148123

149124
expect(ortbData.id).to.equal(bidderRequest.bidderRequestId);
150-
expect(ortbData.site.publisher.id).to.equal(bidderRequest.ortb2.site.publisher.id);
151125
});
152126

153-
it('should obtain publisher ID from ad unit params if the value does not exist in ortb2.', function () {
154-
delete bidderRequest.ortb2.site.publisher.id;
155-
const request = spec.buildRequests(bidderRequest.bids, bidderRequest);
156-
const ortbData = request.data;
157-
158-
expect(ortbData.site.publisher.id).to.equal(bidderRequest.bids[0].params.publisherId);
159-
});
160-
161-
it('should obtain adServerBaseUrl from ad unit params if the value does not exist in ortb2.', function () {
127+
it('should obtain adServerBaseUrl from ad unit params if the value does not exist in ortb2', function () {
162128
delete bidderRequest.ortb2.site.publisher.ext.adServerBaseUrl;
163129
const request = spec.buildRequests(bidderRequest.bids, bidderRequest);
164130
const ortbData = request.data;
@@ -226,20 +192,6 @@ describe('Mobkoi bidding Adapter', function () {
226192
});
227193
})
228194

229-
describe('getPublisherId', function () {
230-
it('should return the publisherId from the given object', function () {
231-
expect(utils.getPublisherId(bidderRequest)).to.equal(bidderRequest.ortb2.site.publisher.id);
232-
});
233-
234-
it('should throw error when publisherId is missing', function () {
235-
delete bidderRequest.ortb2.site.publisher.id;
236-
delete bidderRequest.bids[0].params.publisherId;
237-
expect(() => {
238-
utils.getPublisherId(bidderRequest);
239-
}).to.throw();
240-
});
241-
})
242-
243195
describe('getOrtbId', function () {
244196
it('should return the ortbId from the prebid request object (i.e bidderRequestId)', function () {
245197
expect(utils.getOrtbId(bidderRequest)).to.equal(bidderRequest.bidderRequestId);
@@ -270,46 +222,5 @@ describe('Mobkoi bidding Adapter', function () {
270222
}).to.throw();
271223
});
272224
})
273-
274-
describe('replaceAllMacrosInPlace', function () {
275-
let bidderResponse, bidRequest, bidderRequest;
276-
277-
beforeEach(function () {
278-
bidderRequest = getBidderRequest();
279-
bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest);
280-
bidderResponse = getBidderResponse();
281-
});
282-
283-
it('should replace all macros in adm, nurl, and lurl fields', function () {
284-
const bid = bidderResponse.body.seatbid[0].bid[0];
285-
bid.nurl = '${BIDDING_API_BASE_URL}/win?price=${AUCTION_PRICE}&impressionId=${AUCTION_IMP_ID}&currency=${AUCTION_CURRENCY}&campaignId=${CAMPAIGN_ID}&creativeId=${CREATIVE_ID}&publisherId=${PUBLISHER_ID}&ortbId=${ORTB_ID}';
286-
bid.lurl = '${BIDDING_API_BASE_URL}/loss?price=${AUCTION_PRICE}&impressionId=${AUCTION_IMP_ID}&currency=${AUCTION_CURRENCY}&campaignId=${CAMPAIGN_ID}&creativeId=${CREATIVE_ID}&publisherId=${PUBLISHER_ID}&ortbId=${ORTB_ID}';
287-
bid.adm = '<div>${AUCTION_PRICE}${AUCTION_CURRENCY}${AUCTION_IMP_ID}${AUCTION_BID_ID}${CAMPAIGN_ID}${CREATIVE_ID}${PUBLISHER_ID}${ORTB_ID}${BIDDING_API_BASE_URL}</div>';
288-
289-
const BIDDING_API_BASE_URL = testAdServerBaseUrl;
290-
const AUCTION_CURRENCY = bidderResponse.body.cur;
291-
const AUCTION_BID_ID = bidderRequest.auctionId;
292-
const AUCTION_PRICE = bid.price;
293-
const AUCTION_IMP_ID = bid.impid;
294-
const CREATIVE_ID = bid.crid;
295-
const CAMPAIGN_ID = bid.cid;
296-
const PUBLISHER_ID = bidderRequest.ortb2.site.publisher.id;
297-
const ORTB_ID = bidderResponse.body.id;
298-
299-
const context = {
300-
bidRequest,
301-
bidderRequest
302-
}
303-
utils.replaceAllMacrosInPlace(bid, context);
304-
305-
expect(bid.adm).to.equal(`<div>${AUCTION_PRICE}${AUCTION_CURRENCY}${AUCTION_IMP_ID}${AUCTION_BID_ID}${CAMPAIGN_ID}${CREATIVE_ID}${PUBLISHER_ID}${ORTB_ID}${BIDDING_API_BASE_URL}</div>`);
306-
expect(bid.lurl).to.equal(
307-
`${BIDDING_API_BASE_URL}/loss?price=${AUCTION_PRICE}&impressionId=${AUCTION_IMP_ID}&currency=${AUCTION_CURRENCY}&campaignId=${CAMPAIGN_ID}&creativeId=${CREATIVE_ID}&publisherId=${PUBLISHER_ID}&ortbId=${ORTB_ID}`
308-
);
309-
expect(bid.nurl).to.equal(
310-
`${BIDDING_API_BASE_URL}/win?price=${AUCTION_PRICE}&impressionId=${AUCTION_IMP_ID}&currency=${AUCTION_CURRENCY}&campaignId=${CAMPAIGN_ID}&creativeId=${CREATIVE_ID}&publisherId=${PUBLISHER_ID}&ortbId=${ORTB_ID}`
311-
);
312-
});
313-
})
314225
})
315226
})

0 commit comments

Comments
 (0)