forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -233,6 +233,119 @@ void main() {
|
||||
expect(step.image, 'step1.jpg');
|
||||
expect(step.description, 'Step description');
|
||||
});
|
||||
|
||||
test('toJson serializes Step correctly', () {
|
||||
const step = Step(
|
||||
image: 'step1.jpg',
|
||||
description: 'Step description',
|
||||
);
|
||||
|
||||
final json = step.toJson();
|
||||
|
||||
expect(json['image'], 'step1.jpg');
|
||||
expect(json['description_md'], 'Step description');
|
||||
});
|
||||
});
|
||||
|
||||
group('Recipe', () {
|
||||
test('toJson serializes Recipe correctly', () {
|
||||
const author = Author(
|
||||
authorSlug: 'chef',
|
||||
authorName: 'Chef Name',
|
||||
authorProfileIcon: 'icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
authorPlaceInRating: null,
|
||||
);
|
||||
|
||||
final ingredients = [
|
||||
const Ingredient(name: 'Flour', unit: 'cup', portion: '1', productId: 1),
|
||||
];
|
||||
|
||||
final steps = [
|
||||
const Step(image: 'step1.jpg', description: 'Step 1 description'),
|
||||
];
|
||||
|
||||
final recipe = Recipe(
|
||||
id: 1,
|
||||
image: 'recipe.jpg',
|
||||
state: 'published',
|
||||
cookingTime: 30,
|
||||
activeCookingTime: 15,
|
||||
ingredients: ingredients,
|
||||
description: 'Recipe description',
|
||||
steps: steps,
|
||||
videoUrl: 'video.mp4',
|
||||
createdAt: DateTime(2023, 1, 1),
|
||||
updatedAt: DateTime(2023, 1, 2),
|
||||
title: 'Test Recipe',
|
||||
type: 'main',
|
||||
slug: 'test-recipe',
|
||||
commentsCount: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
calories: 250.0,
|
||||
servings: 4,
|
||||
likesCount: 10,
|
||||
viewsCount: 100,
|
||||
tags: [const Tag(name: 'sweet')],
|
||||
author: author,
|
||||
);
|
||||
|
||||
final json = recipe.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['title'], 'Test Recipe');
|
||||
expect(json['slug'], 'test-recipe');
|
||||
expect(json['cooking_time'], 30);
|
||||
expect(json['energy_per_serving'], 250.0);
|
||||
expect(json.containsKey('ingredients'), isTrue);
|
||||
expect(json.containsKey('steps'), isTrue);
|
||||
expect(json.containsKey('tags'), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('Tag', () {
|
||||
test('toJson serializes Tag correctly', () {
|
||||
const tag = Tag(name: 'dessert');
|
||||
|
||||
final json = tag.toJson();
|
||||
|
||||
expect(json['name'], 'dessert');
|
||||
});
|
||||
});
|
||||
|
||||
group('Ingredient', () {
|
||||
test('toJson serializes Ingredient correctly', () {
|
||||
const ingredient = Ingredient(
|
||||
name: 'Flour',
|
||||
unit: 'cup',
|
||||
portion: '1',
|
||||
productId: 1,
|
||||
);
|
||||
|
||||
final json = ingredient.toJson();
|
||||
|
||||
expect(json['name'], 'Flour');
|
||||
expect(json['unit'], 'cup');
|
||||
expect(json['portion'], '1');
|
||||
expect(json['product_nutritional_id'], 1);
|
||||
});
|
||||
|
||||
test('toJson serializes Ingredient with null unit correctly', () {
|
||||
const ingredient = Ingredient(
|
||||
name: 'Salt',
|
||||
unit: null,
|
||||
portion: 'pinch',
|
||||
productId: 2,
|
||||
);
|
||||
|
||||
final json = ingredient.toJson();
|
||||
|
||||
expect(json['name'], 'Salt');
|
||||
expect(json['unit'], isNull);
|
||||
expect(json['portion'], 'pinch');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user