forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -30,6 +30,22 @@ void main() {
|
||||
expect(ingredient.name, 'Apple');
|
||||
expect(ingredient.productId, 1);
|
||||
});
|
||||
|
||||
test('toJson serializes Ingredient correctly', () {
|
||||
const ingredient = Ingredient(
|
||||
name: 'Apple',
|
||||
unit: 'gr',
|
||||
portion: '100',
|
||||
productId: 1,
|
||||
);
|
||||
|
||||
final json = ingredient.toJson();
|
||||
|
||||
expect(json['name'], 'Apple');
|
||||
expect(json['unit'], 'gr');
|
||||
expect(json['portion'], '100');
|
||||
expect(json['product_nutritional_id'], 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,18 @@ void main() {
|
||||
expect(product.id, 1);
|
||||
expect(product.name, 'Apple');
|
||||
});
|
||||
|
||||
test('toJson serializes Product correctly', () {
|
||||
const product = Product(
|
||||
id: 1,
|
||||
name: 'Apple',
|
||||
);
|
||||
|
||||
final json = product.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['name'], 'Apple');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
114
test/features/create_recipe/models/recipe_create_model_test.dart
Normal file
114
test/features/create_recipe/models/recipe_create_model_test.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'package:eatvio_app/features/create_recipe/models/ingredient.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/models/recipe_create_model.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/models/step.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('RecipeType enum', () {
|
||||
test('has all expected values', () {
|
||||
expect(RecipeType.values.length, 7);
|
||||
expect(RecipeType.firstMeals, isNotNull);
|
||||
expect(RecipeType.secondMeals, isNotNull);
|
||||
expect(RecipeType.salads, isNotNull);
|
||||
expect(RecipeType.snacks, isNotNull);
|
||||
expect(RecipeType.sweets, isNotNull);
|
||||
expect(RecipeType.drinks, isNotNull);
|
||||
expect(RecipeType.other, isNotNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('RecipeCreateModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'title': 'Test Recipe',
|
||||
'state': 'draft',
|
||||
'description_md': 'Recipe description',
|
||||
'type': 'firstMeals',
|
||||
'video_url': 'https://example.com/video.mp4',
|
||||
'cooking_time': '30',
|
||||
'active_time': '15',
|
||||
'servings': '4',
|
||||
'energy_per_serving': '250',
|
||||
'tags': ['tag1', 'tag2'],
|
||||
'ingredients': [
|
||||
{'name': 'Ingredient 1', 'unit': 'gr', 'portion': '100', 'product_nutritional_id': 1},
|
||||
],
|
||||
'steps': [
|
||||
{'image': 'step1.jpg', 'description': 'Step 1 description'},
|
||||
],
|
||||
};
|
||||
|
||||
final model = RecipeCreateModel.fromJson(json);
|
||||
|
||||
expect(model.title, 'Test Recipe');
|
||||
expect(model.state, 'draft');
|
||||
expect(model.description, 'Recipe description');
|
||||
expect(model.type, RecipeType.firstMeals);
|
||||
expect(model.videoUrl, 'https://example.com/video.mp4');
|
||||
expect(model.cookingTime, '30');
|
||||
expect(model.activeTime, '15');
|
||||
expect(model.servings, '4');
|
||||
expect(model.energyPerServing, '250');
|
||||
expect(model.tags, ['tag1', 'tag2']);
|
||||
expect(model.ingredients.length, 1);
|
||||
expect(model.steps.length, 1);
|
||||
});
|
||||
|
||||
test('fromJson handles null optional fields', () {
|
||||
final json = {
|
||||
'title': 'Test Recipe',
|
||||
'state': 'draft',
|
||||
'description_md': 'Recipe description',
|
||||
'type': 'salads',
|
||||
'servings': '4',
|
||||
'energy_per_serving': '250',
|
||||
'tags': [],
|
||||
'ingredients': [],
|
||||
'steps': [],
|
||||
};
|
||||
|
||||
final model = RecipeCreateModel.fromJson(json);
|
||||
|
||||
expect(model.title, 'Test Recipe');
|
||||
expect(model.type, RecipeType.salads);
|
||||
expect(model.videoUrl, isNull);
|
||||
expect(model.cookingTime, isNull);
|
||||
expect(model.activeTime, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
const ingredient = Ingredient(name: 'Ingredient 1', unit: 'gr', portion: '100', productId: 1);
|
||||
const step = Step(image: 'step1.jpg', description: 'Step 1 description');
|
||||
const model = RecipeCreateModel(
|
||||
title: 'Test Recipe',
|
||||
state: 'draft',
|
||||
description: 'Recipe description',
|
||||
type: RecipeType.firstMeals,
|
||||
videoUrl: 'https://example.com/video.mp4',
|
||||
cookingTime: '30',
|
||||
activeTime: '15',
|
||||
servings: '4',
|
||||
energyPerServing: '250',
|
||||
tags: ['tag1', 'tag2'],
|
||||
ingredients: [ingredient],
|
||||
steps: [step],
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['title'], 'Test Recipe');
|
||||
expect(json['state'], 'draft');
|
||||
expect(json['description_md'], 'Recipe description');
|
||||
expect(json['type'], 'firstMeals');
|
||||
expect(json['video_url'], 'https://example.com/video.mp4');
|
||||
expect(json['cooking_time'], '30');
|
||||
expect(json['active_time'], '15');
|
||||
expect(json['servings'], '4');
|
||||
expect(json['energy_per_serving'], '250');
|
||||
expect(json['tags'], ['tag1', 'tag2']);
|
||||
expect(json['ingredients'], isA<List>());
|
||||
expect(json['steps'], isA<List>());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,5 +72,32 @@ void main() {
|
||||
expect(model.tags, isNull);
|
||||
expect(model.title, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes RecipeModel correctly', () {
|
||||
const model = RecipeModel(
|
||||
ingredients: [],
|
||||
steps: [],
|
||||
tags: ['tag1', 'tag2'],
|
||||
type: 'breakfast',
|
||||
state: 'active',
|
||||
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,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['title'], 'Test Recipe');
|
||||
expect(json['description'], 'Test Description');
|
||||
expect(json['video_url'], 'https://example.com/video.mp4');
|
||||
expect(json['tags'], ['tag1', 'tag2']);
|
||||
expect(json['totalCookingTime'], 30);
|
||||
expect(json['servings'], 4);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,6 +103,62 @@ void main() {
|
||||
expect(tag.name, 'Breakfast');
|
||||
expect(tag.recipesCount, 10);
|
||||
});
|
||||
|
||||
test('toJson serializes RecipeTag correctly', () {
|
||||
final tag = RecipeTag(
|
||||
id: 1,
|
||||
name: 'Breakfast',
|
||||
recipesCount: 10,
|
||||
createdAt: DateTime(2024, 1, 1),
|
||||
updatedAt: DateTime(2024, 1, 2),
|
||||
);
|
||||
|
||||
final json = tag.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['name'], 'Breakfast');
|
||||
expect(json['recipes_count'], 10);
|
||||
expect(json.containsKey('created_at'), isTrue);
|
||||
expect(json.containsKey('updated_at'), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('RecipeTagModel', () {
|
||||
test('toJson serializes RecipeTagModel correctly', () {
|
||||
final tag = RecipeTag(
|
||||
id: 1,
|
||||
name: 'Breakfast',
|
||||
recipesCount: 10,
|
||||
createdAt: DateTime(2024, 1, 1),
|
||||
updatedAt: DateTime(2024, 1, 2),
|
||||
);
|
||||
|
||||
final model = RecipeTagModel(
|
||||
data: [tag],
|
||||
links: const Links(
|
||||
first: 'https://example.com?page=1',
|
||||
last: 'https://example.com?page=1',
|
||||
prev: null,
|
||||
next: null,
|
||||
),
|
||||
meta: const Meta(
|
||||
currentPage: 1,
|
||||
from: 1,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
perPage: 10,
|
||||
to: 1,
|
||||
total: 1,
|
||||
),
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect((json['data'] as List).length, 1);
|
||||
expect(json.containsKey('links'), isTrue);
|
||||
expect(json.containsKey('meta'), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -40,5 +40,26 @@ void main() {
|
||||
expect(step.image, isNull);
|
||||
expect(step.description, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes Step correctly', () {
|
||||
const step = Step(
|
||||
image: 'https://example.com/image.jpg',
|
||||
description: 'Test step description',
|
||||
);
|
||||
|
||||
final json = step.toJson();
|
||||
|
||||
expect(json['image'], 'https://example.com/image.jpg');
|
||||
expect(json['description'], 'Test step description');
|
||||
});
|
||||
|
||||
test('toJson serializes Step with null values correctly', () {
|
||||
const step = Step();
|
||||
|
||||
final json = step.toJson();
|
||||
|
||||
expect(json['image'], isNull);
|
||||
expect(json['description'], isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user