-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.test.mjs
More file actions
102 lines (82 loc) · 3.61 KB
/
helpers.test.mjs
File metadata and controls
102 lines (82 loc) · 3.61 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
101
102
/**
* Comprehensive tests for all helper functions in the Lagoon CLI Wrapper
*/
import { gitUrlToGithubUrl, extractPrNumber } from './lagoon-api.mjs';
describe('gitUrlToGithubUrl', () => {
test('should handle empty input', () => {
expect(gitUrlToGithubUrl('')).toBeNull();
});
test('should handle null input', () => {
expect(gitUrlToGithubUrl(null)).toBeNull();
});
test('should handle undefined input', () => {
expect(gitUrlToGithubUrl(undefined)).toBeNull();
});
test('should convert SSH format with username', () => {
expect(gitUrlToGithubUrl('git@github.com:username/repo.git')).toBe('https://github.com/username/repo');
});
test('should convert SSH format with organization', () => {
expect(gitUrlToGithubUrl('git@github.com:org-name/repo-name.git')).toBe('https://github.com/org-name/repo-name');
});
test('should handle HTTPS format correctly', () => {
expect(gitUrlToGithubUrl('https://github.com/user/repo.git')).toBe('https://github.com/user/repo');
});
test('should handle HTTPS format without .git suffix', () => {
expect(gitUrlToGithubUrl('https://github.com/user/repo')).toBe('https://github.com/user/repo');
});
test('should return null for non-GitHub URLs', () => {
expect(gitUrlToGithubUrl('https://gitlab.com/user/repo.git')).toBeNull();
expect(gitUrlToGithubUrl('https://bitbucket.org/user/repo.git')).toBeNull();
expect(gitUrlToGithubUrl('git@gitlab.com:user/repo.git')).toBeNull();
expect(gitUrlToGithubUrl('git@ssh.dev.azure.com:v3/org/project/repo')).toBeNull();
});
test('should handle repo names with dots', () => {
expect(gitUrlToGithubUrl('git@github.com:user/repo.name.git')).toBe('https://github.com/user/repo.name');
});
test('should handle repo names with hyphens', () => {
expect(gitUrlToGithubUrl('git@github.com:user/repo-name.git')).toBe('https://github.com/user/repo-name');
});
test('should handle repo paths with slashes', () => {
expect(gitUrlToGithubUrl('https://github.com/org/project/repo.git')).toBe('https://github.com/org/project/repo');
});
});
describe('extractPrNumber', () => {
test('should handle empty input', () => {
expect(extractPrNumber('')).toBeNull();
});
test('should handle null input', () => {
expect(extractPrNumber(null)).toBeNull();
});
test('should handle undefined input', () => {
expect(extractPrNumber(undefined)).toBeNull();
});
test('should extract simple PR numbers', () => {
expect(extractPrNumber('pr-1')).toBe('1');
expect(extractPrNumber('pr-42')).toBe('42');
expect(extractPrNumber('pr-999')).toBe('999');
});
test('should be case insensitive', () => {
expect(extractPrNumber('PR-123')).toBe('123');
expect(extractPrNumber('Pr-123')).toBe('123');
expect(extractPrNumber('pR-123')).toBe('123');
});
test('should return null for non-PR environment names', () => {
expect(extractPrNumber('master')).toBeNull();
expect(extractPrNumber('develop')).toBeNull();
expect(extractPrNumber('feature/branch')).toBeNull();
expect(extractPrNumber('release-1.0')).toBeNull();
});
test('should not match PR- in the middle of a string', () => {
expect(extractPrNumber('feature-pr-123')).toBeNull();
});
test('should not match without a hyphen', () => {
expect(extractPrNumber('pr123')).toBeNull();
});
test('should handle PR numbers of varying lengths', () => {
expect(extractPrNumber('pr-1')).toBe('1');
expect(extractPrNumber('pr-12')).toBe('12');
expect(extractPrNumber('pr-123')).toBe('123');
expect(extractPrNumber('pr-1234')).toBe('1234');
expect(extractPrNumber('pr-12345')).toBe('12345');
});
});