update testhandler to only check for id

Signed-off-by: Claire Peng <clairep@spotify.com>
This commit is contained in:
Claire Peng
2025-09-30 14:17:51 +02:00
parent 7be9bd7106
commit d4a1229782
2 changed files with 15 additions and 37 deletions
@@ -272,28 +272,19 @@ const httpProjectFindByIdDynamic = all_projects_response.map(project => {
* https://docs.gitlab.com/api/repository_files/#get-file-from-repository
*/
const httpProjectCatalogDynamic = all_projects_response.flatMap(project => {
const possibleIdSegments: string[] = [
project.id.toString(),
project.path_with_namespace ?? '',
];
return possibleIdSegments.map(seg =>
rest.head(
`${apiBaseUrl}/projects/${encodeURIComponent(
seg,
)}/repository/files/catalog-info.yaml`,
(req, res, ctx) => {
const branch = req.url.searchParams.get('ref');
if (
branch === project.default_branch ||
branch === 'main' ||
branch === 'develop'
) {
return res(ctx.status(200));
}
return res(ctx.status(404, 'Not Found'));
},
),
return rest.head(
`${apiBaseUrl}/projects/${project.id.toString()}/repository/files/catalog-info.yaml`,
(req, res, ctx) => {
const branch = req.url.searchParams.get('ref');
if (
branch === project.default_branch ||
branch === 'main' ||
branch === 'develop'
) {
return res(ctx.status(200));
}
return res(ctx.status(404, 'Not Found'));
},
);
});
@@ -580,26 +580,13 @@ describe('hasFile', () => {
});
});
it('should find catalog file by id', async () => {
it('should find catalog file', async () => {
const hasFile = await client.hasFile(1, 'main', 'catalog-info.yaml');
expect(hasFile).toBe(true);
});
it('should find catalog file by namespace path', async () => {
const hasFile = await client.hasFile(
'group1/test-repo1',
'main',
'catalog-info.yaml',
);
expect(hasFile).toBe(true);
});
it('should not find catalog file', async () => {
const hasFile = await client.hasFile(
'group1/test-repo1',
'unknown',
'catalog-info.yaml',
);
const hasFile = await client.hasFile(1, 'unknown', 'catalog-info.yaml');
expect(hasFile).toBe(false);
});
});