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:
@@ -3,12 +3,10 @@ import 'package:eatvio_app/features/consultant_rating/models/statistics_model.da
|
||||
import 'package:eatvio_app/features/consultant_rating/repositories/consultant_rating_repository.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/services/consultant_rating_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
import 'consultant_rating_repository_test.mocks.dart';
|
||||
class MockConsultantRatingService extends Mock implements ConsultantRatingService {}
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ConsultantRatingService>()])
|
||||
void main() {
|
||||
group('ConsultantRatingRepository', () {
|
||||
late ConsultantRatingRepository repository;
|
||||
@@ -19,47 +17,49 @@ void main() {
|
||||
repository = ConsultantRatingRepository(mockService);
|
||||
});
|
||||
|
||||
test('getConsultantStatistics - успешное получение статистики', () async {
|
||||
final expectedStats = StatisticsModel(
|
||||
countReferal: 10,
|
||||
blogPostsCount: 5,
|
||||
recipesCount: 3,
|
||||
dietsCount: 2,
|
||||
consultationsCount: 15,
|
||||
qwe: 1,
|
||||
refLink: 'https://example.com/ref',
|
||||
);
|
||||
test('getConsultantStatistics - успешный запрос', () async {
|
||||
final mockStatistics = StatisticsModel();
|
||||
|
||||
when(mockService.getConsultantStatistics(date: null))
|
||||
.thenAnswer((_) async => expectedStats);
|
||||
when(() => mockService.getConsultantStatistics(date: any(named: 'date')))
|
||||
.thenAnswer((_) async => mockStatistics);
|
||||
|
||||
final result = await repository.getConsultantStatistics();
|
||||
|
||||
expect(result, equals(expectedStats));
|
||||
expect(result.countReferal, 10);
|
||||
verify(mockService.getConsultantStatistics(date: null)).called(1);
|
||||
expect(result, mockStatistics);
|
||||
verify(() => mockService.getConsultantStatistics(date: null)).called(1);
|
||||
});
|
||||
|
||||
test('getScoreLogs - успешное получение логов', () async {
|
||||
final expectedLogs = [
|
||||
RatingModel(
|
||||
date: DateTime(2024, 1, 1),
|
||||
type: RatingEnum.addedRecipe,
|
||||
amount: 10,
|
||||
),
|
||||
];
|
||||
test('getConsultantStatistics - с датой', () async {
|
||||
const date = '2024-01-01';
|
||||
final mockStatistics = StatisticsModel();
|
||||
|
||||
final pagination = RatingPaginationModel(data: expectedLogs);
|
||||
when(() => mockService.getConsultantStatistics(date: date))
|
||||
.thenAnswer((_) async => mockStatistics);
|
||||
|
||||
when(mockService.getScoreLogs(date: null))
|
||||
.thenAnswer((_) async => pagination);
|
||||
final result = await repository.getConsultantStatistics(date: date);
|
||||
|
||||
expect(result, mockStatistics);
|
||||
verify(() => mockService.getConsultantStatistics(date: date)).called(1);
|
||||
});
|
||||
|
||||
test('getScoreLogs - успешный запрос', () async {
|
||||
final mockRatings = <RatingModel>[];
|
||||
final mockPagination = RatingPaginationModel(data: mockRatings);
|
||||
|
||||
when(() => mockService.getScoreLogs(date: any(named: 'date')))
|
||||
.thenAnswer((_) async => mockPagination);
|
||||
|
||||
final result = await repository.getScoreLogs();
|
||||
|
||||
expect(result.length, 1);
|
||||
expect(result.first.amount, 10);
|
||||
verify(mockService.getScoreLogs(date: null)).called(1);
|
||||
expect(result, mockRatings);
|
||||
verify(() => mockService.getScoreLogs(date: null)).called(1);
|
||||
});
|
||||
|
||||
test('getScoreLogs - пробрасывает ошибку', () async {
|
||||
when(() => mockService.getScoreLogs(date: any(named: 'date')))
|
||||
.thenThrow(Exception('Error'));
|
||||
|
||||
expect(() => repository.getScoreLogs(), throwsException);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user