1+ import { CreateBucketCommand , DeleteBucketCommand , S3Client } from '@aws-sdk/client-s3' ;
12import { Test , TestingModule } from '@nestjs/testing' ;
23import {
34 ClassSerializerInterceptor ,
@@ -18,6 +19,8 @@ import * as GRPC from '@grpc/grpc-js';
1819import * as ProtoLoader from '@grpc/proto-loader' ;
1920import { RpcExceptionFilter } from 'src/rpc_exception_filter' ;
2021
22+ jest . setTimeout ( 15000 ) ;
23+
2124let app : INestApplication ;
2225const ADMIN_EMAIL = 'test-superadmin@test.com' ;
2326const ADMIN_PASSWORD = 'test-password' ;
@@ -38,14 +41,17 @@ async function APIKeyForProjectName(projectName: string): Promise<string> {
3841 return key . body [ 'apiKey' ] ;
3942}
4043
41- const bucketName = 'test-delete-gw -juno' ;
44+ const bucketName = 'test-delete-bog -juno' ;
4245const configId = 0 ;
4346const providerName = 'backblazeb2-delete-gw' ;
4447
4548const accessKeyId = process . env . accessKeyId ;
4649const secretAccessKey = process . env . secretAccessKey ;
4750const baseURL = process . env . baseURL ;
4851
52+ const s3BucketName = `${ bucketName } -${ configId } -prod` ;
53+ let s3Client : S3Client ;
54+
4955beforeAll ( async ( ) => {
5056 const proto = ProtoLoader . loadSync ( [ ResetProtoFile ] ) as any ;
5157 const protoGRPC = GRPC . loadPackageDefinition ( proto ) as any ;
@@ -98,11 +104,32 @@ beforeAll(async () => {
98104 ( ) => resolve ( 0 ) ,
99105 ) ;
100106 } ) ;
107+
108+ s3Client = new S3Client ( {
109+ endpoint : baseURL as string ,
110+ region : 'us-east-005' ,
111+ credentials : {
112+ accessKeyId : accessKeyId as string ,
113+ secretAccessKey : secretAccessKey as string ,
114+ } ,
115+ forcePathStyle : true ,
116+ } ) ;
117+ try {
118+ await s3Client . send ( new CreateBucketCommand ( { Bucket : s3BucketName } ) ) ;
119+ } catch {
120+ // Bucket may already exist from a previous run
121+ }
101122} ) ;
102123
103- afterAll ( ( done ) => {
104- app . close ( ) ;
105- done ( ) ;
124+ afterAll ( async ( ) => {
125+ if ( app ) await app . close ( ) ;
126+ if ( s3Client ) {
127+ try {
128+ await s3Client . send ( new DeleteBucketCommand ( { Bucket : s3BucketName } ) ) ;
129+ } catch {
130+ // Ignore cleanup errors
131+ }
132+ }
106133} ) ;
107134
108135beforeEach ( async ( ) => {
@@ -198,14 +225,15 @@ describe('File Delete Routes', () => {
198225 ) ;
199226 } ) ;
200227
201- return request ( app . getHttpServer ( ) )
228+ const res = await request ( app . getHttpServer ( ) )
202229 . delete ( '/file/delete' )
203230 . set ( 'Authorization' , 'Bearer ' + apiKey )
204231 . send ( {
205232 bucketName,
206233 configId,
207234 fileNames : [ 'FileToDeleteGW' ] ,
208- } )
209- . expect ( 200 ) ;
235+ } ) ;
236+
237+ expect ( res . status ) . toBe ( 200 ) ;
210238 } ) ;
211239} ) ;
0 commit comments