update test handlers to simulate checking for both project.id and project.path_with_namespace

Signed-off-by: Claire Peng <clairep@spotify.com>
This commit is contained in:
Claire Peng
2025-09-22 10:37:52 +01:00
parent bdfbee209d
commit 37f540b71d
2 changed files with 33 additions and 18 deletions
@@ -266,24 +266,34 @@ const httpProjectFindByIdDynamic = all_projects_response.map(project => {
return res(ctx.json(all_projects_response.find(p => p.id === project.id)));
});
});
const httpProjectCatalogDynamic = all_projects_response.map(project => {
const path: string = project.path_with_namespace
? project.path_with_namespace!.replace(/\//g, '%2F')
: `${project.path_with_namespace}%2F${project.name}`;
return rest.head(
`${apiBaseUrl}/projects/${path}/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'));
},
/**
* Checks for both project id and namespaced path, as these can both be used for the :id segment in Gitlab API:
* 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'));
},
),
);
});
@@ -580,7 +580,12 @@ describe('hasFile', () => {
});
});
it('should find catalog file', async () => {
it('should find catalog file by id', 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',