Skip to content

Commit 9fedbed

Browse files
committed
test: add tests for stripGitHubFromGitPath
1 parent 1810e8d commit 9fedbed

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

test/testProxyRoute.test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { handleMessage, validGitRequest } = require('../src/proxy/routes');
1+
const { handleMessage, validGitRequest, stripGitHubFromGitPath } = require('../src/proxy/routes');
22
const chai = require('chai');
33

44
const expect = chai.expect;
@@ -74,4 +74,41 @@ describe('proxy route helpers', () => {
7474
expect(res).to.be.false;
7575
});
7676
});
77+
78+
describe('stripGitHubFromGitPath', () => {
79+
it('should strip owner and repo from a valid GitHub-style path with 4 parts', () => {
80+
const res = stripGitHubFromGitPath('/foo/bar.git/info/refs');
81+
expect(res).to.equal('/info/refs');
82+
});
83+
84+
it('should strip owner and repo from a valid GitHub-style path with 5 parts', () => {
85+
const res = stripGitHubFromGitPath('/foo/bar.git/git-upload-pack');
86+
expect(res).to.equal('/git-upload-pack');
87+
});
88+
89+
it('should return undefined for malformed path with too few segments', () => {
90+
const res = stripGitHubFromGitPath('/foo/bar.git');
91+
expect(res).to.be.undefined;
92+
});
93+
94+
it('should return undefined for malformed path with too many segments', () => {
95+
const res = stripGitHubFromGitPath('/foo/bar.git/extra/path/stuff');
96+
expect(res).to.be.undefined;
97+
});
98+
99+
it('should handle repo names that include dots correctly', () => {
100+
const res = stripGitHubFromGitPath('/foo/some.repo.git/info/refs');
101+
expect(res).to.equal('/info/refs');
102+
});
103+
104+
it('should not break if the path is just a slash', () => {
105+
const res = stripGitHubFromGitPath('/');
106+
expect(res).to.be.undefined;
107+
});
108+
109+
it('should not break if the path is empty', () => {
110+
const res = stripGitHubFromGitPath('');
111+
expect(res).to.be.undefined;
112+
});
113+
});
77114
});

0 commit comments

Comments
 (0)