40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
|
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||
|
|
import { CastMapper } from '../../ts/integrations/cast/index.js';
|
||
|
|
|
||
|
|
const snapshot = {
|
||
|
|
deviceInfo: {
|
||
|
|
uuid: '1234567890abcdef1234567890abcdef',
|
||
|
|
friendlyName: 'Living Room TV',
|
||
|
|
modelName: 'Chromecast',
|
||
|
|
manufacturer: 'Google',
|
||
|
|
},
|
||
|
|
receiverStatus: {
|
||
|
|
applications: [{ appId: 'CC1AD845', displayName: 'Default Media Receiver', transportId: 'transport-1' }],
|
||
|
|
volume: { level: 0.44, muted: false },
|
||
|
|
isActiveInput: true,
|
||
|
|
},
|
||
|
|
mediaStatus: {
|
||
|
|
mediaSessionId: 1,
|
||
|
|
playerState: 'PLAYING',
|
||
|
|
currentTime: 12,
|
||
|
|
media: {
|
||
|
|
contentId: 'https://example.com/movie.mp4',
|
||
|
|
contentType: 'video/mp4',
|
||
|
|
duration: 120,
|
||
|
|
metadata: { title: 'Sample Movie' },
|
||
|
|
},
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
tap.test('maps Google Cast snapshots to media devices and entities', async () => {
|
||
|
|
const devices = CastMapper.toDevices(snapshot);
|
||
|
|
const entities = CastMapper.toEntities(snapshot);
|
||
|
|
expect(devices[0].id).toEqual('cast.device.1234567890abcdef1234567890abcdef');
|
||
|
|
expect(devices[0].state.some((stateArg) => stateArg.featureId === 'volume' && stateArg.value === 44)).toBeTrue();
|
||
|
|
expect(entities[0].platform).toEqual('media_player');
|
||
|
|
expect(entities[0].state).toEqual('playing');
|
||
|
|
expect(entities[0].attributes?.mediaTitle).toEqual('Sample Movie');
|
||
|
|
});
|
||
|
|
|
||
|
|
export default tap.start();
|