Skip to content

Commit b9963b9

Browse files
committed
test: add e2e tests for getAllFiles
1 parent 0472320 commit b9963b9

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎packages/api-gateway/test/file_bucket.e2e-spec.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,22 @@ describe('File Bucket Routes', () => {
230230

231231
await client.send(command);
232232
});
233+
234+
it('Gets all files successfully', async () => {
235+
await request(app.getHttpServer())
236+
.get('/file/all/0')
237+
.set('Authorization', 'Bearer ' + apiKey)
238+
.expect(200);
239+
});
240+
241+
it('Unsuccessfully gets all files due to invalid configId', async () => {
242+
await request(app.getHttpServer())
243+
.get('/file/all/invalid')
244+
.set('Authorization', 'Bearer ' + apiKey)
245+
.expect(400);
246+
});
247+
248+
it('Unsuccessfully gets all files due to missing authorization', async () => {
249+
await request(app.getHttpServer()).get('/file/all/0').expect(401);
250+
});
233251
});

‎packages/file-service/test/file_bucket.e2e-spec.ts‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,78 @@ describe('File Bucket Creation Tests', () => {
267267
await createBucketPromise2;
268268
});
269269
});
270+
271+
describe('Get All Files Tests', () => {
272+
it('Successfully gets all files for a config', async () => {
273+
const metadata = {
274+
endpoint: baseURL,
275+
region: region,
276+
credentials: {
277+
accessKeyId: accessKeyId as string,
278+
secretAccessKey: secretAccessKey as string,
279+
},
280+
};
281+
282+
const client = new S3Client(metadata);
283+
const command = new DeleteBucketCommand({
284+
Bucket: `get-all-files-bucket-${configId}-${configEnv}`,
285+
});
286+
287+
try {
288+
await client.send(command);
289+
} catch {}
290+
291+
await new Promise((resolve, reject) => {
292+
bucketClient.registerBucket(
293+
{
294+
name: 'get-all-files-bucket',
295+
configId,
296+
configEnv,
297+
fileProviderName: providerName,
298+
},
299+
(err: any) => {
300+
if (err) return reject(err);
301+
resolve(0);
302+
},
303+
);
304+
});
305+
306+
const getAllFilesPromise = new Promise((resolve, reject) => {
307+
bucketClient.getAllFiles(
308+
{
309+
configId,
310+
configEnv,
311+
},
312+
(err: any, response: any) => {
313+
if (err) return reject(err);
314+
expect(err).toBeNull();
315+
expect(response).toBeDefined();
316+
expect(response.files).toBeDefined();
317+
resolve(response);
318+
},
319+
);
320+
});
321+
await getAllFilesPromise;
322+
323+
await client.send(command);
324+
});
325+
326+
it('Returns empty files for nonexistent config', async () => {
327+
const getAllFilesPromise = new Promise((resolve, reject) => {
328+
bucketClient.getAllFiles(
329+
{
330+
configId: 9999,
331+
configEnv: 'nonexistent',
332+
},
333+
(err: any, response: any) => {
334+
if (err) return reject(err);
335+
expect(err).toBeNull();
336+
expect(response).toBeDefined();
337+
expect(response.files).toBeUndefined();
338+
resolve(response);
339+
},
340+
);
341+
});
342+
await getAllFilesPromise;
343+
});
344+
});

0 commit comments

Comments
 (0)