diff --git a/packages/shared/src/__tests__/platforms.test.ts b/packages/shared/src/__tests__/platforms.test.ts new file mode 100644 index 0000000..dace5a0 --- /dev/null +++ b/packages/shared/src/__tests__/platforms.test.ts @@ -0,0 +1,45 @@ +import { describe, it, expect } from 'vitest'; +import { isSupportedPlatform } from '../platforms'; + +// ─── isSupportedPlatform Tests ─── + +describe('isSupportedPlatform', () => { + it('returns true for known platform: github', () => { + expect(isSupportedPlatform('github')).toBe(true); + }); + + it('returns true for known platform: linkedin', () => { + expect(isSupportedPlatform('linkedin')).toBe(true); + }); + + it('returns true for known platform: twitter', () => { + expect(isSupportedPlatform('twitter')).toBe(true); + }); + + it('returns true for known platform: discord', () => { + expect(isSupportedPlatform('discord')).toBe(true); + }); + + it('returns true for known platform: email', () => { + expect(isSupportedPlatform('email')).toBe(true); + }); + + it('returns false for unknown platform id', () => { + expect(isSupportedPlatform('unknown-platform')).toBe(false); + }); + + it('returns false for empty string', () => { + expect(isSupportedPlatform('')).toBe(false); + }); + + it('returns false for near-miss platform names', () => { + expect(isSupportedPlatform('Github')).toBe(false); + expect(isSupportedPlatform('GITHUB')).toBe(false); + expect(isSupportedPlatform('git hub')).toBe(false); + }); + + it('returns a boolean value (not truthy/falsy)', () => { + expect(typeof isSupportedPlatform('github')).toBe('boolean'); + expect(typeof isSupportedPlatform('nope')).toBe('boolean'); + }); +}); diff --git a/packages/shared/src/platforms.ts b/packages/shared/src/platforms.ts index 81c81ab..aa7ce0b 100644 --- a/packages/shared/src/platforms.ts +++ b/packages/shared/src/platforms.ts @@ -292,3 +292,8 @@ export function getDeepLinkUrl(platformId: string, username: string): string | n if (!platform?.deepLinkPattern) return null; return platform.deepLinkPattern.replace(/{username}/g, username); } + +/** Returns true if the given ID corresponds to a known platform */ +export function isSupportedPlatform(id: string): boolean { + return PLATFORMS[id] !== undefined; +}