Repository navigation
Expand file tree
/
Copy pathparse-url.test.ts
More file actions
48 lines (40 loc) · 1.77 KB
/
Copy pathparse-url.test.ts
File metadata and controls
48 lines (40 loc) · 1.77 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
import { describe, it, expect } from 'bun:test';
import { parseGitHubUrl, parseRepoParams } from './parse-url';
describe('parse-url', () => {
describe('parseGitHubUrl', () => {
it('parses standard https url', () => {
const result = parseGitHubUrl('https://github.com/mbayue/gitSdm');
expect(result).toEqual({ owner: 'mbayue', repo: 'gitSdm' });
});
it('parses url with .git extension', () => {
const result = parseGitHubUrl('https://github.com/mbayue/gitSdm.git');
expect(result).toEqual({ owner: 'mbayue', repo: 'gitSdm' });
});
it('parses owner/repo shorthand format', () => {
const result = parseGitHubUrl('mbayue/gitSdm');
expect(result).toEqual({ owner: 'mbayue', repo: 'gitSdm' });
});
it('returns null for invalid urls', () => {
expect(parseGitHubUrl('https://google.com')).toBeNull();
expect(parseGitHubUrl('not-a-repo')).toBeNull();
});
it('handles git trailing slashes safely', () => {
const result = parseGitHubUrl('https://github.com/mbayue/gitSdm/');
expect(result).toEqual({ owner: 'mbayue', repo: 'gitSdm' });
});
});
describe('parseRepoParams', () => {
it('uses owner and repo if provided', () => {
const result = parseRepoParams('facebook', 'react');
expect(result).toEqual({ owner: 'facebook', repo: 'react' });
});
it('falls back to url if owner and repo are missing', () => {
const result = parseRepoParams(undefined, undefined, 'https://github.com/facebook/react');
expect(result).toEqual({ owner: 'facebook', repo: 'react' });
});
it('returns empty fallback elements if missing parameters and URL is empty', () => {
const result = parseRepoParams(undefined, undefined, '');
expect(result).toBeNull();
});
});
});