Skip to content

Commit 5a871e4

Browse files
committed
test(bulk-import): add repository filtering tests for GitLab integration
Signed-off-by: Dominik Augustín <daugusti@redhat.com>
1 parent 52e22ca commit 5a871e4

1 file changed

Lines changed: 195 additions & 1 deletion

File tree

workspaces/bulk-import/plugins/bulk-import-backend/src/service/handlers/repository/repositories-gitlab.test.ts

Lines changed: 195 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { AuthorizeResult } from '@backstage/plugin-permission-common';
1919
import { rest } from 'msw';
2020
import request from 'supertest';
2121

22-
import { LOCAL_ADDR } from '../../../../__fixtures__/handlers';
22+
import {
23+
CATALOG_API_LOCATIONS_LOCAL_ADDR,
24+
LOCAL_ADDR,
25+
} from '../../../../__fixtures__/handlers';
2326
import {
2427
setupTest,
2528
startBackendServer,
@@ -104,6 +107,197 @@ describe('repositories', () => {
104107
errors: ['Gitlab Token auth did not succeed'],
105108
});
106109
});
110+
111+
describe('filtering repositories', () => {
112+
it('returns all repos when no repos are imported yet', async () => {
113+
const { mockCatalogClient } = useTestData();
114+
115+
const backendServer = await startBackendServer(
116+
mockCatalogClient,
117+
AuthorizeResult.ALLOW,
118+
);
119+
120+
const response = await request(backendServer)
121+
.get('/api/bulk-import/repositories')
122+
.query({ approvalTool: 'GITLAB' });
123+
124+
expect(response.status).toEqual(200);
125+
expect(response.body).toEqual({
126+
approvalTool: 'GITLAB',
127+
errors: [],
128+
repositories: [
129+
{
130+
defaultBranch: 'main',
131+
errors: [],
132+
id: 'saltypig1/dolbear',
133+
lastUpdate: '2025-07-31T14:52:27.849Z',
134+
name: 'dolbear',
135+
organization: 'saltypig1',
136+
url: 'http://localhost:8765/saltypig1/dolbear',
137+
},
138+
{
139+
defaultBranch: 'main',
140+
errors: [],
141+
id: 'saltypig1/funtimes',
142+
lastUpdate: '2025-08-15T15:03:44.927Z',
143+
name: 'funtimes',
144+
organization: 'saltypig1',
145+
url: 'http://localhost:8765/saltypig1/funtimes',
146+
},
147+
{
148+
defaultBranch: 'main',
149+
errors: [],
150+
id: 'saltypig1/swapi-node',
151+
lastUpdate: '2025-07-31T14:54:57.289Z',
152+
name: 'swapi-node',
153+
organization: 'saltypig1',
154+
url: 'http://localhost:8765/saltypig1/swapi-node',
155+
},
156+
],
157+
totalCount: 3,
158+
});
159+
});
160+
161+
it('returns empty array when there are no repos to be imported', async () => {
162+
const { server, mockCatalogClient } = useTestData();
163+
164+
server.use(
165+
rest.get(`${LOCAL_ADDR}/api/v4/projects`, (_, res, ctx) =>
166+
res(ctx.status(200), ctx.json([])),
167+
),
168+
);
169+
170+
const backendServer = await startBackendServer(
171+
mockCatalogClient,
172+
AuthorizeResult.ALLOW,
173+
);
174+
175+
const response = await request(backendServer)
176+
.get('/api/bulk-import/repositories')
177+
.query({ approvalTool: 'GITLAB' });
178+
179+
expect(response.status).toEqual(200);
180+
expect(response.body).toEqual({
181+
approvalTool: 'GITLAB',
182+
errors: [],
183+
repositories: [],
184+
totalCount: 0,
185+
});
186+
});
187+
188+
it('returns filtered (not yet imported) repos when some repos are already imported', async () => {
189+
const { server, mockCatalogClient } = useTestData();
190+
191+
server.use(
192+
rest.get(CATALOG_API_LOCATIONS_LOCAL_ADDR, (_, res, ctx) =>
193+
res(
194+
ctx.status(200),
195+
ctx.json([
196+
{
197+
data: {
198+
id: 'imported-funtimes',
199+
target:
200+
'http://localhost:8765/saltypig1/funtimes/catalog-info.yaml',
201+
type: 'url',
202+
},
203+
},
204+
]),
205+
),
206+
),
207+
);
208+
209+
const backendServer = await startBackendServer(
210+
mockCatalogClient,
211+
AuthorizeResult.ALLOW,
212+
);
213+
214+
const response = await request(backendServer)
215+
.get('/api/bulk-import/repositories')
216+
.query({ approvalTool: 'GITLAB' });
217+
218+
expect(response.status).toEqual(200);
219+
expect(response.body).toEqual({
220+
approvalTool: 'GITLAB',
221+
errors: [],
222+
repositories: [
223+
{
224+
defaultBranch: 'main',
225+
errors: [],
226+
id: 'saltypig1/dolbear',
227+
lastUpdate: '2025-07-31T14:52:27.849Z',
228+
name: 'dolbear',
229+
organization: 'saltypig1',
230+
url: 'http://localhost:8765/saltypig1/dolbear',
231+
},
232+
{
233+
defaultBranch: 'main',
234+
errors: [],
235+
id: 'saltypig1/swapi-node',
236+
lastUpdate: '2025-07-31T14:54:57.289Z',
237+
name: 'swapi-node',
238+
organization: 'saltypig1',
239+
url: 'http://localhost:8765/saltypig1/swapi-node',
240+
},
241+
],
242+
totalCount: 2,
243+
});
244+
});
245+
246+
it('returns empty array when all repos are already imported', async () => {
247+
const { server, mockCatalogClient } = useTestData();
248+
249+
server.use(
250+
rest.get(CATALOG_API_LOCATIONS_LOCAL_ADDR, (_, res, ctx) =>
251+
res(
252+
ctx.status(200),
253+
ctx.json([
254+
{
255+
data: {
256+
id: 'imported-dolbear',
257+
target:
258+
'http://localhost:8765/saltypig1/dolbear/catalog-info.yaml',
259+
type: 'url',
260+
},
261+
},
262+
{
263+
data: {
264+
id: 'imported-funtimes',
265+
target:
266+
'http://localhost:8765/saltypig1/funtimes/catalog-info.yaml',
267+
type: 'url',
268+
},
269+
},
270+
{
271+
data: {
272+
id: 'imported-swapi-node',
273+
target:
274+
'http://localhost:8765/saltypig1/swapi-node/catalog-info.yaml',
275+
type: 'url',
276+
},
277+
},
278+
]),
279+
),
280+
),
281+
);
282+
283+
const backendServer = await startBackendServer(
284+
mockCatalogClient,
285+
AuthorizeResult.ALLOW,
286+
);
287+
288+
const response = await request(backendServer)
289+
.get('/api/bulk-import/repositories')
290+
.query({ approvalTool: 'GITLAB' });
291+
292+
expect(response.status).toEqual(200);
293+
expect(response.body).toEqual({
294+
approvalTool: 'GITLAB',
295+
errors: [],
296+
repositories: [],
297+
totalCount: 0,
298+
});
299+
});
300+
});
107301
});
108302

109303
describe('GET /organizations/{org}/repositories', () => {

0 commit comments

Comments
 (0)