Skip to content

Commit

Permalink
#494 fix. AUCTION_END event was getting emitted in multiple scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiminpanchal27 committed Aug 4, 2016
1 parent 45fd284 commit fe7a5db
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,10 @@ exports.executeCallback = function () {

//execute one time callback
if (externalOneTimeCallback) {
$$PREBID_GLOBAL$$.clearAuction();
processCallbacks([externalOneTimeCallback]);
externalOneTimeCallback = null;
}

$$PREBID_GLOBAL$$.clearAuction();
};

function triggerAdUnitCallbacks(adUnitCode) {
Expand Down
78 changes: 78 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,4 +778,82 @@ describe('Unit: Prebid Module', function () {
bidmanager.setPriceGranularity.restore();
});
});

describe('emit event', () => {
it('should call AUCTION_END only once', () => {

var clock = sinon.useFakeTimers();
var spyClearAuction = sinon.spy($$PREBID_GLOBAL$$, 'clearAuction');

var requestObj = {
bidsBackHandler: function bidsBackHandlerCallback() {},
timeout: 2000,
};

$$PREBID_GLOBAL$$.requestBids(requestObj);
clock.tick(2000);
assert.ok(spyClearAuction.calledOnce, 'once');

$$PREBID_GLOBAL$$._bidsRequested = [{
"bidderCode": "appnexus",
"requestId": "1863e370099523",
"bidderRequestId": "2946b569352ef2",
"bids": [
{
"bidder": "appnexus",
"params": {
"placementId": "4799418",
"test": "me"
},
"placementCode": "/19968336/header-bid-tag1",
"sizes": [[728,90],[970,90]],
"bidId": "392b5a6b05d648",
"bidderRequestId": "2946b569352ef2",
"requestId": "1863e370099523",
"startTime": 1462918897462,
"status": 1
}
],
"start": 1462918897460
}];

$$PREBID_GLOBAL$$._bidsReceived = [];

var bid = {
"bidderCode": "appnexus",
"width": 728,
"height": 90,
"statusMessage": "Bid available",
"adId": "24bd938435ec3fc",
"creative_id": 33989846,
"cpm": 0,
"adUrl": "http://lax1-ib.adnxs.com/ab?e=wqT_3QLyBKhyAgAAAwDWAAUBCMjAybkFEOOryfjI7rGNWhjL84KE1tzG-kkgASotCQAAAQII4D8RAQcQAADgPxkJCQjwPyEJCQjgPykRCaAwuvekAji-B0C-B0gCUNbJmhBYweAnYABokUB4mt0CgAEBigEDVVNEkgUG8ECYAdgFoAFaqAEBsAEAuAEBwAEDyAEA0AEA2AEA4AEA8AEAigI6dWYoJ2EnLCA0OTQ0NzIsIDE0NjI5MTkyNDApOwEcLHInLCAzMzk4OTg0NjYeAPBvkgLNASFwU2Y1YUFpNjBJY0VFTmJKbWhBWUFDREI0Q2N3QURnQVFBUkl2Z2RRdXZla0FsZ0FZSk1IYUFCd3lnNTRDb0FCcGh5SUFRcVFBUUdZQVFHZ0FRR29BUU93QVFDNUFRQUFBQUFBQU9BX3dRRQkMSEFEZ1A4a0JJNTJDbGs5VjB6X1oVKCRQQV80QUVBOVFFBSw8bUFLS2dNQ0NENkFDQUxVQwUVBEwwCQh0T0FDQU9nQ0FQZ0NBSUFEQVEuLpoCJSFfZ2lqYXdpMtAA8KZ3ZUFuSUFRb2lvREFnZzgu2ALoB-ACx9MB6gIfaHR0cDovL3ByZWJpZC5vcmc6OTk5OS9ncHQuaHRtbIADAIgDAZADAJgDBaADAaoDALADALgDAMADrALIAwDYAwDgAwDoAwD4AwOABACSBAQvanB0mAQAogQKMTAuMS4xMy4zN6gEi-wJsgQICAAQABgAIAC4BADABADIBADSBAsxMC4wLjgwLjI0MA..&s=1f584d32c2d7ae3ce3662cfac7ca24e710bc7fd0&referrer=http%3A%2F%2Fprebid.org%3A9999%2Fgpt.html",
"responseTimestamp": 1462919239342,
"requestTimestamp": 1462919238919,
"bidder": "appnexus",
"adUnitCode": "/19968336/header-bid-tag1",
"timeToRespond": 423,
"pbLg": "5.00",
"pbMg": "10.00",
"pbHg": "10.00",
"pbAg": "10.00",
"size": "728x90",
"alwaysUseBid": true,
"adserverTargeting": {
"hb_bidder": "appnexus",
"hb_adid": "24bd938435ec3fc",
"hb_pb": "10.00",
"hb_size": "728x90",
"foobar": "728x90"
}
};

const adUnitCode = '/19968336/header-bid-tag1';
$$PREBID_GLOBAL$$.addBidResponse(adUnitCode, bid);
assert.equal(spyClearAuction.callCount,1, 'AUCTION_END event emitted more than once');

clock.restore();
resetAuction();
});
});
});

0 comments on commit fe7a5db

Please sign in to comment.