Files
eatvio_app/test/features/feed/models/feed_consultant_model_test.dart
2026-01-14 18:47:11 +03:00

125 lines
3.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:eatvio_app/core/models/pagination_model.dart';
import 'package:eatvio_app/features/feed/models/feed_consultant_model.dart';
import 'package:eatvio_app/features/profile/models/badge_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FeedConsultantModel', () {
test('создает FeedConsultantModel с правильными значениями', () {
const model = FeedConsultantModel(
slug: 'consultant-1',
name: 'Consultant Name',
description: 'Test description',
ratingPlace: 1,
totalScores: 450,
photo: 'https://example.com/photo.jpg',
badges: [
BadgeModel(
id: 1,
title: 'Badge 1',
description: 'Description',
image: 'https://example.com/badge1.jpg',
type: 'type',
),
],
);
expect(model.slug, 'consultant-1');
expect(model.name, 'Consultant Name');
expect(model.totalScores, 450);
expect(model.badges.length, 1);
});
test('fromJson создает FeedConsultantModel из JSON', () {
final json = {
'slug': 'consultant-1',
'name': 'Consultant Name',
'additional_info': 'Test description',
'rating_place': 1,
'total_scores': 450,
'profile_photo_url': 'https://example.com/photo.jpg',
'badges': [
{
'id': 1,
'title': 'Badge 1',
'description': 'Description',
'image': 'https://example.com/badge1.jpg',
'type': 'type'
},
],
};
final model = FeedConsultantModel.fromJson(json);
expect(model.slug, 'consultant-1');
expect(model.totalScores, 450);
});
test('toJson serializes FeedConsultantModel correctly', () {
const model = FeedConsultantModel(
slug: 'consultant-1',
name: 'Consultant Name',
description: 'Test description',
ratingPlace: 1,
totalScores: 450,
photo: 'https://example.com/photo.jpg',
badges: [
BadgeModel(
id: 1,
title: 'Badge 1',
description: 'Description',
image: 'https://example.com/badge1.jpg',
type: 'type',
),
],
);
final json = model.toJson();
expect(json['slug'], 'consultant-1');
expect(json['name'], 'Consultant Name');
expect(json['additional_info'], 'Test description');
expect(json['rating_place'], 1);
expect(json['total_scores'], 450);
expect(json.containsKey('badges'), isTrue);
});
});
group('FeedConsultantPaginationModel', () {
test('создает FeedConsultantPaginationModel с правильными значениями', () {
const consultant = FeedConsultantModel(
slug: 'consultant-1',
name: 'Consultant Name',
description: 'Test description',
ratingPlace: null,
totalScores: 450,
photo: 'https://example.com/photo.jpg',
badges: [],
);
const pagination = FeedConsultantPaginationModel(
data: [consultant],
links: Links(
first: 'https://example.com?page=1',
last: 'https://example.com?page=1',
prev: null,
next: null,
),
meta: Meta(
currentPage: 1,
from: 1,
lastPage: 1,
links: [],
perPage: 10,
to: 1,
total: 1,
),
);
expect(pagination.data.length, 1);
expect(pagination.data.first.slug, 'consultant-1');
});
});
}