Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/shared/src/__tests__/platforms.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
5 changes: 5 additions & 0 deletions packages/shared/src/platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Comment thread
Satvik-art-creator marked this conversation as resolved.

/** Get the profile URL for a given platform and username */
export function getProfileUrl(platformId: string, username: string): string {
const platform = PLATFORMS[platformId];
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"forceConsistentCasingInFileNames": true,
"declaration": true,
"outDir": "./dist",
"rootDir": "./src"
"rootDir": "./src",
"types": ["vitest/globals"]
},
"include": ["src/**/*"]
}