From d4a122978277fd1ba239eddb5bf42266c24c794e Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Tue, 30 Sep 2025 14:17:51 +0200 Subject: [PATCH] update testhandler to only check for id Signed-off-by: Claire Peng --- .../src/__testUtils__/handlers.ts | 35 +++++++------------ .../src/lib/client.test.ts | 17 ++------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts b/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts index 241bc86df6..4f349a1978 100644 --- a/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts +++ b/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts @@ -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')); + }, ); }); diff --git a/plugins/catalog-backend-module-gitlab/src/lib/client.test.ts b/plugins/catalog-backend-module-gitlab/src/lib/client.test.ts index 35107c6e97..60974d2d0f 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/client.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/client.test.ts @@ -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); }); });