Skip to content

Commit 2807bea

Browse files
committed
additional tests for sanitizeRepoPathSsh()
1 parent 4cc507a commit 2807bea

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

tests/GitHelper.test.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,48 @@ test('Testing - sanitizeRepoPathSsh from HTTPS', () => {
4848
).toBe('ssh://git@github.com:22/username/repository.git')
4949
})
5050

51+
test('Testing - sanitizeRepoPathSsh - not git suffix', () => {
52+
expect(
53+
GitHelper.sanitizeRepoPathSsh(' github.com/owner/repository ').repoPath
54+
).toBe('ssh://git@github.com:22/owner/repository.git')
55+
})
56+
5157
test('Testing - sanitizeRepoPathSsh - alt domain', () => {
5258
expect(
5359
GitHelper.sanitizeRepoPathSsh(
54-
' https://gitea@git.alt-domain.com:2221/username/repository/ '
60+
' git@git.alt-domain.com/owner/repository.git/ '
5561
).repoPath
56-
).toBe('ssh://gitea@git.alt-domain.com:2221/username/repository.git')
62+
).toBe('ssh://git@git.alt-domain.com:22/owner/repository.git')
5763
})
5864

59-
test('Testing - sanitizeRepoPathSsh - no owner', () => {
65+
test('Testing - sanitizeRepoPathSsh - alt user', () => {
6066
expect(
6167
GitHelper.sanitizeRepoPathSsh(
62-
' foo@git.alt-domain.com:repository.git '
68+
' foobar@github.com/owner/repository.git/ '
6369
).repoPath
64-
).toBe('ssh://foo@git.alt-domain.com:22/repository.git')
70+
).toBe('ssh://foobar@github.com:22/owner/repository.git')
71+
})
72+
73+
test('Testing - sanitizeRepoPathSsh - default user', () => {
74+
expect(
75+
GitHelper.sanitizeRepoPathSsh(' github.com/owner/repository.git/ ')
76+
.repoPath
77+
).toBe('ssh://git@github.com:22/owner/repository.git')
78+
})
79+
80+
test('Testing - sanitizeRepoPathSsh - no owner', () => {
81+
expect(
82+
GitHelper.sanitizeRepoPathSsh(' git@github.com:repository.git/ ')
83+
.repoPath
84+
).toBe('ssh://git@github.com:22/repository.git')
85+
})
86+
87+
test('Testing - sanitizeRepoPathSsh - invalid url', () => {
88+
expect(() =>
89+
GitHelper.sanitizeRepoPathSsh(
90+
' git:password@github.com/owner/repository.git/ '
91+
)
92+
).toThrow(Error)
6593
})
6694

6795
test('Testing - getDomainFromSanitizedSshRepoPath - pure', () => {
@@ -95,7 +123,7 @@ test('Testing - getDomainFromSanitizedSshRepoPath from HTTPS', () => {
95123
test('Testing - getDomainFromSanitizedSshRepoPath - alt domain', () => {
96124
expect(
97125
GitHelper.getDomainFromSanitizedSshRepoPath(
98-
' ssh://user@some.do-main.com/owner/repository.git/ '
126+
' ssh://user@some.other-domain.com/owner/repository.git/ '
99127
)
100-
).toBe('some.do-main.com')
101-
})
128+
).toBe('some.other-domain.com')
129+
})

0 commit comments

Comments
 (0)