From c44cde81a495cbdd4a6c45355b8bcfc7e6c5165b Mon Sep 17 00:00:00 2001 From: Yatendra Kumar Date: Fri, 28 Jul 2023 11:30:56 +0530 Subject: [PATCH] fix: analyser issues , refactor: mint repo --- lib/mint_nft/nft_mint_repo.dart | 8 +++++++- .../uploadImageToIPFS.welltested_test.dart | 16 ++-------------- .../uploadImageToIPFS.welltested_test.mocks.dart | 10 ++++++++++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/mint_nft/nft_mint_repo.dart b/lib/mint_nft/nft_mint_repo.dart index 12df8cf..3f2a44f 100644 --- a/lib/mint_nft/nft_mint_repo.dart +++ b/lib/mint_nft/nft_mint_repo.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'dart:developer' as developer; import 'dart:io'; +import 'package:ai_muse/mint_nft/base_nft_mint_repo.dart'; import 'package:ai_muse/utils/session_helper.dart'; import 'package:flutter/material.dart'; // ignore: depend_on_referenced_packages @@ -16,7 +17,8 @@ import 'package:welltested/welltested.dart'; import '../../keys.dart'; @Welltested() -class NFTMintRepo { +class NFTMintRepo extends BaseNFTMintRepo { + @override Future generateImageFromAI({required String prompt}) async { String errorMessage = "Something went wrong"; @@ -49,6 +51,7 @@ class NFTMintRepo { throw (errorMessage); } + @override Future storeFileInDirectory( {required String url, required String title, @@ -75,6 +78,7 @@ class NFTMintRepo { throw (errorMessage); } + @override Future uploadImageToIPFS( {required String imageUrl, required String nftName, @@ -171,6 +175,7 @@ class NFTMintRepo { throw (errorMessage); } + @override Future mintNFTUsingAPI( {required String chain, // ignore: non_constant_identifier_names @@ -212,6 +217,7 @@ class NFTMintRepo { throw (errorMessage); } + @override Future mintNFTOnSolana( {required String name, required String symbol, diff --git a/test/mint_nft/nft_mint_repo/uploadImageToIPFS.welltested_test.dart b/test/mint_nft/nft_mint_repo/uploadImageToIPFS.welltested_test.dart index 26c6fde..bc17466 100644 --- a/test/mint_nft/nft_mint_repo/uploadImageToIPFS.welltested_test.dart +++ b/test/mint_nft/nft_mint_repo/uploadImageToIPFS.welltested_test.dart @@ -7,13 +7,14 @@ import 'package:ai_muse/mint_nft/nft_mint_repo.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; +// ignore: depend_on_referenced_packages import 'package:http/http.dart' as http; +// ignore: depend_on_referenced_packages import 'package:path_provider/path_provider.dart'; @GenerateMocks([http.Client, Directory, File]) void main() { WidgetsFlutterBinding.ensureInitialized(); - group('uploadImageToIPFS', () { const imageUrl = 'https://example.com/image.png'; const nftName = 'TestNFT'; @@ -100,18 +101,5 @@ void main() { traitsDescription: traitsDescription), throwsA(isA())); }); - - // Add a test to mock the path_provider plugin - test('mock path_provider', () async { - final directory = MockDirectory(); - when(getApplicationDocumentsDirectory()) - .thenAnswer((_) async => directory); - when(directory.path).thenReturn('/test/path'); - - // You can add additional mocks for other path_provider methods if needed. - - // Now you can call your function that uses path_provider in your repository, - // and it should work properly without throwing MissingPluginException. - }); }); } diff --git a/test/mint_nft/nft_mint_repo/uploadImageToIPFS.welltested_test.mocks.dart b/test/mint_nft/nft_mint_repo/uploadImageToIPFS.welltested_test.mocks.dart index da6fa7c..f456443 100644 --- a/test/mint_nft/nft_mint_repo/uploadImageToIPFS.welltested_test.mocks.dart +++ b/test/mint_nft/nft_mint_repo/uploadImageToIPFS.welltested_test.mocks.dart @@ -8,6 +8,7 @@ import 'dart:convert' as _i5; import 'dart:io' as _i3; import 'dart:typed_data' as _i6; +import 'package:ai_muse/utils/session_helper.dart' as _i7; import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; @@ -345,6 +346,15 @@ class MockClient extends _i1.Mock implements _i2.Client { ); } +/// A class which mocks [SessionHelper]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockSessionHelper extends _i1.Mock implements _i7.SessionHelper { + MockSessionHelper() { + _i1.throwOnMissingStub(this); + } +} + /// A class which mocks [Directory]. /// /// See the documentation for Mockito's code generation for more information.