|
| 1 | +import { expect, describe, test } from 'vitest' |
| 2 | + |
| 3 | +import { parseBitBucketUrl, parseGitHubUrl } from '../../../src/utils/git' |
| 4 | + |
| 5 | +describe('parseGitHubUrl', () => { |
| 6 | + test('parses a valid GitHub URL with organization and repository', () => { |
| 7 | + const url = 'https://github.com/organization/repository' |
| 8 | + const result = parseGitHubUrl(url) |
| 9 | + expect(result).toEqual({ |
| 10 | + org: 'organization', |
| 11 | + repo: 'repository', |
| 12 | + branch: 'main', |
| 13 | + path: '', |
| 14 | + }) |
| 15 | + }) |
| 16 | + |
| 17 | + test('parses a valid GitHub URL with trailing slash', () => { |
| 18 | + const url = 'https://github.com/organization/repository/' |
| 19 | + const result = parseGitHubUrl(url) |
| 20 | + expect(result).toEqual({ |
| 21 | + org: 'organization', |
| 22 | + repo: 'repository', |
| 23 | + branch: 'main', |
| 24 | + path: '', |
| 25 | + }) |
| 26 | + }) |
| 27 | + |
| 28 | + test('parses a valid GitHub URL with additional path segments', () => { |
| 29 | + const url = 'https://github.com/organization/repository/tree/develop/components' |
| 30 | + const result = parseGitHubUrl(url) |
| 31 | + expect(result).toEqual({ |
| 32 | + org: 'organization', |
| 33 | + repo: 'repository', |
| 34 | + branch: 'develop', |
| 35 | + path: 'components', |
| 36 | + }) |
| 37 | + }) |
| 38 | + |
| 39 | + test('returns null for invalid GitHub URL (missing repository)', () => { |
| 40 | + const url = 'https://github.com/organization' |
| 41 | + const result = parseGitHubUrl(url) |
| 42 | + expect(result).toBeNull() |
| 43 | + }) |
| 44 | + |
| 45 | + test('returns null for non-GitHub URL', () => { |
| 46 | + const url = 'https://gitlab.com/organization/repository' |
| 47 | + const result = parseGitHubUrl(url) |
| 48 | + expect(result).toBeNull() |
| 49 | + }) |
| 50 | + |
| 51 | + test('returns null for malformed URL', () => { |
| 52 | + const url = 'not-a-url' |
| 53 | + const result = parseGitHubUrl(url) |
| 54 | + expect(result).toBeNull() |
| 55 | + }) |
| 56 | + |
| 57 | + test('parses a GitHub URL with feature branch', () => { |
| 58 | + const url = 'https://github.com/organization/repository/tree/feat/something' |
| 59 | + const result = parseGitHubUrl(url) |
| 60 | + expect(result).toEqual({ |
| 61 | + org: 'organization', |
| 62 | + repo: 'repository', |
| 63 | + branch: 'feat/something', |
| 64 | + path: '', |
| 65 | + }) |
| 66 | + }) |
| 67 | + |
| 68 | + test('parses a GitHub URL with feature branch and path', () => { |
| 69 | + const url = 'https://github.com/organization/repository/tree/feat/something/components' |
| 70 | + const result = parseGitHubUrl(url) |
| 71 | + expect(result).toEqual({ |
| 72 | + org: 'organization', |
| 73 | + repo: 'repository', |
| 74 | + branch: 'feat/something', |
| 75 | + path: 'components', |
| 76 | + }) |
| 77 | + }) |
| 78 | +}) |
| 79 | + |
| 80 | +describe('parseBitBucketUrl', () => { |
| 81 | + test('parses a valid BitBucket URL with workspace and repository', () => { |
| 82 | + const url = 'https://bitbucket.org/workspace/repository' |
| 83 | + const result = parseBitBucketUrl(url) |
| 84 | + expect(result).toEqual({ |
| 85 | + org: 'workspace', |
| 86 | + repo: 'repository', |
| 87 | + branch: 'main', |
| 88 | + path: '', |
| 89 | + }) |
| 90 | + }) |
| 91 | + |
| 92 | + test('parses a valid BitBucket URL with trailing slash', () => { |
| 93 | + const url = 'https://bitbucket.org/workspace/repository/' |
| 94 | + const result = parseBitBucketUrl(url) |
| 95 | + expect(result).toEqual({ |
| 96 | + org: 'workspace', |
| 97 | + repo: 'repository', |
| 98 | + branch: 'main', |
| 99 | + path: '', |
| 100 | + }) |
| 101 | + }) |
| 102 | + |
| 103 | + test('parses a valid BitBucket URL with additional path segments', () => { |
| 104 | + const url = 'https://bitbucket.org/workspace/repository/src/develop/components' |
| 105 | + const result = parseBitBucketUrl(url) |
| 106 | + expect(result).toEqual({ |
| 107 | + org: 'workspace', |
| 108 | + repo: 'repository', |
| 109 | + branch: 'develop', |
| 110 | + path: 'components', |
| 111 | + }) |
| 112 | + }) |
| 113 | + |
| 114 | + test('returns null for invalid BitBucket URL (missing repository)', () => { |
| 115 | + const url = 'https://bitbucket.org/workspace' |
| 116 | + const result = parseBitBucketUrl(url) |
| 117 | + expect(result).toBeNull() |
| 118 | + }) |
| 119 | + |
| 120 | + test('returns null for non-BitBucket URL', () => { |
| 121 | + const url = 'https://github.com/organization/repository' |
| 122 | + const result = parseBitBucketUrl(url) |
| 123 | + expect(result).toBeNull() |
| 124 | + }) |
| 125 | + |
| 126 | + test('returns null for malformed URL', () => { |
| 127 | + const url = 'not-a-url' |
| 128 | + const result = parseBitBucketUrl(url) |
| 129 | + expect(result).toBeNull() |
| 130 | + }) |
| 131 | + |
| 132 | + test('parses a BitBucket URL with feature branch', () => { |
| 133 | + const url = 'https://bitbucket.org/organization/repository/src/feat/something' |
| 134 | + const result = parseBitBucketUrl(url) |
| 135 | + expect(result).toEqual({ |
| 136 | + org: 'organization', |
| 137 | + repo: 'repository', |
| 138 | + branch: 'feat/something', |
| 139 | + path: '', |
| 140 | + }) |
| 141 | + }) |
| 142 | + |
| 143 | + test('parses a BitBucket URL with feature branch and path', () => { |
| 144 | + const url = 'https://bitbucket.org/organization/repository/src/feat/something/components' |
| 145 | + const result = parseBitBucketUrl(url) |
| 146 | + expect(result).toEqual({ |
| 147 | + org: 'organization', |
| 148 | + repo: 'repository', |
| 149 | + branch: 'feat/something', |
| 150 | + path: 'components', |
| 151 | + }) |
| 152 | + }) |
| 153 | +}) |
0 commit comments