@@ -17,7 +17,9 @@ import {
17
17
cleanUpMockUsers ,
18
18
sleep ,
19
19
cleanUpRecursively ,
20
- mockCeremoniesCleanup
20
+ mockCeremoniesCleanup ,
21
+ generatePseudoRandomStringOfNumbers ,
22
+ uploadFileToS3
21
23
} from "../utils/index"
22
24
import { fakeCeremoniesData , fakeCircuitsData , fakeUsersData } from "../data/samples"
23
25
import {
@@ -39,7 +41,7 @@ import {
39
41
import { TestingEnvironment } from "../../src/types/enums"
40
42
import { ChunkWithUrl , ETagWithPartNumber } from "../../src/types/index"
41
43
import { getChunksAndPreSignedUrls , getWasmStorageFilePath , uploadParts } from "../../src/helpers/storage"
42
- import { completeMultiPartUpload , openMultiPartUpload } from "../../src/helpers/functions"
44
+ import { completeMultiPartUpload , openMultiPartUpload , transferObject } from "../../src/helpers/functions"
43
45
44
46
chai . use ( chaiAsPromised )
45
47
@@ -684,6 +686,60 @@ describe("Storage", () => {
684
686
} )
685
687
} )
686
688
689
+ describe ( "transferObject" , ( ) => {
690
+ // we need two buckets - source and destination
691
+ const sourceBucketName = generatePseudoRandomStringOfNumbers ( 10 )
692
+ const destinationBucketName = generatePseudoRandomStringOfNumbers ( 10 )
693
+ const objectKey = "test.txt"
694
+ fs . writeFileSync ( objectKey , "test" )
695
+
696
+ beforeAll ( async ( ) => {
697
+ // login as coordinator
698
+ await signInWithEmailAndPassword ( userAuth , users [ 1 ] . data . email , passwords [ 1 ] )
699
+ // create the buckets and upload the file
700
+ await createS3Bucket ( userFunctions , sourceBucketName )
701
+ await createS3Bucket ( userFunctions , destinationBucketName )
702
+ await uploadFileToS3 (
703
+ sourceBucketName ,
704
+ objectKey ,
705
+ objectKey
706
+ )
707
+ } )
708
+
709
+ it ( "should successfully transfer an object between buckets" , async ( ) => {
710
+ const result = await transferObject (
711
+ userFunctions ,
712
+ sourceBucketName ,
713
+ objectKey ,
714
+ destinationBucketName ,
715
+ objectKey
716
+ )
717
+
718
+ expect ( result ) . to . be . true
719
+ } )
720
+
721
+ it ( "should transfer an object between buckets in different regions" , async ( ) => { } )
722
+ it ( "should throw when trying to transfer an object that does not exist" , async ( ) => {
723
+ await expect ( transferObject (
724
+ userFunctions ,
725
+ sourceBucketName ,
726
+ "i-dont-exist.txt" ,
727
+ destinationBucketName ,
728
+ objectKey
729
+ ) ) . to . be . rejected
730
+ } )
731
+
732
+ afterAll ( async ( ) => {
733
+ // delete the buckets
734
+ await deleteObjectFromS3 ( sourceBucketName , objectKey )
735
+ await deleteObjectFromS3 ( destinationBucketName , objectKey )
736
+ await deleteBucket ( sourceBucketName )
737
+ await deleteBucket ( destinationBucketName )
738
+
739
+ fs . unlinkSync ( objectKey )
740
+ } )
741
+ } )
742
+
687
743
// @todo this is not used in the cli yet
688
744
describe ( "uploadFileToStorage" , ( ) => {
689
745
it ( "should successfully upload a file to storage" , async ( ) => { } )
0 commit comments