From 41f882256703c55e01cac05c60d91c1bf29f5c3a Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Thu, 8 May 2025 12:06:15 +0200 Subject: [PATCH] test: Add type checks for LiveKitPermissions and VideoGrant interfaces --- .../unit/typings/livekit-video-grants.test.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 backend/tests/unit/typings/livekit-video-grants.test.ts diff --git a/backend/tests/unit/typings/livekit-video-grants.test.ts b/backend/tests/unit/typings/livekit-video-grants.test.ts new file mode 100644 index 0000000..f4633ca --- /dev/null +++ b/backend/tests/unit/typings/livekit-video-grants.test.ts @@ -0,0 +1,40 @@ +import { describe, it, expect } from '@jest/globals'; +import { VideoGrant } from 'livekit-server-sdk'; +import { LiveKitPermissions } from '../../../src/typings/ce/index.js'; + +// 1) Extract the keys from each interface using keyof +type KeysLiveKit = keyof LiveKitPermissions; +type KeysVideo = keyof VideoGrant; + +// 2) Calculate the differences between the interfaces +type OnlyInLiveKit = Exclude; // Properties only in LiveKitPermissions +type OnlyInVideo = Exclude; // Properties only in VideoGrant +type SymmetricDiff = OnlyInLiveKit | OnlyInVideo; // All properties that differ between interfaces + +// 3) Type assertion that forces SymmetricDiff to be 'never' +// If interfaces have different properties, this will cause a compile error +type AssertNoDiff = T; +type Assert = AssertNoDiff; + +// 4) Additional bi-directional assignability check +// These will fail if property types don't match exactly +type AssertLiveKitIsVideoGrant = LiveKitPermissions extends VideoGrant ? true : never; +type AssertVideoGrantIsLiveKit = VideoGrant extends LiveKitPermissions ? true : never; +type BiDirectionalCheck = [AssertLiveKitIsVideoGrant, AssertVideoGrantIsLiveKit]; + +// 5) Check individual property types for exact matches +type CheckPropertyTypes = LiveKitPermissions[K & + keyof LiveKitPermissions] extends VideoGrant[K & keyof VideoGrant] + ? VideoGrant[K & keyof VideoGrant] extends LiveKitPermissions[K & keyof LiveKitPermissions] + ? true + : never + : never; + +// Apply the check to all properties +type PropertyTypeCheck = { [K in KeysVideo]: CheckPropertyTypes }; + +describe('OpenVidu Meet LiveKitPermissions type', () => { + it('should have identical properties to VideoGrant', () => { + expect(true).toBe(true); // Test passes if compilation succeeds + }); +});