forked from eatvio/eatvio_app
99 lines
3.1 KiB
Dart
99 lines
3.1 KiB
Dart
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
|
|
import 'package:eatvio_app/features/recipe/services/about_recipe_service.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:mockito/annotations.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
|
|
|
import 'about_recipe_service_test.mocks.dart';
|
|
|
|
@GenerateNiceMocks([MockSpec<AboutRecipeService>()])
|
|
void main() {
|
|
group('AboutRecipeService', () {
|
|
late MockAboutRecipeService mockAboutRecipeService;
|
|
|
|
setUp(() {
|
|
mockAboutRecipeService = MockAboutRecipeService();
|
|
});
|
|
|
|
test('likeRecipe likes recipe by slug', () async {
|
|
const slug = 'test-recipe-slug';
|
|
|
|
when(mockAboutRecipeService.likeRecipe(slug: slug)).thenAnswer((_) async => Future.value());
|
|
|
|
await mockAboutRecipeService.likeRecipe(slug: slug);
|
|
|
|
verify(mockAboutRecipeService.likeRecipe(slug: slug)).called(1);
|
|
});
|
|
|
|
test('addToFavorite adds recipe to favorite by slug', () async {
|
|
const slug = 'test-recipe-slug';
|
|
|
|
when(mockAboutRecipeService.addToFavorite(slug: slug)).thenAnswer((_) async => Future.value());
|
|
|
|
await mockAboutRecipeService.addToFavorite(slug: slug);
|
|
|
|
verify(mockAboutRecipeService.addToFavorite(slug: slug)).called(1);
|
|
});
|
|
|
|
test('removeFromFavorite removes recipe from favorite by slug', () async {
|
|
const slug = 'test-recipe-slug';
|
|
|
|
when(mockAboutRecipeService.removeFromFavorite(slug: slug)).thenAnswer((_) async => Future.value());
|
|
|
|
await mockAboutRecipeService.removeFromFavorite(slug: slug);
|
|
|
|
verify(mockAboutRecipeService.removeFromFavorite(slug: slug)).called(1);
|
|
});
|
|
|
|
test('getRecipe returns Recipe by id', () async {
|
|
const id = '1';
|
|
const expected = Recipe(
|
|
id: 1,
|
|
image: 'https://someurl.com/img.jpg',
|
|
state: 'active',
|
|
cookingTime: 30,
|
|
activeCookingTime: 15,
|
|
ingredients: [],
|
|
description: 'Test recipe description',
|
|
steps: [],
|
|
videoUrl: null,
|
|
createdAt: null,
|
|
updatedAt: null,
|
|
title: 'Test Recipe',
|
|
type: 'main',
|
|
slug: 'test-recipe-slug',
|
|
commentsCount: 5,
|
|
wasLikedByMe: false,
|
|
isFavorite: false,
|
|
calories: 300.0,
|
|
servings: 4,
|
|
likesCount: 10,
|
|
viewsCount: 100,
|
|
tags: [],
|
|
author: Author(authorSlug: '', authorName: '', authorProfileIcon: '', authorIsMe: false),
|
|
);
|
|
|
|
when(mockAboutRecipeService.getRecipe(id)).thenAnswer((_) async => expected);
|
|
|
|
final result = await mockAboutRecipeService.getRecipe(id);
|
|
|
|
expect(result, isA<Recipe>());
|
|
expect(result.id, 1);
|
|
expect(result.title, 'Test Recipe');
|
|
verify(mockAboutRecipeService.getRecipe(id)).called(1);
|
|
});
|
|
|
|
test('deleteRecipe deletes recipe by slug', () async {
|
|
const slug = 'test-recipe-slug';
|
|
|
|
when(mockAboutRecipeService.deleteRecipe(slug: slug)).thenAnswer((_) async => Future.value());
|
|
|
|
await mockAboutRecipeService.deleteRecipe(slug: slug);
|
|
|
|
verify(mockAboutRecipeService.deleteRecipe(slug: slug)).called(1);
|
|
});
|
|
});
|
|
}
|
|
|