Skip to content
Open
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
45 changes: 45 additions & 0 deletions packages/shared/src/__tests__/platforms.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
5 changes: 5 additions & 0 deletions packages/shared/src/platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}