Skip to content

Commit 11b1a8d

Browse files
feat(shared): add isSupportedPlatform helper and unit tests (#555)
* 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 * 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 * fix(shared): add vitest types to tsconfig for IDE type resolution
1 parent 82a256c commit 11b1a8d

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { isSupportedPlatform, PLATFORMS } from '../platforms';
3+
4+
// ─── isSupportedPlatform Tests ───
5+
6+
describe('isSupportedPlatform', () => {
7+
it('should return true for every registered platform', () => {
8+
for (const id of Object.keys(PLATFORMS)) {
9+
expect(isSupportedPlatform(id)).toBe(true);
10+
}
11+
});
12+
13+
it('should return false for an unknown platform ID', () => {
14+
expect(isSupportedPlatform('nonexistent')).toBe(false);
15+
});
16+
17+
it('should return false for an empty string', () => {
18+
expect(isSupportedPlatform('')).toBe(false);
19+
});
20+
21+
it('should return false for different casing', () => {
22+
expect(isSupportedPlatform('Github')).toBe(false);
23+
});
24+
});

packages/shared/src/platforms.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ export function getPlatform(id: string): PlatformDef | undefined {
272272
return PLATFORMS[id];
273273
}
274274

275+
/** Check whether a platform ID exists in the registry */
276+
export function isSupportedPlatform(id: string): boolean {
277+
return Object.prototype.hasOwnProperty.call(PLATFORMS, id);
278+
}
279+
275280
/** Get the profile URL for a given platform and username */
276281
export function getProfileUrl(platformId: string, username: string): string {
277282
const platform = PLATFORMS[platformId];

packages/shared/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"forceConsistentCasingInFileNames": true,
1010
"declaration": true,
1111
"outDir": "./dist",
12-
"rootDir": "./src"
12+
"rootDir": "./src",
13+
"types": ["vitest/globals"]
1314
},
1415
"include": ["src/**/*"]
1516
}

0 commit comments

Comments
 (0)