Skip to content

Commit

Permalink
Update VideoData interface (#54)
Browse files Browse the repository at this point in the history
* Updated the function definitions for getAvailableTimeRanges(), triggerLiveVideoUpload() and triggerOnDemandVideoUploadRequest()
* Removed unnecessary try-catch blocks
  • Loading branch information
mukeshsahay authored Aug 15, 2022
1 parent faacba5 commit 8cc5e18
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 196 deletions.
53 changes: 26 additions & 27 deletions packages/source-iottwinmaker/src/__mocks__/MockVideoPlayerProps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GetDataEndpointOutput } from '@aws-sdk/client-kinesis-video';
import {
import {
BatchPutAssetPropertyValueResponse,
GetAssetPropertyValueRequest,
GetAssetPropertyValueResponse,
Expand All @@ -26,41 +26,41 @@ export const mockOnDemandGetHLSStreamingSessionURLResponse = { HLSStreamingSessi
export const mockSitewiseAssetId = 'mockSitewiseAssetId';
export const mockVideoUploadRequestPropertyId = 'mockVideoUploadRequestPropertyId';
export const batchPutAssetPropertyResponse: BatchPutAssetPropertyValueResponse = {
errorEntries: [{ entryId: 'test', errors: [] }],
errorEntries: [{ entryId: 'test', errors: [] }],
};
export const mockGetAssetPropertyValueRequest: GetAssetPropertyValueRequest = {
assetId: mockAssetId,
propertyId: mockPropertyId,
};
export const mockGetAssetPropertyValue: Primitive | undefined = 'test-video-stream';
export const mockGetAssetPropertyValueResponse: GetAssetPropertyValueResponse = {
propertyValue: {
value: {
stringValue: 'test-video-stream',
},
timestamp: {
timeInSeconds: 1234567890,
},
propertyValue: {
value: {
stringValue: 'test-video-stream',
},
timestamp: {
timeInSeconds: 1234567890,
},
},
};
export const mockGetInterpolatedAssetPropertyValuesResponse: GetInterpolatedAssetPropertyValuesResponse = {
interpolatedAssetPropertyValues: [
{
timestamp: {
timeInSeconds: 1630004199,
offsetInNanos: 0,
},
value: {
doubleValue: 1630005400.0,
},
interpolatedAssetPropertyValues: [
{
timestamp: {
timeInSeconds: 1630004199,
offsetInNanos: 0,
},
value: {
doubleValue: 1630005400.0,
},
],
},
],
};

export const mockAWSCredentials: Credentials = {
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
sessionToken: 'sessionToken',
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
sessionToken: 'sessionToken',
};

export const mockEntityPropertyReference = {
Expand Down Expand Up @@ -295,14 +295,13 @@ export const mockGetAvailableTimeRangeResponse = [
{ start: 1630005400000, end: 1630005600000 },
{ start: 1630005800000, end: 1630005900000 },
],
'',
];

export const mockGetPropertyValueHistoryRequest: GetPropertyValueHistoryRequest = {
workspaceId: mockWorkspaceId,
entityId: mockEntityId,
componentName: mockComponentName,
entityId: mockEntityId,
componentName: mockComponentName,
selectedProperties: [mockPropertyId],
startTime: (new Date()).toISOString(),
endTime: (new Date()).toISOString(),
startTime: (new Date()).toISOString(),
endTime: (new Date()).toISOString(),
};
6 changes: 3 additions & 3 deletions packages/source-iottwinmaker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export interface VideoData {
getAvailableTimeRanges: (
startTime: Date,
endTime: Date
) => Promise<[{ start: number; end: number; src: string }[], { start: number; end: number }[], string] | undefined>;
triggerLiveVideoUpload: () => Promise<boolean>;
triggerOnDemandVideoUploadRequest: (startTimestamp: string, endTimestamp: string) => Promise<boolean>;
) => Promise<[{ start: number; end: number; src: string }[], { start: number; end: number }[]] | undefined>;
triggerLiveVideoUpload: () => Promise<void>;
triggerOnDemandVideoUploadRequest: (startTimestamp: string, endTimestamp: string) => Promise<void>;
}

export type VideoDataProps =
Expand Down
45 changes: 6 additions & 39 deletions packages/source-iottwinmaker/src/video-data/VideoData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,13 @@ describe('Test VideoData class', () => {
});

it('Test successful triggerLiveVideoUpload()', async () => {
const response = await videoDataSimpleMode.triggerLiveVideoUpload();
expect(response).toEqual(true);
});

it('Test failed triggerLiveVideoUpload()', async () => {
siteWiseClientMock.on(BatchPutAssetPropertyValueCommand).rejects(new Error());
const response = await videoDataSimpleMode.triggerLiveVideoUpload();
expect(response).toEqual(false);
expect(() => videoDataSimpleMode.triggerLiveVideoUpload()).not.toThrow();
});

it('Test successful triggerOnDemandVideoUploadRequest()', async () => {
const response = await videoDataSimpleMode.triggerOnDemandVideoUploadRequest(
new Date().toISOString(),
new Date().toISOString()
);
expect(response).toEqual(true);
});

it('Test failed triggerOnDemandVideoUploadRequest()', async () => {
siteWiseClientMock.on(BatchPutAssetPropertyValueCommand).rejects(new Error());
const response = await videoDataSimpleMode.triggerOnDemandVideoUploadRequest(
new Date().toISOString(),
new Date().toISOString()
);
expect(response).toEqual(false);
expect(() =>
videoDataSimpleMode.triggerOnDemandVideoUploadRequest(new Date().toISOString(), new Date().toISOString())
).not.toThrow();
});

it('Fetch KVS stream source for LIVE playback - Simple Mode', async () => {
Expand Down Expand Up @@ -192,8 +174,8 @@ describe('Test VideoData class', () => {
twinMakerClientMock.on(GetEntityCommand).resolves(mockEdgeVideoEntity);
twinMakerClientMock
.on(GetPropertyValueHistoryCommand)
.resolvesOnce(mockVideoUploadedTimeRange)
.resolves(mockCachedVideoAgeOutOnEdge);
.resolvesOnce(mockCachedVideoAgeOutOnEdge)
.resolves(mockVideoUploadedTimeRange);
siteWiseClientMock
.on(GetInterpolatedAssetPropertyValuesCommand)
.resolves(mockGetInterpolatedAssetPropertyValuesResponse);
Expand All @@ -202,19 +184,4 @@ describe('Test VideoData class', () => {
expect(kvsStreamSrc).toEqual(mockOnDemandURL);
expect(response).toEqual(mockGetAvailableTimeRangeResponse);
});

it('Exception while getting available time ranges', async () => {
kinesisVideoArchivedMediaClientMock
.on(GetHLSStreamingSessionURLCommand)
.resolves(mockOnDemandGetHLSStreamingSessionURLResponse);
twinMakerClientMock.on(GetEntityCommand).resolves(mockEdgeVideoEntity);
twinMakerClientMock.on(GetPropertyValueHistoryCommand).rejects(new Error('ErrorInGetPropertyValueHistoryCommand'));
siteWiseClientMock
.on(GetInterpolatedAssetPropertyValuesCommand)
.resolves(mockGetInterpolatedAssetPropertyValuesResponse);
const kvsStreamSrc = await videoData.getKvsStreamSrc(PLAYBACKMODE_ON_DEMAND);
const response = await videoData.getAvailableTimeRanges(new Date(), new Date());
expect(kvsStreamSrc).toEqual(mockOnDemandURL);
expect(response).toEqual([[], [], new Error('ErrorInGetPropertyValueHistoryCommand')]);
});
});
Loading

0 comments on commit 8cc5e18

Please sign in to comment.