22 getS3Client ,
33 putObjectToS3 ,
44 getObjectFromS3 ,
5- resetS3Client ,
65 getListObjectsFromS3 ,
76 s3FileExists ,
87 getHeadObjectFromS3 ,
@@ -13,48 +12,30 @@ import { S3Client, type _Object, type S3ClientConfig } from "@aws-sdk/client-s3"
1312import { createS3Client } from "mock-aws-s3-v3" ;
1413import fs from "fs" ;
1514import { finished } from "stream/promises" ;
16- import { describe , it , expect , beforeEach , afterAll } from "vitest" ;
15+ import { describe , it , expect , afterAll } from "vitest" ;
1716import { createHash } from "crypto" ;
1817
19- describe ( "getS3Client(config?)" , ( ) => {
20- it ( "Should fail because config is undefined and the client is not set" , ( ) => {
21- expect ( ( ) => getS3Client ( ) ) . toThrow ( ) ;
22- } ) ;
18+ const config = {
19+ endpoint : "http://0.0.0.0:9000" ,
20+ credentials : {
21+ accessKeyId : "dev" ,
22+ secretAccessKey : "devpasswd" ,
23+ } ,
24+ } ;
2325
26+ describe ( "getS3Client(config)" , ( ) => {
2427 it ( "Should return an instance of an S3Client" , ( ) => {
25- const config = {
26- endpoint : "http://0.0.0.0:9000" ,
27- credentials : {
28- accessKeyId : "dev" ,
29- secretAccessKey : "devpasswd" ,
30- } ,
31- } ;
32-
3328 expect ( getS3Client ( config ) instanceof S3Client ) . toBe ( true ) ;
3429 } ) ;
35-
36- it ( "Should return an instance of the S3Client even with undefined config" , ( ) => {
37- expect ( getS3Client ( ) instanceof S3Client ) . toBe ( true ) ;
38- } ) ;
3930} ) ;
4031
41- describe ( "putFileToS3(bucket, key, file, s3Client?)" , ( ) => {
42- beforeEach ( resetS3Client ) ;
43-
32+ describe ( "putFileToS3(bucket, key, file, s3Client)" , ( ) => {
4433 afterAll ( ( ) => {
4534 fs . rm ( "test/s3_mock/dev/put_test" , { recursive : true } , ( err ) => {
4635 if ( err != null ) console . error ( err ) ;
4736 } ) ;
4837 } ) ;
4938
50- it ( "Should fail because s3Client is not set" , async ( ) => {
51- const file = fs . readFileSync ( "test/test.xml" ) ;
52-
53- await expect (
54- putObjectToS3 ( "dev" , "put_test/test.xml" , file ) ,
55- ) . rejects . toThrow ( ) ;
56- } ) ;
57-
5839 const mockClient = createS3Client ( {
5940 localDirectory : "./test/s3_mock" ,
6041 bucket : "dev" ,
@@ -69,14 +50,7 @@ describe("putFileToS3(bucket, key, file, s3Client?)", () => {
6950 } ) ;
7051} ) ;
7152
72- describe ( "getFileFromS3(bucket, key, s3Client?)" , ( ) => {
73- beforeEach ( resetS3Client ) ;
74-
75- it ( "Should fail because s3Client is not set" , async ( ) => {
76- await expect (
77- getObjectFromS3 ( "dev" , "get_test/test.xml" ) ,
78- ) . rejects . toThrow ( ) ;
79- } ) ;
53+ describe ( "getFileFromS3(bucket, key, s3Client)" , ( ) => {
8054
8155 it ( "Should get the file from S3 (test/mock) successfully" , async ( ) => {
8256 const mockClient = createS3Client ( {
@@ -93,8 +67,7 @@ describe("getFileFromS3(bucket, key, s3Client?)", () => {
9367 } ) ;
9468} ) ;
9569
96- describe ( "getListObjectsFromS3(bucket, prefix, s3Client?)" , ( ) => {
97- beforeEach ( resetS3Client ) ;
70+ describe ( "getListObjectsFromS3(bucket, prefix, s3Client)" , ( ) => {
9871
9972 it ( "Should get the list of files from S3 (50 subfolders with 1 XML file and 1 PDF file each))" , async ( ) => {
10073 const mockClient = createS3Client ( {
@@ -104,8 +77,8 @@ describe("getListObjectsFromS3(bucket, prefix, s3Client?)", () => {
10477
10578 const streamNoMaxKeys = getListObjectsFromS3 (
10679 "dev" ,
107- "get_list_object_test" ,
108- { delimiter : "arbitrary delimiter" , s3Client : mockClient } ,
80+ "get_list_object_test" , mockClient ,
81+ { delimiter : "arbitrary delimiter" } ,
10982 ) ;
11083
11184 const objectsNoMaxKeys : _Object [ ] = [ ] ;
@@ -118,10 +91,10 @@ describe("getListObjectsFromS3(bucket, prefix, s3Client?)", () => {
11891 const streamMaxKeys = getListObjectsFromS3 (
11992 "dev" ,
12093 "get_list_object_test" ,
94+ mockClient ,
12195 {
12296 delimiter : "arbitrary delimiter" ,
12397 maxKeys : 2 ,
124- s3Client : mockClient ,
12598 } ,
12699 ) ;
127100
@@ -151,7 +124,7 @@ describe("getListObjectsFromS3(bucket, prefix, s3Client?)", () => {
151124 } ) ;
152125} ) ;
153126
154- describe ( "s3FileExists(bucket, key)" , ( ) => {
127+ describe ( "s3FileExists(bucket, key, s3Client )" , ( ) => {
155128 const mockClient = createS3Client ( {
156129 localDirectory : "./test/s3_mock" ,
157130 bucket : "dev" ,
@@ -179,7 +152,7 @@ describe("s3FileExists(bucket, key)", () => {
179152 } ) ;
180153} ) ;
181154
182- describe ( "getHeadObjectFromS3(bucket, key, s3Client? )" , ( ) => {
155+ describe ( "getHeadObjectFromS3(bucket, key, s3Client)" , ( ) => {
183156 const mockClient = createS3Client ( {
184157 localDirectory : "./test/s3_mock" ,
185158 bucket : "dev" ,
@@ -232,14 +205,7 @@ describe("getEnvConfig()", () => {
232205 } )
233206} )
234207
235- describe ( "getSHA1OfObject(bucket, key, s3Client?)" , ( ) => {
236- beforeEach ( resetS3Client ) ;
237-
238- it ( "Should fail because s3Client is not set" , async ( ) => {
239- await expect (
240- getSHA1OfObject ( "dev" , "get_test/test.xml" ) ,
241- ) . rejects . toThrow ( ) ;
242- } ) ;
208+ describe ( "getSHA1OfObject(bucket, key, s3Client)" , ( ) => {
243209
244210 it ( "Should return the SHA1 of an existing object" , async ( ) => {
245211 const mockClient = createS3Client ( {
0 commit comments