Skip to content

Commit

Permalink
fix: analyser issues , refactor: mint repo
Browse files Browse the repository at this point in the history
  • Loading branch information
yatendra2001 committed Jul 28, 2023
1 parent 60dd9a9 commit c44cde8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
8 changes: 7 additions & 1 deletion lib/mint_nft/nft_mint_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +17,8 @@ import 'package:welltested/welltested.dart';
import '../../keys.dart';

@Welltested()
class NFTMintRepo {
class NFTMintRepo extends BaseNFTMintRepo {
@override
Future<String?> generateImageFromAI({required String prompt}) async {
String errorMessage = "Something went wrong";

Expand Down Expand Up @@ -49,6 +51,7 @@ class NFTMintRepo {
throw (errorMessage);
}

@override
Future<String> storeFileInDirectory(
{required String url,
required String title,
Expand All @@ -75,6 +78,7 @@ class NFTMintRepo {
throw (errorMessage);
}

@override
Future<String> uploadImageToIPFS(
{required String imageUrl,
required String nftName,
Expand Down Expand Up @@ -171,6 +175,7 @@ class NFTMintRepo {
throw (errorMessage);
}

@override
Future<void> mintNFTUsingAPI(
{required String chain,
// ignore: non_constant_identifier_names
Expand Down Expand Up @@ -212,6 +217,7 @@ class NFTMintRepo {
throw (errorMessage);
}

@override
Future<void> mintNFTOnSolana(
{required String name,
required String symbol,
Expand Down
16 changes: 2 additions & 14 deletions test/mint_nft/nft_mint_repo/uploadImageToIPFS.welltested_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -100,18 +101,5 @@ void main() {
traitsDescription: traitsDescription),
throwsA(isA<String>()));
});

// 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.
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c44cde8

Please sign in to comment.