forked from eatvio/eatvio_app
feat(tests): added services tests and fixtures
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/models/recipe_model.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/models/recipe_tag_model.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/services/recipe_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'recipe_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<CreateRecipeService>()])
|
||||
void main() {
|
||||
group('CreateRecipeService', () {
|
||||
late MockCreateRecipeService mockCreateRecipeService;
|
||||
|
||||
setUp(() {
|
||||
mockCreateRecipeService = MockCreateRecipeService();
|
||||
});
|
||||
|
||||
test('likeRecipe - лайкает рецепт', () async {
|
||||
const slug = 'test-recipe';
|
||||
|
||||
when(mockCreateRecipeService.likeRecipe(slug: slug))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockCreateRecipeService.likeRecipe(slug: slug);
|
||||
|
||||
verify(mockCreateRecipeService.likeRecipe(slug: slug)).called(1);
|
||||
});
|
||||
|
||||
test('getRecipe - возвращает рецепт', () async {
|
||||
const id = '1';
|
||||
const expectedRecipe = RecipeModel(
|
||||
ingredients: [],
|
||||
steps: [],
|
||||
tags: [],
|
||||
type: 'breakfast',
|
||||
state: 'published',
|
||||
title: 'Test Recipe',
|
||||
description: 'Test Description',
|
||||
videoUrl: 'https://example.com/video.mp4',
|
||||
image: 'https://example.com/image.jpg',
|
||||
totalCookingTime: 30,
|
||||
activeCookTime: 20,
|
||||
servings: 4,
|
||||
energyPerServing: 250,
|
||||
);
|
||||
|
||||
when(mockCreateRecipeService.getRecipe(id))
|
||||
.thenAnswer((_) async => expectedRecipe);
|
||||
|
||||
final result = await mockCreateRecipeService.getRecipe(id);
|
||||
|
||||
expect(result, isA<RecipeModel>());
|
||||
expect(result.title, 'Test Recipe');
|
||||
verify(mockCreateRecipeService.getRecipe(id)).called(1);
|
||||
});
|
||||
|
||||
test('getTags - возвращает теги рецептов', () async {
|
||||
const expectedTags = RecipeTagModel(
|
||||
data: [],
|
||||
links: Links(first: '', last: '', prev: null, next: null),
|
||||
meta: Meta(currentPage: 1, from: null, lastPage: 1, links: [], perPage: 10, to: null, total: 0),
|
||||
);
|
||||
|
||||
when(mockCreateRecipeService.getTags())
|
||||
.thenAnswer((_) async => expectedTags);
|
||||
|
||||
final result = await mockCreateRecipeService.getTags();
|
||||
|
||||
expect(result, isA<RecipeTagModel>());
|
||||
verify(mockCreateRecipeService.getTags()).called(1);
|
||||
});
|
||||
|
||||
test('publishRecipe - публикует рецепт', () async {
|
||||
final formData = FormData.fromMap({});
|
||||
|
||||
when(mockCreateRecipeService.publishRecipe(formData: formData))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockCreateRecipeService.publishRecipe(formData: formData);
|
||||
|
||||
verify(mockCreateRecipeService.publishRecipe(formData: formData)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user