forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -141,5 +141,88 @@ void main() {
|
||||
expect(recipe.steps!.length, 2);
|
||||
expect(recipe.videoUrl, 'video.mp4');
|
||||
});
|
||||
|
||||
test('creates MyRecipeModel from JSON', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'image': 'image.jpg',
|
||||
'state': 'published',
|
||||
'cooking_time': 30,
|
||||
'active_time': 15,
|
||||
'description_md': 'Test recipe',
|
||||
'steps': null,
|
||||
'video_url': null,
|
||||
'title': 'Recipe 1',
|
||||
'slug': 'recipe-1',
|
||||
'energy_per_serving': 250.0,
|
||||
'total_likes': 10,
|
||||
'total_views': 100,
|
||||
};
|
||||
|
||||
final recipe = MyRecipeModel.fromJson(json);
|
||||
|
||||
expect(recipe.id, 1);
|
||||
expect(recipe.title, 'Recipe 1');
|
||||
expect(recipe.cookingTime, 30);
|
||||
expect(recipe.calories, 250.0);
|
||||
});
|
||||
|
||||
test('toJson serializes MyRecipeModel correctly', () {
|
||||
const recipe = MyRecipeModel(
|
||||
id: 1,
|
||||
image: 'image.jpg',
|
||||
state: 'published',
|
||||
cookingTime: 30,
|
||||
activeCookingTime: 15,
|
||||
description: 'Test recipe',
|
||||
steps: null,
|
||||
videoUrl: null,
|
||||
title: 'Recipe 1',
|
||||
slug: 'recipe-1',
|
||||
calories: 250.0,
|
||||
likesCount: 10,
|
||||
viewsCount: 100,
|
||||
);
|
||||
|
||||
final json = recipe.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['title'], 'Recipe 1');
|
||||
expect(json['slug'], 'recipe-1');
|
||||
expect(json['cooking_time'], 30);
|
||||
expect(json['active_time'], 15);
|
||||
expect(json['energy_per_serving'], 250.0);
|
||||
expect(json['total_likes'], 10);
|
||||
expect(json['total_views'], 100);
|
||||
});
|
||||
});
|
||||
|
||||
group('MyRecipePaginationModel', () {
|
||||
test('toJson serializes MyRecipePaginationModel correctly', () {
|
||||
final recipes = [
|
||||
const MyRecipeModel(
|
||||
id: 1,
|
||||
image: 'image1.jpg',
|
||||
state: 'published',
|
||||
cookingTime: 30,
|
||||
activeCookingTime: 15,
|
||||
description: 'Test recipe 1',
|
||||
steps: null,
|
||||
videoUrl: null,
|
||||
title: 'Recipe 1',
|
||||
slug: 'recipe-1',
|
||||
calories: 250.0,
|
||||
likesCount: 10,
|
||||
viewsCount: 100,
|
||||
),
|
||||
];
|
||||
|
||||
final model = MyRecipePaginationModel(data: recipes);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect((json['data'] as List).length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user