From cb593d50b326621b9e5d67a22d5774931dfbbe86 Mon Sep 17 00:00:00 2001 From: matthieularere-msq Date: Thu, 31 Aug 2023 15:43:42 +0200 Subject: [PATCH] using Set in trackers map --- src/video.js | 8 ++++---- test/spec/video_spec.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/video.js b/src/video.js index 13f036dd1bd..303e15b5a00 100644 --- a/src/video.js +++ b/src/video.js @@ -118,8 +118,8 @@ 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()) } @@ -127,8 +127,8 @@ function trackersToMap(trackers) { 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; } diff --git a/test/spec/video_spec.js b/test/spec/video_spec.js index 8e3db27d81f..eca668b71f5 100644 --- a/test/spec/video_spec.js +++ b/test/spec/video_spec.js @@ -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() { @@ -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; }); });