Skip to content

Commit 7a3e719

Browse files
Add (#70)
1 parent 9e3a6d2 commit 7a3e719

4 files changed

Lines changed: 96 additions & 2 deletions

File tree

packages/shared/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
"types": "./src/index.ts",
88
"scripts": {
99
"lint": "eslint src/",
10-
"typecheck": "tsc --noEmit"
10+
"typecheck": "tsc --noEmit",
11+
"test": "vitest run"
1112
},
1213
"devDependencies": {
13-
"typescript": "^5.4.0"
14+
"typescript": "^5.4.0",
15+
"vitest": "^2.0.0"
1416
}
1517
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { describe, it, expect } from 'vitest';
2+
import {
3+
PLATFORMS,
4+
getAllPlatforms,
5+
getPlatform,
6+
getProfileUrl,
7+
getWebViewUrl,
8+
getDeepLinkUrl,
9+
} from './platforms';
10+
11+
// ─── StackOverflow Platform Tests ───
12+
13+
describe('stackoverflow platform', () => {
14+
it('should exist in PLATFORMS registry', () => {
15+
expect(PLATFORMS.stackoverflow).toBeDefined();
16+
});
17+
18+
it('should have correct platform definition', () => {
19+
const so = PLATFORMS.stackoverflow;
20+
expect(so.id).toBe('stackoverflow');
21+
expect(so.name).toBe('Stack Overflow');
22+
expect(so.icon).toBe('stackoverflow');
23+
expect(so.color).toBe('#F58025');
24+
expect(so.urlPattern).toBe('https://stackoverflow.com/users/{username}');
25+
expect(so.followStrategy).toBe('link');
26+
expect(so.deepLinkPattern).toBeNull();
27+
expect(so.webViewUrlPattern).toBeNull();
28+
expect(so.oauthScopes).toEqual([]);
29+
expect(so.usesFullUrl).toBe(false);
30+
expect(so.usernamePlaceholder).toBeTruthy();
31+
});
32+
33+
it('should be included in getAllPlatforms()', () => {
34+
const all = getAllPlatforms();
35+
const so = all.find((p) => p.id === 'stackoverflow');
36+
expect(so).toBeDefined();
37+
expect(so!.name).toBe('Stack Overflow');
38+
});
39+
40+
it('should be retrievable via getPlatform()', () => {
41+
const so = getPlatform('stackoverflow');
42+
expect(so).toBeDefined();
43+
expect(so!.id).toBe('stackoverflow');
44+
});
45+
});
46+
47+
// ─── getProfileUrl Tests for StackOverflow ───
48+
49+
describe('getProfileUrl – stackoverflow', () => {
50+
it('should generate correct URL with user ID and display name', () => {
51+
const url = getProfileUrl('stackoverflow', '1234/user');
52+
expect(url).toBe('https://stackoverflow.com/users/1234/user');
53+
});
54+
55+
it('should generate correct URL with numeric ID only', () => {
56+
const url = getProfileUrl('stackoverflow', '56789');
57+
expect(url).toBe('https://stackoverflow.com/users/56789');
58+
});
59+
60+
it('should return empty string for unknown platform', () => {
61+
const url = getProfileUrl('nonexistent', '1234');
62+
expect(url).toBe('');
63+
});
64+
});
65+
66+
// ─── getWebViewUrl / getDeepLinkUrl for StackOverflow ───
67+
68+
describe('getWebViewUrl / getDeepLinkUrl – stackoverflow', () => {
69+
it('should return null for webViewUrl (not supported)', () => {
70+
expect(getWebViewUrl('stackoverflow', '1234/user')).toBeNull();
71+
});
72+
73+
it('should return null for deepLinkUrl (not supported)', () => {
74+
expect(getDeepLinkUrl('stackoverflow', '1234/user')).toBeNull();
75+
});
76+
});

packages/shared/src/platforms.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ export const PLATFORMS: Record<string, PlatformDef> = {
175175
usernamePlaceholder: 'e.g. hacker',
176176
usesFullUrl: false,
177177
},
178+
stackoverflow: {
179+
id: 'stackoverflow',
180+
name: 'Stack Overflow',
181+
icon: 'stackoverflow',
182+
color: '#F58025',
183+
urlPattern: 'https://stackoverflow.com/users/{username}',
184+
deepLinkPattern: null,
185+
webViewUrlPattern: null,
186+
followStrategy: 'link',
187+
oauthScopes: [],
188+
usernamePlaceholder: 'e.g. 1234/username',
189+
usesFullUrl: false,
190+
},
178191
discord: {
179192
id: 'discord',
180193
name: 'Discord',

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)