Skip to content

Commit

Permalink
Fix if dot is in adUnitCode (#12206)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrmartinez authored Sep 5, 2024
1 parent 675cf35 commit c82ce31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/adUnits.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { deepAccess } from './utils.js';

let adUnits = {};
export function reset() {
adUnits = {}
Expand Down Expand Up @@ -54,7 +52,7 @@ export function incrementBidderWinsCounter(adunit, bidderCode) {
* @returns {number} current adunit count
*/
export function getRequestsCounter(adunit) {
return deepAccess(adUnits, `${adunit}.requestsCounter`) || 0;
return adUnits?.[adunit]?.requestsCounter || 0;
}

/**
Expand All @@ -64,7 +62,7 @@ export function getRequestsCounter(adunit) {
* @returns {number} current adunit bidder requests count
*/
export function getBidderRequestsCounter(adunit, bidder) {
return deepAccess(adUnits, `${adunit}.bidders.${bidder}.requestsCounter`) || 0;
return adUnits?.[adunit]?.bidders?.[bidder]?.requestsCounter || 0;
}

/**
Expand All @@ -74,5 +72,5 @@ export function getBidderRequestsCounter(adunit, bidder) {
* @returns {number} current adunit bidder requests count
*/
export function getBidderWinsCounter(adunit, bidder) {
return deepAccess(adUnits, `${adunit}.bidders.${bidder}.winsCounter`) || 0;
return adUnits?.[adunit]?.bidders?.[bidder]?.winsCounter || 0;
}
15 changes: 15 additions & 0 deletions test/spec/unit/adUnits_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ describe('Adunit Counter', function () {
adunitCounter.incrementRequestsCounter(ADUNIT_ID_2);
expect(adunitCounter.getRequestsCounter(ADUNIT_ID_2)).to.be.equal(1);
});
it('increments and checks requests counter if adUnit has a dots in it', function () {
const adCode = 'adunit.1'
adunitCounter.incrementRequestsCounter(adCode);
expect(adunitCounter.getRequestsCounter(adCode)).to.be.equal(1);
});
it('increments and checks requests counter of adunit 1 for bidder 1', function () {
adunitCounter.incrementBidderRequestsCounter(ADUNIT_ID_1, BIDDER_ID_1);
expect(adunitCounter.getBidderRequestsCounter(ADUNIT_ID_1, BIDDER_ID_1)).to.be.equal(1);
Expand All @@ -34,6 +39,11 @@ describe('Adunit Counter', function () {
adunitCounter.incrementBidderRequestsCounter(ADUNIT_ID_1, BIDDER_ID_1);
expect(adunitCounter.getBidderRequestsCounter(ADUNIT_ID_1, BIDDER_ID_1)).to.be.equal(2);
});
it('increments and checks bidder requests counter if adUnit has a dots in it', function () {
const adCode = 'adunit.1'
adunitCounter.incrementBidderRequestsCounter(adCode, BIDDER_ID_2);
expect(adunitCounter.getBidderRequestsCounter(adCode, BIDDER_ID_2)).to.be.equal(1);
});
it('increments and checks wins counter of adunit 1 for bidder 1', function () {
adunitCounter.incrementBidderWinsCounter(ADUNIT_ID_1, BIDDER_ID_1);
expect(adunitCounter.getBidderWinsCounter(ADUNIT_ID_1, BIDDER_ID_1)).to.be.equal(1);
Expand All @@ -46,4 +56,9 @@ describe('Adunit Counter', function () {
adunitCounter.incrementBidderWinsCounter(ADUNIT_ID_1, BIDDER_ID_2);
expect(adunitCounter.getBidderWinsCounter(ADUNIT_ID_1, BIDDER_ID_2)).to.be.equal(1);
});
it('increments and checks wins counter if adUnit has a dots in it', function () {
const adCode = 'adunit.1'
adunitCounter.incrementBidderWinsCounter(adCode, BIDDER_ID_2);
expect(adunitCounter.getBidderWinsCounter(adCode, BIDDER_ID_2)).to.be.equal(1);
});
});

0 comments on commit c82ce31

Please sign in to comment.