Repository navigation
Expand file tree
/
Copy pathgithubMapper.test.ts
More file actions
96 lines (81 loc) · 2.99 KB
/
Copy pathgithubMapper.test.ts
File metadata and controls
96 lines (81 loc) · 2.99 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
import { describe, it, expect } from 'vitest';
import { mapGitHubData } from './githubMapper';
import type { GitHubUser, GitHubRepo, GitHubSocialAccount } from './githubMapper';
describe('mapGitHubData', () => {
it('maps simple string fields correctly', () => {
const user: GitHubUser = {
name: 'John Doe',
bio: 'A software engineer',
blog: 'johndoe.com',
twitter_username: 'johndoe',
};
const result = mapGitHubData(user, [], []);
expect(result.name).toBe('John Doe');
expect(result.description).toBe('A software engineer');
expect(result.selectedSocials).toContain('twitter');
expect(result.socialLinks['twitter']).toBe('https://x.com/johndoe');
expect(result.selectedSocials).toContain('website');
expect(result.socialLinks['website']).toBe('https://johndoe.com');
expect(result.selectedSocials).toContain('email');
});
it('handles null values gracefully', () => {
const user: GitHubUser = {
name: null,
bio: null,
blog: null,
twitter_username: null,
email: null,
};
const result = mapGitHubData(user, [], []);
expect(result.name).toBe('');
expect(result.description).toBe('');
expect(result.selectedSocials).toHaveLength(0);
});
it('maps social accounts correctly', () => {
const user: GitHubUser = {
name: null,
bio: null,
blog: null,
twitter_username: null,
email: null,
};
const socialAccounts: GitHubSocialAccount[] = [
{ provider: 'linkedin', url: 'https://linkedin.com/in/johndoe' },
{ provider: 'generic', url: 'https://twitch.tv/johndoe' },
];
const result = mapGitHubData(user, [], socialAccounts);
expect(result.selectedSocials).toContain('linkedin');
expect(result.socialLinks['linkedin']).toBe('https://linkedin.com/in/johndoe');
expect(result.selectedSocials).toContain('twitch');
expect(result.socialLinks['twitch']).toBe('https://twitch.tv/johndoe');
});
it('maps repository languages correctly', () => {
const user: GitHubUser = {
name: null,
bio: null,
blog: null,
twitter_username: null,
email: null,
};
const repos: GitHubRepo[] = [
{ language: 'TypeScript' },
{ language: 'TypeScript' },
{ language: 'JavaScript' },
{ language: 'C++' },
{ language: 'Jupyter Notebook' },
{ language: null },
];
const result = mapGitHubData(user, repos, []);
// Sorted by frequency, so TypeScript should be first
expect(result.selectedTechs).toContain('typescript');
expect(result.selectedTechs).toContain('javascript');
expect(result.selectedTechs).toContain('cplusplus');
expect(result.selectedTechs).toContain('python');
// Order matters - TypeScript has 2, others have 1
expect(result.selectedTechs.indexOf('typescript')).toBeLessThan(
result.selectedTechs.indexOf('javascript')
);
});
});