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

@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import '../../../fixtures/fixture_reader.dart';
import 'diet_repository_test.mocks.dart';
@GenerateNiceMocks([MockSpec<DietService>()])
@@ -21,10 +22,8 @@ void main() {
test('likeDiet - успешный лайк', () async {
const dietId = 1;
const expectedLikes = DietLikesModel(
totalLikes: 10,
isLiked: true,
);
final json = FixtureReader.readAsMap('diets/diet_likes_response.json');
final expectedLikes = DietLikesModel.fromJson(json);
when(mockService.likeDiet(id: dietId))
.thenAnswer((_) async => expectedLikes);
@@ -37,31 +36,8 @@ void main() {
test('getDiet - успешное получение диеты по id', () async {
const dietId = 1;
const expectedDiet = Diet(
id: dietId,
slug: 'test-diet',
name: 'Test Diet',
image: 'https://example.com/image.jpg',
duration: 7,
state: DietState.active,
type: DietType(veg: true, light: false, carb: false, meat: false),
details: 'Test details',
dailySchedule: {},
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
totalLikes: 10,
totalViews: 100,
totalComments: 5,
wasLikedByMe: false,
isFavorite: false,
dailyNutrition: [],
);
final json = FixtureReader.readAsMap('diets/diet_response.json');
final expectedDiet = Diet.fromJson(json);
when(mockService.getDiet(id: dietId))
.thenAnswer((_) async => expectedDiet);
@@ -75,31 +51,8 @@ void main() {
test('getDietBySlug - успешное получение диеты по slug', () async {
const slug = 'test-diet';
const expectedDiet = Diet(
id: 1,
slug: slug,
name: 'Test Diet',
image: 'https://example.com/image.jpg',
duration: 7,
state: DietState.active,
type: DietType(veg: true, light: false, carb: false, meat: false),
details: 'Test details',
dailySchedule: {},
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
totalLikes: 10,
totalViews: 100,
totalComments: 5,
wasLikedByMe: false,
isFavorite: false,
dailyNutrition: [],
);
final json = FixtureReader.readAsMap('diets/diet_response.json');
final expectedDiet = Diet.fromJson(json);
when(mockService.getDietBySlug(slug: slug))
.thenAnswer((_) async => expectedDiet);
@@ -113,31 +66,10 @@ void main() {
test('addToFavorite - успешное добавление в избранное', () async {
const dietId = 1;
const expectedDiet = Diet(
id: dietId,
slug: 'test-diet',
name: 'Test Diet',
image: 'https://example.com/image.jpg',
duration: 7,
state: DietState.active,
type: DietType(veg: true, light: false, carb: false, meat: false),
details: 'Test details',
dailySchedule: {},
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
totalLikes: 10,
totalViews: 100,
totalComments: 5,
wasLikedByMe: false,
isFavorite: true,
dailyNutrition: [],
);
final json = FixtureReader.readAsMap('diets/diet_response.json');
final dietJson = Map<String, dynamic>.from(json);
dietJson['is_favorite'] = true;
final expectedDiet = Diet.fromJson(dietJson);
when(mockService.addToFavorite(id: dietId))
.thenAnswer((_) async => expectedDiet);
@@ -151,31 +83,8 @@ void main() {
test('removeFromFavorite - успешное удаление из избранного', () async {
const dietId = 1;
const expectedDiet = Diet(
id: dietId,
slug: 'test-diet',
name: 'Test Diet',
image: 'https://example.com/image.jpg',
duration: 7,
state: DietState.active,
type: DietType(veg: true, light: false, carb: false, meat: false),
details: 'Test details',
dailySchedule: {},
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
totalLikes: 10,
totalViews: 100,
totalComments: 5,
wasLikedByMe: false,
isFavorite: false,
dailyNutrition: [],
);
final json = FixtureReader.readAsMap('diets/diet_response.json');
final expectedDiet = Diet.fromJson(json);
when(mockService.removeFromFavorite(id: dietId))
.thenAnswer((_) async => expectedDiet);