feat(tests): added services tests and fixtures

This commit is contained in:
misha
2025-12-11 15:53:35 +03:00
parent d1753e99f8
commit 070a3e39e7
65 changed files with 2092 additions and 1130 deletions

View File

@@ -1,5 +1,3 @@
import 'package:eatvio_app/core/models/pagination_model.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
import 'package:eatvio_app/features/plans/services/plans_service.dart';
@@ -7,6 +5,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import '../../../fixtures/fixture_reader.dart';
import 'plans_repository_test.mocks.dart';
@GenerateNiceMocks([MockSpec<PlansService>()])
@@ -22,45 +21,15 @@ void main() {
test('getPlansBySlug - успешное получение планов', () async {
const slug = 'test-author';
const plan = PlanModel(
id: 1,
slug: 'test-plan',
name: 'Test Plan',
image: 'https://example.com/image.jpg',
duration: 7,
state: 'active',
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
details: 'Test details',
packetsCount: 3,
author: Author(
authorSlug: 'test-author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
totalLikes: 10,
totalViews: 100,
totalComments: 5,
isFavorite: false,
minPriceOfOptions: 1000.0,
maxPriceOfOptions: 2000.0,
wasLikedByMe: false,
);
const pagination = PlanPaginationModel(
data: [plan],
links: Links(first: 'https://example.com?page=1', last: 'https://example.com?page=1', prev: null, next: null),
meta: Meta(currentPage: 1, from: 1, lastPage: 1, links: [], perPage: 10, to: 1, total: 1),
);
final paginationJson = FixtureReader.readAsMap('feed/plan_pagination_response.json');
final pagination = PlanPaginationModel.fromJson(paginationJson);
when(mockService.getPlansBySlug(author: slug)).thenAnswer((_) async => pagination);
final result = await repository.getPlansBySlug(slug);
expect(result.length, 1);
expect(result.first.slug, 'test-plan');
expect(result.first.slug, 'weight-loss-plan');
verify(mockService.getPlansBySlug(author: slug)).called(1);
});
});