Signed-off-by: Dede Hamzah <dehamzah@gmail.com>
This commit is contained in:
Dede Hamzah
2021-09-21 15:38:49 +07:00
parent 8113ba5ebb
commit 14e01923b4
+46 -1
View File
@@ -47,7 +47,7 @@ describe('gitlab core', () => {
baseUrl: '<ignored>',
};
describe('getGitLabFileFetchUrl', () => {
describe('getGitLabFileFetchUrl with .yaml extension', () => {
it.each([
// Project URLs
{
@@ -91,4 +91,49 @@ describe('gitlab core', () => {
await expect(getGitLabFileFetchUrl(url, config)).resolves.toBe(result);
});
});
describe('getGitLabFileFetchUrl with .yml extension', () => {
it.each([
// Project URLs
{
config: configWithNoToken,
url: 'https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file.yml',
result:
'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile.yml/raw?ref=branch',
},
{
config: configWithNoToken,
// Works with non URI encoded link
url: 'https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file with spaces.yml',
result:
'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile%20with%20spaces.yml/raw?ref=branch',
},
{
config: configWithNoToken,
url: 'https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path%20with%20spaces/to/file.yml',
result:
'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%20with%20spaces%2Fto%2Ffile.yml/raw?ref=branch',
},
{
config: configWithToken,
url: 'https://gitlab.example.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path%20with%20spaces/to/file.yml',
result:
'https://gitlab.example.com/api/v4/projects/12345/repository/files/my%2Fpath%20with%20spaces%2Fto%2Ffile.yml/raw?ref=branch',
},
{
config: configWithNoToken,
url: 'https://gitlab.com/groupA/teams/teamA/repoA/-/blob/branch/my/path%20with%20spaces/to/file.yml', // Repo not in subgroup
result:
'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%20with%20spaces%2Fto%2Ffile.yml/raw?ref=branch',
},
// Raw URLs
{
config: configWithNoToken,
url: 'https://gitlab.example.com/a/b/blob/master/c.yml',
result: 'https://gitlab.example.com/a/b/raw/master/c.yml',
},
])('should handle happy path %#', async ({ config, url, result }) => {
await expect(getGitLabFileFetchUrl(url, config)).resolves.toBe(result);
});
});
});