Created
October 11, 2019 19:26
-
-
Save adityadroid/577e9cf8b1aef4c30b9f017f0ee1dd37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
group('StorageProvider', () { | |
FirebaseStorageMock firebaseStorage = FirebaseStorageMock(); //Create the mock objects required | |
StorageReferenceMock storageReference = StorageReferenceMock(); | |
StorageReferenceMock rootReference = | |
StorageReferenceMock(childReference: storageReference); | |
StorageReferenceMock fileReference = StorageReferenceMock(); | |
StorageUploadTaskMock storageUploadTask = StorageUploadTaskMock(); | |
StorageTaskSnapshotMock storageTaskSnapshot = StorageTaskSnapshotMock(); | |
MockFile mockFile = MockFile(); | |
String resultUrl = "http://www.adityag.me/"; | |
StorageProvider storageProvider = | |
StorageProvider(firebaseStorage: firebaseStorage); | |
test('Testing if uploadImage returns a url', () async { | |
SharedPreferencesMock sharedPreferencesMock = SharedPreferencesMock(); | |
SharedObjects.prefs = sharedPreferencesMock; | |
when(sharedPreferencesMock.getString(any)).thenReturn('uid'); | |
when(SharedObjects.prefs.setString(any, any)).thenAnswer((_)=>Future.value(true)); | |
when(mockFile.path).thenReturn("/storage/file.jpg"); //this is necessary because basename() method from path.dart uses the path of the file to return its basename | |
when(firebaseStorage.ref()).thenReturn(rootReference); | |
when(storageReference.putFile(any)).thenReturn(storageUploadTask); | |
when(storageUploadTask.onComplete).thenAnswer( | |
(_) => Future<StorageTaskSnapshotMock>.value(storageTaskSnapshot)); | |
when(storageTaskSnapshot.ref).thenReturn(fileReference); | |
when(fileReference.getDownloadURL()) | |
.thenAnswer((_) => Future<String>.value(resultUrl)); | |
expect(await storageProvider.uploadFile(mockFile, ''), resultUrl); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment