forked from eatvio/eatvio_app
chore(version): update app version to 1.3.5+85 and improve test coverage reporting in CI
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
import 'package:eatvio_app/features/consultations/models/consultation_model.dart';
|
||||
import 'package:eatvio_app/features/consultations/repositories/consultations_repository.dart';
|
||||
import 'package:eatvio_app/features/consultations/services/consultation_service.dart';
|
||||
import 'package:eatvio_app/features/finances_and_consultations_archive/models/consultant_finance_model.dart';
|
||||
import 'package:eatvio_app/features/finances_and_consultations_archive/models/statistic_model.dart';
|
||||
import 'package:eatvio_app/features/finances_and_consultations_archive/models/user_purchases_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
class MockConsultationService extends Mock implements ConsultationService {}
|
||||
|
||||
class FakeStatisticModel extends Fake implements StatisticModel {}
|
||||
|
||||
void main() {
|
||||
group('ConsultationsRepository', () {
|
||||
late ConsultationsRepository repository;
|
||||
late MockConsultationService mockService;
|
||||
|
||||
setUpAll(() {
|
||||
registerFallbackValue(FakeStatisticModel());
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
mockService = MockConsultationService();
|
||||
repository = ConsultationsRepository(consultationService: mockService);
|
||||
});
|
||||
|
||||
test('getConsultations - успешный запрос', () async {
|
||||
final mockConsultations = <ConsultationModel>[];
|
||||
final mockPagination = ConsultationPaginationModel(data: mockConsultations);
|
||||
|
||||
when(() => mockService.getConsultations())
|
||||
.thenAnswer((_) async => mockPagination);
|
||||
|
||||
final result = await repository.getConsultations();
|
||||
|
||||
expect(result, mockConsultations);
|
||||
verify(() => mockService.getConsultations()).called(1);
|
||||
});
|
||||
|
||||
test('getConsultations - пробрасывает ошибку', () async {
|
||||
when(() => mockService.getConsultations())
|
||||
.thenThrow(Exception('Error'));
|
||||
|
||||
expect(() => repository.getConsultations(), throwsException);
|
||||
});
|
||||
|
||||
test('getFilteredConsultations - успешный запрос', () async {
|
||||
final mockConsultations = <ConsultationModel>[];
|
||||
final mockPagination = ConsultationPaginationModel(data: mockConsultations);
|
||||
|
||||
when(() => mockService.getFilteredConsultations(
|
||||
state: any(named: 'state'),
|
||||
date: any(named: 'date'),
|
||||
stateComparison: any(named: 'stateComparison'),
|
||||
dateComparison: any(named: 'dateComparison'),
|
||||
))
|
||||
.thenAnswer((_) async => mockPagination);
|
||||
|
||||
final result = await repository.getFilteredConsultations();
|
||||
|
||||
expect(result, mockConsultations);
|
||||
verify(() => mockService.getFilteredConsultations(
|
||||
state: null,
|
||||
date: null,
|
||||
stateComparison: null,
|
||||
dateComparison: null,
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('getStatistic - успешный запрос', () async {
|
||||
final mockStatistic = StatisticModel(
|
||||
total: 10,
|
||||
inProgress: 5,
|
||||
finished: 3,
|
||||
canceled: 2,
|
||||
);
|
||||
|
||||
when(() => mockService.getStatistics())
|
||||
.thenAnswer((_) async => mockStatistic);
|
||||
|
||||
final result = await repository.getStatistic();
|
||||
|
||||
expect(result, mockStatistic);
|
||||
verify(() => mockService.getStatistics()).called(1);
|
||||
});
|
||||
|
||||
test('getConsultantFinances - успешный запрос', () async {
|
||||
final mockFinances = <ConsultantFinanceModel>[];
|
||||
|
||||
when(() => mockService.getConsultantFinances(any(), any()))
|
||||
.thenAnswer((_) async => mockFinances);
|
||||
|
||||
final result = await repository.getConsultantFinances(null, null);
|
||||
|
||||
expect(result, mockFinances);
|
||||
verify(() => mockService.getConsultantFinances(null, null)).called(1);
|
||||
});
|
||||
|
||||
test('getUserPurchases - успешный запрос', () async {
|
||||
final mockPurchases = <UserPurchasesModel>[];
|
||||
|
||||
when(() => mockService.getUserPurchases(any(), any()))
|
||||
.thenAnswer((_) async => mockPurchases);
|
||||
|
||||
final result = await repository.getUserPurchases(null, null);
|
||||
|
||||
expect(result, mockPurchases);
|
||||
verify(() => mockService.getUserPurchases(null, null)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user