Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karpov-kir committed May 16, 2024
1 parent c088ab6 commit 92be405
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
30 changes: 17 additions & 13 deletions spec/helper/MockHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,28 @@ import {
SubtitleEvent,
} from 'bitmovin-player';
import { ArrayUtils } from 'bitmovin-player-ui/dist/js/framework/arrayutils';
import * as Conviva from '@convivainc/conviva-js-coresdk';

declare const global: any;
export namespace MockHelper {
export function mockConviva(): void {
global.Conviva = {};
global.Conviva.SystemInterface = jest.fn().mockImplementation();
global.Conviva.SystemSettings = jest.fn().mockImplementation();
global.Conviva.SystemSettings.LogLevel = {
export function createConvivaMock(): typeof Conviva {
const ConvivaMock: Record<string, any> = {};

ConvivaMock.SystemInterface = jest.fn().mockImplementation();
ConvivaMock.SystemSettings = jest.fn().mockImplementation();
ConvivaMock.SystemSettings.LogLevel = {
WARNING: 'warning',
};
global.Conviva.SystemFactory = jest.fn().mockImplementation();
global.Conviva.ClientSettings = jest.fn().mockImplementation();
global.Conviva.ContentMetadata = jest.fn().mockImplementation();
ConvivaMock.SystemFactory = jest.fn().mockImplementation();
ConvivaMock.ClientSettings = jest.fn().mockImplementation();
ConvivaMock.ContentMetadata = jest.fn().mockImplementation();

global.Conviva.ContentMetadata.StreamType = {
ConvivaMock.ContentMetadata.StreamType = {
LIVE: 'live',
VOD: 'vod',
UNKNOWN: 'unknown',
};
global.Conviva.Constants = {
ConvivaMock.Constants = {
DeviceCategory: {
WEB: 'WEB',
},
Expand Down Expand Up @@ -130,15 +132,15 @@ export namespace MockHelper {
const reportAppEvent = jest.fn();

const release = jest.fn();
global.Conviva.Analytics = jest.fn().mockImplementation();
global.Conviva.Analytics = {
ConvivaMock.Analytics = jest.fn().mockImplementation();
ConvivaMock.Analytics = {
init: jest.fn().mockImplementation(),
release: jest.fn().mockImplementation(),
setDeviceMetadata: jest.fn().mockImplementation(),
updateContentMetadata: jest.fn().mockImplementation(),
};

global.Conviva.Analytics.buildVideoAnalytics = jest.fn().mockImplementation(() => {
ConvivaMock.Analytics.buildVideoAnalytics = jest.fn().mockImplementation(() => {
return {
reportPlaybackRequested,
reportPlaybackFailed,
Expand All @@ -156,6 +158,8 @@ export namespace MockHelper {
release,
};
});

return ConvivaMock as typeof Conviva;
}

// Custom cast SDK implementation
Expand Down
7 changes: 5 additions & 2 deletions spec/tests/ContentMetadata.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { PlayerType, StreamType, VRContentType } from 'bitmovin-player';
import { ConvivaAnalytics } from '../../src/ts';
import { MockHelper, TestingPlayerAPI } from '../helper/MockHelper';
import * as Conviva from '@convivainc/conviva-js-coresdk';

jest.mock('@convivainc/conviva-js-coresdk', () => {
const { MockHelper } = jest.requireActual('../helper/MockHelper');
return MockHelper.createConvivaMock();
});
jest.mock('../../src/ts/Html5Logging');

describe('content metadata spec', () => {
Expand All @@ -10,8 +15,6 @@ describe('content metadata spec', () => {
let convivaVideoAnalytics: Conviva.VideoAnalytics;

beforeEach(() => {
MockHelper.mockConviva();

playerMock = MockHelper.getPlayerMock();
convivaVideoAnalytics = Conviva.Analytics.buildVideoAnalytics();

Expand Down
7 changes: 5 additions & 2 deletions spec/tests/ExternalSessionManaging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ConvivaAnalytics } from '../../src/ts';
import { MockHelper, TestingPlayerAPI } from '../helper/MockHelper';
import * as Conviva from '@convivainc/conviva-js-coresdk';

jest.mock('@convivainc/conviva-js-coresdk', () => {
const { MockHelper } = jest.requireActual('../helper/MockHelper');
return MockHelper.createConvivaMock();
});
jest.mock('../../src/ts/Html5Logging');

describe('externally session managing', () => {
Expand All @@ -9,8 +14,6 @@ describe('externally session managing', () => {
let convivaVideoAnalyticsMock: Conviva.VideoAnalytics;

beforeEach(() => {
MockHelper.mockConviva();

playerMock = MockHelper.getPlayerMock();

convivaVideoAnalyticsMock = Conviva.Analytics.buildVideoAnalytics();
Expand Down
8 changes: 6 additions & 2 deletions spec/tests/PlayerEvents.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { MockHelper, TestingPlayerAPI } from '../helper/MockHelper';
import { ConvivaAnalytics } from '../../src/ts';
import * as Conviva from '@convivainc/conviva-js-coresdk';

jest.mock('@convivainc/conviva-js-coresdk', () => {
const { MockHelper } = jest.requireActual('../helper/MockHelper');
return MockHelper.createConvivaMock();
});

describe('player event tests', () => {
let convivaAnalytics: ConvivaAnalytics;
let playerMock: TestingPlayerAPI;
let convivaVideoAnalytics: Conviva.VideoAnalytics;

beforeEach(() => {
MockHelper.mockConviva();

playerMock = MockHelper.getPlayerMock();
convivaVideoAnalytics = Conviva.Analytics.buildVideoAnalytics();

Expand Down

0 comments on commit 92be405

Please sign in to comment.