Skip to content

Commit

Permalink
handles empty responses in getUserSyncs & add tests - ajaBidAdapter (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
pokutuna authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent e522ec3 commit 7d35350
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/ajaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const spec = {

getUserSyncs: function(syncOptions, serverResponses) {
const syncs = [];
if (syncOptions.pixelEnabled) {
if (syncOptions.pixelEnabled && serverResponses.length) {
const bidderResponseBody = serverResponses[0].body;
if (bidderResponseBody.syncs) {
bidderResponseBody.syncs.forEach(sync => {
Expand Down
42 changes: 42 additions & 0 deletions test/spec/modules/ajaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,46 @@ describe('AjaAdapter', function () {
expect(result.length).to.equal(0);
});
});

describe('getUserSyncs', function () {
const bidResponse1 = {
body: {
'is_ad_return': true,
'ad': { /* ad body */ },
'syncs': [
'https://example.test/1'
]
}
};

const bidResponse2 = {
body: {
'is_ad_return': true,
'ad': { /* ad body */ },
'syncs': [
'https://example.test/2'
]
}
};

it('should use a sync url from first response', function () {
const syncs = spec.getUserSyncs({ pixelEnabled: true }, [bidResponse1, bidResponse2]);
expect(syncs).to.deep.equal([
{
type: 'image',
url: 'https://example.test/1'
}
]);
});

it('handle empty response (e.g. timeout)', function () {
const syncs = spec.getUserSyncs({ pixelEnabled: true }, []);
expect(syncs).to.deep.equal([]);
});

it('returns empty syncs when not enabled', function () {
const syncs = spec.getUserSyncs({ pixelEnabled: false }, [bidResponse1]);
expect(syncs).to.deep.equal([]);
});
});
});

0 comments on commit 7d35350

Please sign in to comment.