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
6 changes: 4 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"types": "./src/index.ts",
"scripts": {
"lint": "eslint src/",
"typecheck": "tsc --noEmit"
"typecheck": "tsc --noEmit",
"test": "vitest run"
},
"devDependencies": {
"typescript": "^5.4.0"
"typescript": "^5.4.0",
"vitest": "^2.0.0"
}
}
36 changes: 36 additions & 0 deletions packages/shared/src/__tests__/platforms-url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, it, expect } from 'vitest';
import { getProfileUrl, getWebViewUrl, getDeepLinkUrl } from '../platforms';

describe('getProfileUrl', () => {
it('returns the correct GitHub profile URL', () => {
expect(getProfileUrl('github', 'octocat')).toBe('https://github.com/octocat');
});

it('returns the correct LinkedIn profile URL', () => {
expect(getProfileUrl('linkedin', 'johndoe')).toBe('https://www.linkedin.com/in/johndoe');
});

it('returns empty string for an unknown platform', () => {
expect(getProfileUrl('unknown', 'x')).toBe('');
});
});

describe('getWebViewUrl', () => {
it('returns the LinkedIn webview URL', () => {
expect(getWebViewUrl('linkedin', 'johndoe')).toBe('https://www.linkedin.com/in/johndoe');
});

it('returns null for github (no webview URL)', () => {
expect(getWebViewUrl('github', 'octocat')).toBeNull();
});
});

describe('getDeepLinkUrl', () => {
it('returns the Twitter deep link URL', () => {
expect(getDeepLinkUrl('twitter', 'elonmusk')).toBe('twitter://user?screen_name=elonmusk');
});

it('returns null for github (no deep link)', () => {
expect(getDeepLinkUrl('github', 'octocat')).toBeNull();
});
});
30 changes: 30 additions & 0 deletions packages/shared/src/__tests__/platforms.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, it, expect } from 'vitest';
import { isSupportedPlatform } from '../platforms';

describe('isSupportedPlatform', () => {
it('returns true for github', () => {
expect(isSupportedPlatform('github')).toBe(true);
});

it('returns true for linkedin', () => {
expect(isSupportedPlatform('linkedin')).toBe(true);
});

it('returns false for myspace (unknown platform)', () => {
expect(isSupportedPlatform('myspace')).toBe(false);
});

it('returns false for empty string', () => {
expect(isSupportedPlatform('')).toBe(false);
});

it('returns false for GITHUB (case-sensitive check)', () => {
expect(isSupportedPlatform('GITHUB')).toBe(false);
});

it('returns false for inherited Object prototype keys like toString', () => {
expect(isSupportedPlatform('toString')).toBe(false);
expect(isSupportedPlatform('constructor')).toBe(false);
expect(isSupportedPlatform('__proto__')).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 @@ -274,3 +274,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 registered platform */
export function isSupportedPlatform(id: string): boolean {
return Object.prototype.hasOwnProperty.call(PLATFORMS, id);
}