forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -26,6 +26,33 @@ void main() {
|
||||
expect(model.amount, 10);
|
||||
expect(model.type, RatingEnum.addedRecipe);
|
||||
});
|
||||
|
||||
test('toJson serializes RatingModel correctly', () {
|
||||
final model = RatingModel(
|
||||
date: DateTime(2024, 1, 1),
|
||||
type: RatingEnum.addedRecipe,
|
||||
amount: 10,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['log_scores'], 10);
|
||||
expect(json['log_data'], 'ADDED_RECIPE');
|
||||
expect(json.containsKey('created_at'), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('RatingEnum', () {
|
||||
test('has all expected values', () {
|
||||
expect(RatingEnum.values.length, 7);
|
||||
expect(RatingEnum.addedRecipe, isNotNull);
|
||||
expect(RatingEnum.addedPublicDiet, isNotNull);
|
||||
expect(RatingEnum.addedBlogPost, isNotNull);
|
||||
expect(RatingEnum.invitedUser, isNotNull);
|
||||
expect(RatingEnum.hasMedicalDegree, isNotNull);
|
||||
expect(RatingEnum.consulted, isNotNull);
|
||||
expect(RatingEnum.addedGlossary, isNotNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('RatingPaginationModel', () {
|
||||
@@ -41,6 +68,39 @@ void main() {
|
||||
expect(pagination.data.length, 1);
|
||||
expect(pagination.data.first.amount, 10);
|
||||
});
|
||||
|
||||
test('fromJson creates RatingPaginationModel from JSON', () {
|
||||
final json = {
|
||||
'data': [
|
||||
{
|
||||
'created_at': '2024-01-01T00:00:00Z',
|
||||
'log_data': 'ADDED_RECIPE',
|
||||
'log_scores': 10,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
final pagination = RatingPaginationModel.fromJson(json);
|
||||
|
||||
expect(pagination.data.length, 1);
|
||||
expect(pagination.data.first.amount, 10);
|
||||
expect(pagination.data.first.type, RatingEnum.addedRecipe);
|
||||
});
|
||||
|
||||
test('toJson serializes RatingPaginationModel correctly', () {
|
||||
final rating = RatingModel(
|
||||
date: DateTime(2024, 1, 1),
|
||||
type: RatingEnum.addedRecipe,
|
||||
amount: 10,
|
||||
);
|
||||
|
||||
final pagination = RatingPaginationModel(data: [rating]);
|
||||
|
||||
final json = pagination.toJson();
|
||||
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect((json['data'] as List).length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user