Skip to content

Commit

Permalink
Merge pull request #140 from MailOnline/next-release
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
carpasse authored Jan 28, 2019
2 parents d39cbd4 + e9bf62c commit 4beb2f7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/adUnit/VpaidAdUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class VpaidAdUnit extends VideoAdUnit {
});
},
[adImpression]: () => {
// NOTE: some ads forget to trigger the adVideoStart event. :(
if (!this[_private].videoStart) {
this[_private].handleVpaidEvt(adVideoStart);
}

this.emit(impression, {
adUnit: this,
type: impression
Expand Down Expand Up @@ -216,11 +221,14 @@ class VpaidAdUnit extends VideoAdUnit {
});
},
[adVideoStart]: () => {
this[_private].paused = false;
this.emit(start, {
adUnit: this,
type: start
});
if (!this[_private].videoStart) {
this[_private].videoStart = true;
this[_private].paused = false;
this.emit(start, {
adUnit: this,
type: start
});
}
},
[adVideoThirdQuartile]: () => {
this.emit(thirdQuartile, {
Expand Down
37 changes: 37 additions & 0 deletions src/adUnit/__tests__/VpaidAdUnit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,43 @@ describe('VpaidAdUnit', () => {
});
});

test('must emit start event once', async () => {
const callback = jest.fn();

adUnit.on(start, callback);
await adUnit.start();

adUnit.creativeAd.emit(adVideoStart);
adUnit.creativeAd.emit(adVideoStart);
adUnit.creativeAd.emit(adVideoStart);
expect(callback).toHaveBeenCalledTimes(1);
});

test('must fake `adVideoStarted` on adImpression if not called already', async () => {
const callback = jest.fn();

adUnit.on(start, callback);
await adUnit.start();

adUnit.creativeAd.emit(adImpression);
expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith({
adUnit,
type: start
});
});

test('must not fake `adVideoStarted` on adImpression if called already', async () => {
const callback = jest.fn();

adUnit.on(start, callback);
await adUnit.start();
adUnit.creativeAd.emit(adVideoStart);
expect(callback).toHaveBeenCalledTimes(1);
adUnit.creativeAd.emit(adImpression);
expect(callback).toHaveBeenCalledTimes(1);
});

describe('paused', () => {
it('must return true if the creative is paused and false otherwise', async () => {
await adUnit.start();
Expand Down

0 comments on commit 4beb2f7

Please sign in to comment.