createDomainUseCaseTest method
void
createDomainUseCaseTest()
Implementation
void createDomainUseCaseTest(
String pathTestPage,
String featureName,
String pageName,
List<Map<String, String>> resultModelUnitTest,
) {
final path = join(pathTestPage, 'domain', 'usecases');
DirectoryHelper.createDir(path);
for (var e in resultModelUnitTest) {
final apiName = e['apiName'];
final className = apiName?.pascalCase;
final methodName = apiName?.camelCase;
join(path, '${apiName?.snakeCase}_use_case_test.dart').write(
'''// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:$featureName/$pageName/domain/repositories/${pageName}_repository.dart';
import 'package:$featureName/$pageName/data/models/body/${apiName?.snakeCase}_body.dart' as body_${e['apiName']?.snakeCase};
import 'package:$featureName/$pageName/domain/entities/${apiName?.snakeCase}_entity.dart' as entity_${e['apiName']?.snakeCase};
import 'package:$featureName/$pageName/domain/usecases/${apiName?.snakeCase}_use_case.dart';
import 'package:core/core.dart';
import 'package:dev_dependency_manager/dev_dependency_manager.dart';
class MockRepository extends Mock implements ${pageName.pascalCase}Repository {}
Future<void> main() async {
late ${className}UseCase usecase;
late MockRepository mockRepository;
setUp(() {
mockRepository = MockRepository();
usecase = ${className}UseCase(repository: mockRepository);
});
${getConstOrFinalValue(e['body'] ?? '')} body${e['apiName']?.pascalCase} = ${e['body']}
${getConstOrFinalValue(e['entity'] ?? '')} entity${e['apiName']?.pascalCase} = ${e['entity']}
test(
'Should fetch entity for the body from the repository',
() async {
// arrange
when(() => mockRepository.$methodName(body$className))
.thenAnswer((_) async => Right(entity$className));
// act
final result = await usecase(body$className);
// assert
expect(result, Right(entity$className));
verify(() => mockRepository.$methodName(body$className));
verifyNoMoreInteractions(mockRepository);
},
);
}''');
StatusHelper.generated(
join(path, '${apiName?.snakeCase}_use_case_test.dart'));
}
}