diff --git a/packages/shared/src/__tests__/platforms.test.ts b/packages/shared/src/__tests__/platforms.test.ts new file mode 100644 index 00000000..baca6e5e --- /dev/null +++ b/packages/shared/src/__tests__/platforms.test.ts @@ -0,0 +1,24 @@ +import { describe, it, expect } from 'vitest'; +import { isSupportedPlatform, PLATFORMS } from '../platforms'; + +// ─── isSupportedPlatform Tests ─── + +describe('isSupportedPlatform', () => { + it('should return true for every registered platform', () => { + for (const id of Object.keys(PLATFORMS)) { + expect(isSupportedPlatform(id)).toBe(true); + } + }); + + it('should return false for an unknown platform ID', () => { + expect(isSupportedPlatform('nonexistent')).toBe(false); + }); + + it('should return false for an empty string', () => { + expect(isSupportedPlatform('')).toBe(false); + }); + + it('should return false for different casing', () => { + expect(isSupportedPlatform('Github')).toBe(false); + }); +}); diff --git a/packages/shared/src/platforms.ts b/packages/shared/src/platforms.ts index 81c81ab4..9c36173b 100644 --- a/packages/shared/src/platforms.ts +++ b/packages/shared/src/platforms.ts @@ -272,6 +272,11 @@ export function getPlatform(id: string): PlatformDef | undefined { return PLATFORMS[id]; } +/** Check whether a platform ID exists in the registry */ +export function isSupportedPlatform(id: string): boolean { + return Object.prototype.hasOwnProperty.call(PLATFORMS, id); +} + /** Get the profile URL for a given platform and username */ export function getProfileUrl(platformId: string, username: string): string { const platform = PLATFORMS[platformId]; diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index 771659c0..1397cd1f 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -9,7 +9,8 @@ "forceConsistentCasingInFileNames": true, "declaration": true, "outDir": "./dist", - "rootDir": "./src" + "rootDir": "./src", + "types": ["vitest/globals"] }, "include": ["src/**/*"] }