|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | | -import { parseRepositoryInfo, type RepositoryInfo } from '#shared/utils/git-providers' |
| 2 | +import { |
| 3 | + normalizeGitUrl, |
| 4 | + parseRepositoryInfo, |
| 5 | + type RepositoryInfo, |
| 6 | +} from '#shared/utils/git-providers' |
| 7 | + |
| 8 | +describe('normalizeGitUrl', () => { |
| 9 | + it('should return null for empty input', () => { |
| 10 | + expect.soft(normalizeGitUrl('')).toBeNull() |
| 11 | + }) |
| 12 | + |
| 13 | + it('should leave plain HTTPS URLs unchanged', () => { |
| 14 | + expect |
| 15 | + .soft(normalizeGitUrl('https://github.com/user/repo')) |
| 16 | + .toBe('https://github.com/user/repo') |
| 17 | + }) |
| 18 | + |
| 19 | + it('should remove git+ prefix', () => { |
| 20 | + expect |
| 21 | + .soft(normalizeGitUrl('git+https://github.com/user/repo')) |
| 22 | + .toBe('https://github.com/user/repo') |
| 23 | + expect |
| 24 | + .soft(normalizeGitUrl('git+https://github.com/user/repo.git')) |
| 25 | + .toBe('https://github.com/user/repo') |
| 26 | + expect |
| 27 | + .soft(normalizeGitUrl('git+ssh://git@github.com/user/repo.git')) |
| 28 | + .toBe('https://github.com/user/repo') |
| 29 | + }) |
| 30 | + |
| 31 | + it('should remove .git suffix', () => { |
| 32 | + expect |
| 33 | + .soft(normalizeGitUrl('https://github.com/user/repo.git')) |
| 34 | + .toBe('https://github.com/user/repo') |
| 35 | + expect |
| 36 | + .soft(normalizeGitUrl('https://gitlab.com/user/repo.git')) |
| 37 | + .toBe('https://gitlab.com/user/repo') |
| 38 | + expect |
| 39 | + .soft(normalizeGitUrl('https://bitbucket.org/user/repo.git')) |
| 40 | + .toBe('https://bitbucket.org/user/repo') |
| 41 | + }) |
| 42 | + |
| 43 | + it('should convert git:// protocol to https://', () => { |
| 44 | + expect.soft(normalizeGitUrl('git://github.com/user/repo')).toBe('https://github.com/user/repo') |
| 45 | + expect |
| 46 | + .soft(normalizeGitUrl('git://github.com/user/repo.git')) |
| 47 | + .toBe('https://github.com/user/repo') |
| 48 | + }) |
| 49 | + |
| 50 | + it('should convert ssh:// protocol to https://', () => { |
| 51 | + expect |
| 52 | + .soft(normalizeGitUrl('ssh://git@github.com/user/repo')) |
| 53 | + .toBe('https://github.com/user/repo') |
| 54 | + expect |
| 55 | + .soft(normalizeGitUrl('ssh://git@github.com/user/repo.git')) |
| 56 | + .toBe('https://github.com/user/repo') |
| 57 | + }) |
| 58 | + |
| 59 | + it('should convert SSH format to https://', () => { |
| 60 | + expect.soft(normalizeGitUrl('git@github.com:user/repo')).toBe('https://github.com/user/repo') |
| 61 | + expect |
| 62 | + .soft(normalizeGitUrl('git@github.com:user/repo.git')) |
| 63 | + .toBe('https://github.com/user/repo') |
| 64 | + expect |
| 65 | + .soft(normalizeGitUrl('git@github.com/user/repo:123')) |
| 66 | + .toBe('https://github.com/user/repo:123') |
| 67 | + }) |
| 68 | + |
| 69 | + it('should handle combined permutations', () => { |
| 70 | + expect |
| 71 | + .soft(normalizeGitUrl('git+git://github.com/user/repo.git')) |
| 72 | + .toBe('https://github.com/user/repo') |
| 73 | + expect |
| 74 | + .soft(normalizeGitUrl('git+ssh://git@gitlab.com/user/repo.git')) |
| 75 | + .toBe('https://gitlab.com/user/repo') |
| 76 | + }) |
| 77 | +}) |
3 | 78 |
|
4 | 79 | describe('parseRepositoryInfo', () => { |
5 | 80 | it('returns undefined for undefined input', () => { |
|
0 commit comments