From 6b1b724ec267d5382e423a429aebd6bb2a323c6a Mon Sep 17 00:00:00 2001 From: Satvik Rastogi Date: Fri, 12 Jun 2026 13:16:38 +0530 Subject: [PATCH 1/3] feat(shared): add isSupportedPlatform helper and unit tests - Add exported isSupportedPlatform helper to platforms.ts - Add tests in __tests__/platforms.test.ts for existing and unknown platform IDs Closes #9 --- .../shared/src/__tests__/platforms.test.ts | 40 +++++++++++++++++++ packages/shared/src/platforms.ts | 5 +++ 2 files changed, 45 insertions(+) create mode 100644 packages/shared/src/__tests__/platforms.test.ts diff --git a/packages/shared/src/__tests__/platforms.test.ts b/packages/shared/src/__tests__/platforms.test.ts new file mode 100644 index 00000000..3c5a38fd --- /dev/null +++ b/packages/shared/src/__tests__/platforms.test.ts @@ -0,0 +1,40 @@ +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 true for "github"', () => { + expect(isSupportedPlatform('github')).toBe(true); + }); + + it('should return true for "linkedin"', () => { + expect(isSupportedPlatform('linkedin')).toBe(true); + }); + + it('should return true for "twitter"', () => { + expect(isSupportedPlatform('twitter')).toBe(true); + }); + + it('should return true for "stackoverflow"', () => { + expect(isSupportedPlatform('stackoverflow')).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 a misspelled platform ID', () => { + expect(isSupportedPlatform('Github')).toBe(false); + }); +}); diff --git a/packages/shared/src/platforms.ts b/packages/shared/src/platforms.ts index 81c81ab4..8681710c 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 PLATFORMS[id] !== undefined; +} + /** Get the profile URL for a given platform and username */ export function getProfileUrl(platformId: string, username: string): string { const platform = PLATFORMS[platformId]; From ff7a770aad4a9473f47ec9dfc1f80788f2190965 Mon Sep 17 00:00:00 2001 From: Satvik Rastogi Date: Fri, 12 Jun 2026 13:32:30 +0530 Subject: [PATCH 2/3] fix(shared): address Copilot review feedback on isSupportedPlatform - Use Object.prototype.hasOwnProperty.call for safer own-property check - Remove redundant per-platform assertions covered by the loop test - Rename misleading test description to reflect casing check intent --- .../shared/src/__tests__/platforms.test.ts | 18 +----------------- packages/shared/src/platforms.ts | 2 +- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/packages/shared/src/__tests__/platforms.test.ts b/packages/shared/src/__tests__/platforms.test.ts index 3c5a38fd..baca6e5e 100644 --- a/packages/shared/src/__tests__/platforms.test.ts +++ b/packages/shared/src/__tests__/platforms.test.ts @@ -10,22 +10,6 @@ describe('isSupportedPlatform', () => { } }); - it('should return true for "github"', () => { - expect(isSupportedPlatform('github')).toBe(true); - }); - - it('should return true for "linkedin"', () => { - expect(isSupportedPlatform('linkedin')).toBe(true); - }); - - it('should return true for "twitter"', () => { - expect(isSupportedPlatform('twitter')).toBe(true); - }); - - it('should return true for "stackoverflow"', () => { - expect(isSupportedPlatform('stackoverflow')).toBe(true); - }); - it('should return false for an unknown platform ID', () => { expect(isSupportedPlatform('nonexistent')).toBe(false); }); @@ -34,7 +18,7 @@ describe('isSupportedPlatform', () => { expect(isSupportedPlatform('')).toBe(false); }); - it('should return false for a misspelled platform ID', () => { + 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 8681710c..9c36173b 100644 --- a/packages/shared/src/platforms.ts +++ b/packages/shared/src/platforms.ts @@ -274,7 +274,7 @@ export function getPlatform(id: string): PlatformDef | undefined { /** Check whether a platform ID exists in the registry */ export function isSupportedPlatform(id: string): boolean { - return PLATFORMS[id] !== undefined; + return Object.prototype.hasOwnProperty.call(PLATFORMS, id); } /** Get the profile URL for a given platform and username */ From c6e9f4525ce58b08c83e9b774a3de0384ef53eaf Mon Sep 17 00:00:00 2001 From: Satvik Rastogi Date: Fri, 12 Jun 2026 13:35:05 +0530 Subject: [PATCH 3/3] fix(shared): add vitest types to tsconfig for IDE type resolution --- packages/shared/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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/**/*"] }