-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathplatforms.test.ts
More file actions
100 lines (88 loc) · 3.42 KB
/
Copy pathplatforms.test.ts
File metadata and controls
100 lines (88 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { describe, it, expect } from 'vitest';
import {
PLATFORMS,
getAllPlatforms,
getPlatform,
getProfileUrl,
getWebViewUrl,
getDeepLinkUrl,
} from './platforms';
describe('stackoverflow platform', () => {
it('should exist in PLATFORMS registry', () => {
expect(PLATFORMS.stackoverflow).toBeDefined();
});
it('should have correct platform definition', () => {
const so = PLATFORMS.stackoverflow;
expect(so.id).toBe('stackoverflow');
expect(so.name).toBe('Stack Overflow');
expect(so.icon).toBe('stackoverflow');
expect(so.color).toBe('#F58025');
expect(so.urlPattern).toBe('https://stackoverflow.com/users/{username}');
expect(so.followStrategy).toBe('link');
expect(so.deepLinkPattern).toBeNull();
expect(so.webViewUrlPattern).toBeNull();
expect(so.oauthScopes).toEqual([]);
expect(so.usesFullUrl).toBe(false);
expect(so.usernamePlaceholder).toBeTruthy();
});
it('should be included in getAllPlatforms()', () => {
const all = getAllPlatforms();
const so = all.find((p) => p.id === 'stackoverflow');
expect(so).toBeDefined();
expect(so!.name).toBe('Stack Overflow');
});
it('should be retrievable via getPlatform()', () => {
const so = getPlatform('stackoverflow');
expect(so).toBeDefined();
expect(so!.id).toBe('stackoverflow');
});
});
describe('getProfileUrl - stackoverflow', () => {
it('should generate correct URL with user ID and display name', () => {
const url = getProfileUrl('stackoverflow', '1234/user');
expect(url).toBe('https://stackoverflow.com/users/1234/user');
});
it('should generate correct URL with numeric ID only', () => {
const url = getProfileUrl('stackoverflow', '56789');
expect(url).toBe('https://stackoverflow.com/users/56789');
});
it('should return empty string for unknown platform', () => {
const url = getProfileUrl('nonexistent', '1234');
expect(url).toBe('');
});
});
describe('getWebViewUrl / getDeepLinkUrl - stackoverflow', () => {
it('should return null for webViewUrl (not supported)', () => {
expect(getWebViewUrl('stackoverflow', '1234/user')).toBeNull();
});
it('should return null for deepLinkUrl (not supported)', () => {
expect(getDeepLinkUrl('stackoverflow', '1234/user')).toBeNull();
});
});
describe('validationRegex logic', () => {
it('should correctly validate github usernames', () => {
const regex = PLATFORMS.github.validationRegex!;
expect(regex.test('valid-user')).toBe(true);
expect(regex.test('a')).toBe(true);
expect(regex.test('user123')).toBe(true);
expect(regex.test('-invalid')).toBe(false);
expect(regex.test('invalid-')).toBe(false);
expect(regex.test('in--valid')).toBe(false);
expect(regex.test('user name')).toBe(false);
});
it('should correctly validate linkedin usernames', () => {
const regex = PLATFORMS.linkedin.validationRegex!;
expect(regex.test('valid-user')).toBe(true);
expect(regex.test('user123')).toBe(true);
expect(regex.test('ab')).toBe(false);
expect(regex.test('user name')).toBe(false);
});
it('should correctly validate twitter usernames', () => {
const regex = PLATFORMS.twitter.validationRegex!;
expect(regex.test('valid_user')).toBe(true);
expect(regex.test('user123')).toBe(true);
expect(regex.test('user-name')).toBe(false);
expect(regex.test('this_is_a_very_long_name_indeed')).toBe(false);
expect(regex.test('user name')).toBe(false);
});
});