Skip to content

Commit

Permalink
Add missing unit test cases
Browse files Browse the repository at this point in the history
Co-authored-by: Mukul Mishra <[email protected]>
  • Loading branch information
HalfbyteHeroes and mukulmishra18 committed Dec 4, 2024
1 parent a052cef commit 18710ca
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
14 changes: 14 additions & 0 deletions spec/tests/ConvivaAnalytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,20 @@ describe(ConvivaAnalytics, () => {
Conviva.Constants.ErrorSeverity.WARNING
);
})

it('reports ad break ended when restoring content', () => {
playerEventHelper.fireRestoringContentEvent();

expect(MockHelper.latestVideoAnalytics.reportAdBreakEnded).toHaveBeenCalledTimes(1);
});

it('reports the playback metric on ad finished', () => {
(MockHelper.latestVideoAnalytics.reportPlaybackMetric as jest.Mock).mockReset();

playerEventHelper.fireAdBreakFinishedEvent();

expect(MockHelper.latestVideoAnalytics.reportPlaybackMetric).toHaveBeenCalledTimes(1);
});
});
})

Expand Down
35 changes: 34 additions & 1 deletion spec/tests/ConvivaAnalyticsTracker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,40 @@ describe(ConvivaAnalyticsTracker, () => {
expect(invokedTimesAfter).toBe(invokedTimesBefore);
})

it('should report ad break ended on RestoringContent event', () => {
const { playerMock, playerEventHelper } = MockHelper.createPlayerMock();
const convivaAnalyticsTracker = new ConvivaAnalyticsTracker('test-key');

convivaAnalyticsTracker.attachPlayer(playerMock);
playerEventHelper.firePlayEvent();
convivaAnalyticsTracker.trackRestoringContent();

expect(MockHelper.latestVideoAnalytics.reportAdBreakEnded).toHaveBeenCalledTimes(1);
});

it('should not report the player state on AdBreakFinished events if there is still an active ad', () => {
const { playerMock, playerEventHelper } = MockHelper.createPlayerMock();
const convivaAnalyticsTracker = new ConvivaAnalyticsTracker('test-key');

convivaAnalyticsTracker.attachPlayer(playerMock);
playerEventHelper.fireAdBreakFinishedEvent();
convivaAnalyticsTracker.trackAdBreakFinished();

expect(MockHelper.latestVideoAnalytics.reportPlaybackMetric).not.toHaveBeenCalled();
});

it('should report the player state on AdBreakFinished events if there is no active ad', () => {
const { playerMock, playerEventHelper } = MockHelper.createPlayerMock();
const convivaAnalyticsTracker = new ConvivaAnalyticsTracker('test-key');

convivaAnalyticsTracker.attachPlayer(playerMock);
playerEventHelper.firePlayEvent();
convivaAnalyticsTracker.trackRestoringContent();
convivaAnalyticsTracker.trackAdBreakFinished();

expect(MockHelper.latestVideoAnalytics.reportPlaybackMetric).toHaveBeenCalled();
});

describe('trackPlaybackStateChanged', () => {
let convivaAnalyticsTracker: ConvivaAnalyticsTracker;

Expand Down Expand Up @@ -112,7 +146,6 @@ describe(ConvivaAnalyticsTracker, () => {
PlayerEvent.StallEnded,
PlayerEvent.PlaybackFinished,
PlayerEvent.AdStarted,
PlayerEvent.AdBreakFinished,
])('should clear timer for stalling when reported player event is %s', (event) => {
const stallTrackingStopTimeoutSpy = jest.spyOn(convivaAnalyticsTracker['stallTrackingTimeout'], 'clear');

Expand Down

0 comments on commit 18710ca

Please sign in to comment.