1
1
import {
2
2
GetObjectCommand ,
3
+ HeadBucketCommand ,
3
4
PutObjectCommand ,
4
5
S3Client ,
5
6
} from '@aws-sdk/client-s3' ;
@@ -17,6 +18,7 @@ jest.mock('@aws-sdk/client-s3', () => {
17
18
S3Client : jest . fn ( ( ) => mS3Client ) ,
18
19
GetObjectCommand : jest . fn ( ) ,
19
20
PutObjectCommand : jest . fn ( ) ,
21
+ HeadBucketCommand : jest . fn ( ) ,
20
22
ObjectCannedACL : {
21
23
private : 'private' ,
22
24
public_read : 'public-read' ,
@@ -72,17 +74,23 @@ describe('FileService', () => {
72
74
expect ( fileService ) . toBeDefined ( ) ;
73
75
} ) ;
74
76
75
- it ( 'should throw an error if S3 configuration is missing' , ( ) => {
76
- expect ( ( ) => {
77
- new FileService (
78
- '' ,
79
- 'test-bucket-thumbs' ,
80
- 'test-key' ,
81
- 'test-secret' ,
82
- 'test-endpoint' ,
83
- 'test-region' ,
84
- ) ;
85
- } ) . toThrow ( 'Missing S3 bucket configuration' ) ;
77
+ describe ( 'verifyBucket' , ( ) => {
78
+ it ( 'should verify the buckets successfully' , async ( ) => {
79
+ ( s3Client . send as jest . Mock ) . mockResolvedValueOnce ( { } ) ;
80
+ ( s3Client . send as jest . Mock ) . mockResolvedValueOnce ( { } ) ;
81
+
82
+ await fileService [ 'verifyBucket' ] ( ) ;
83
+
84
+ expect ( s3Client . send ) . toHaveBeenCalledWith ( expect . any ( HeadBucketCommand ) ) ;
85
+ expect ( s3Client . send ) . toHaveBeenCalledWith ( expect . any ( HeadBucketCommand ) ) ;
86
+ } ) ;
87
+
88
+ it ( 'should log an error if bucket verification fails' , async ( ) => {
89
+ const error = new Error ( 'Bucket not found' ) ;
90
+ ( s3Client . send as jest . Mock ) . mockRejectedValueOnce ( error ) ;
91
+
92
+ await expect ( fileService [ 'verifyBucket' ] ( ) ) . rejects . toThrow ( error ) ;
93
+ } ) ;
86
94
} ) ;
87
95
88
96
it ( 'should upload a song' , async ( ) => {
0 commit comments