Skip to content

Commit

Permalink
using Set in trackers map
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieularere-msq committed Aug 31, 2023
1 parent 641c597 commit cb593d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ function isValidVastTracker(trackers, trackerToAdd) {

function trackersToMap(trackers) {
return trackers.reduce((map, {url, event}) => {
!map.has(event) && map.set(event, [])
map.get(event).push(url);
!map.has(event) && map.set(event, new Set())
map.get(event).add(url);
return map;
}, new Map())
}

export function addImpUrlToTrackers(bid, trackersMap) {
if (bid.vastImpUrl) {
if (!trackersMap) { trackersMap = new Map(); }
if (!trackersMap.get('impressions')) { trackersMap.set('impressions', []); }
trackersMap.get('impressions').push(bid.vastImpUrl);
if (!trackersMap.get('impressions')) { trackersMap.set('impressions', new Set()); }
trackersMap.get('impressions').add(bid.vastImpUrl);
}
return trackersMap;
}
4 changes: 2 additions & 2 deletions test/spec/video_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('video.js', function () {
trackers = getVastTrackers({'cpm': 1.0});
expect(trackers).to.be.a('map');
expect(trackers.get('impressions')).to.exists;
expect(trackers.get('impressions')[0]).to.equal('https://vasttracking.mydomain.com/vast?cpm=1');
expect(trackers.get('impressions').has('https://vasttracking.mydomain.com/vast?cpm=1')).to.be.true;
});

it('insert trackers in vastXml', function() {
Expand All @@ -128,6 +128,6 @@ describe('video.js', function () {
const trackers = addImpUrlToTrackers({'vastImpUrl': 'imptracker.com'}, getVastTrackers({'cpm': 1.0}));
expect(trackers).to.be.a('map');
expect(trackers.get('impressions')).to.exists;
expect(trackers.get('impressions')[1]).to.equal('imptracker.com');
expect(trackers.get('impressions').has('imptracker.com')).to.be.true;
});
});

0 comments on commit cb593d5

Please sign in to comment.