From 3d717ddcde891c8695c293f324c138cd8fa02384 Mon Sep 17 00:00:00 2001 From: Ekjot <43255916+ekjotmultani@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:58:03 -0700 Subject: [PATCH] added integration tests --- .../category/amplify_storage_category.dart | 1 + .../integration_test/get_properties_test.dart | 116 ++++++++++++++++++ .../test/amplify_storage_s3_dart_test.dart | 7 -- 3 files changed, 117 insertions(+), 7 deletions(-) diff --git a/packages/amplify_core/lib/src/category/amplify_storage_category.dart b/packages/amplify_core/lib/src/category/amplify_storage_category.dart index c3f4cfbe2f..84c9603c03 100644 --- a/packages/amplify_core/lib/src/category/amplify_storage_category.dart +++ b/packages/amplify_core/lib/src/category/amplify_storage_category.dart @@ -153,6 +153,7 @@ class StorageCategory extends AmplifyCategory { data: data, onProgress: onProgress, options: options, + bucket: bucket, ), ); } diff --git a/packages/storage/amplify_storage_s3/example/integration_test/get_properties_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/get_properties_test.dart index 9540e49650..e53dc39e4b 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/get_properties_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/get_properties_test.dart @@ -101,5 +101,121 @@ void main() { expect(result.storageItem.size, data.length); }); }); + group('multibucket config', () { + setUpAll(() async { + await configure(amplifyEnvironments['main']!); + addTearDownPath(StoragePath.fromString(path)); + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromString(path), + options: const StorageUploadDataOptions(metadata: metadata), + bucket: const StorageBucket.fromBucketInfo( + BucketInfo( + bucketName: + 'amplify-main-main-sandbox-storageintegtestsecondar-mxf6yc4ivr2h', + region: 'us-west-2', + ), + ), + ).result; + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromString(path), + options: const StorageUploadDataOptions(metadata: metadata), + bucket: StorageBucket.fromOutputs('Storage Integ Test main bucket'), + ).result; + }); + + testWidgets('String StoragePath', (_) async { + final result = await Amplify.Storage.getProperties( + path: StoragePath.fromString(path), + options: const StorageGetPropertiesOptions( + bucket: StorageBucket.fromBucketInfo( + BucketInfo( + bucketName: + 'amplify-main-main-sandbox-storageintegtestmainbuck-nmfvvkcjjel6', + region: 'us-west-2', + ), + ), + ), + ).result; + expect(result.storageItem.path, path); + expect(result.storageItem.metadata, metadata); + expect(result.storageItem.eTag, isNotNull); + expect(result.storageItem.size, data.length); + + final resultSecondaryBucket = await Amplify.Storage.getProperties( + path: StoragePath.fromString(path), + options: StorageGetPropertiesOptions( + bucket: StorageBucket.fromOutputs( + 'Storage Integ Test secondary bucket', + ), + ), + ).result; + expect(resultSecondaryBucket.storageItem.path, path); + expect(resultSecondaryBucket.storageItem.metadata, metadata); + expect(resultSecondaryBucket.storageItem.eTag, isNotNull); + expect(resultSecondaryBucket.storageItem.size, data.length); + }); + + testWidgets('with identity ID', (_) async { + final mainBucket = + StorageBucket.fromOutputs('Storage Integ Test main bucket'); + final secondaryBucket = + StorageBucket.fromOutputs('Storage Integ Test secondary bucket'); + final userIdentityId = await signInNewUser(); + final name = 'get-properties-with-identity-id-${uuid()}'; + final data = 'with identity ID'.codeUnits; + final expectedResolvedPath = 'private/$userIdentityId/$name'; + addTearDownPath(StoragePath.fromString(expectedResolvedPath)); + await Amplify.Storage.uploadData( + data: StorageDataPayload.bytes(data), + path: StoragePath.fromString(expectedResolvedPath), + options: const StorageUploadDataOptions(metadata: metadata), + bucket: secondaryBucket, + ).result; + final result = await Amplify.Storage.getProperties( + path: StoragePath.fromIdentityId( + ((identityId) => 'private/$identityId/$name'), + ), + options: StorageGetPropertiesOptions( + bucket: secondaryBucket, + ), + ).result; + expect(result.storageItem.path, expectedResolvedPath); + expect(result.storageItem.metadata, metadata); + expect(result.storageItem.eTag, isNotNull); + expect(result.storageItem.size, data.length); + await expectLater( + Amplify.Storage.getProperties( + path: StoragePath.fromIdentityId( + ((identityId) => 'private/$identityId/$name'), + ), + options: StorageGetPropertiesOptions( + bucket: mainBucket, + ), + ).result, + throwsA(isA()), + ); + // we expect this error here since the main bucket does not have this data uploaded + }); + + testWidgets('unauthorized path', (_) async { + await expectLater( + () => Amplify.Storage.getProperties( + path: const StoragePath.fromString('unauthorized/path'), + ).result, + throwsA(isA()), + ); + }); + + testWidgets('not existent path', (_) async { + await expectLater( + () => Amplify.Storage.getProperties( + path: const StoragePath.fromString('public/not-existent-path'), + ).result, + throwsA(isA()), + ); + }); + }); }); } diff --git a/packages/storage/amplify_storage_s3_dart/test/amplify_storage_s3_dart_test.dart b/packages/storage/amplify_storage_s3_dart/test/amplify_storage_s3_dart_test.dart index b1871bf064..3968db24ed 100644 --- a/packages/storage/amplify_storage_s3_dart/test/amplify_storage_s3_dart_test.dart +++ b/packages/storage/amplify_storage_s3_dart/test/amplify_storage_s3_dart_test.dart @@ -250,13 +250,6 @@ void main() { ), ); - var testOptionsFromOutputs = StorageGetPropertiesOptions( - pluginOptions: const S3GetPropertiesPluginOptions(), - bucket: StorageBucket.fromOutputs( - 'Storage Integ Test secondary bucket', - ), - ); - when( () => storageS3Service.getProperties( path: testPath,