From d07eb9bdb1e7a7cee90ef6587076a4cc4fbed382 Mon Sep 17 00:00:00 2001 From: evujici Date: Fri, 20 Sep 2024 10:43:20 +0200 Subject: [PATCH] test: when permission are denied --- src/device/device-management.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/device/device-management.spec.ts b/src/device/device-management.spec.ts index bb2d639..3d3d344 100644 --- a/src/device/device-management.spec.ts +++ b/src/device/device-management.spec.ts @@ -14,6 +14,7 @@ import { createMicrophoneStream, getDevices, } from './device-management'; +import { WebrtcCoreError, WebrtcCoreErrorType } from '../errors'; jest.mock('../mocks/media-stream-stub'); @@ -303,5 +304,19 @@ describe('Device Management', () => { const devices = await getDevices(media.DeviceKind.AudioInput); expect(devices).toStrictEqual([{ kind: 'audioinput', deviceId: 'audio1' }]); }); + + it('should throw WebrtcCoreError when device permissions are denied', async () => { + expect.hasAssertions(); + jest.spyOn(media, 'ensureDevicePermissions').mockImplementation(() => { + throw new Error(); + }); + + const expectedError = new WebrtcCoreError( + WebrtcCoreErrorType.DEVICE_PERMISSION_DENIED, + 'Failed to ensure device permissions' + ); + + await expect(getDevices()).rejects.toStrictEqual(expectedError); + }); }); });