forked from eatvio/eatvio_app
feat(tests): added services tests and fixtures
This commit is contained in:
@@ -14,6 +14,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
import 'feed_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<FeedService>()])
|
||||
@@ -86,28 +87,8 @@ void main() {
|
||||
|
||||
test('getBlogPost - успешное получение поста', () async {
|
||||
const postId = 1;
|
||||
final expectedPost = FeedBlogPostModel(
|
||||
id: postId,
|
||||
state: 'published',
|
||||
image: 'https://example.com/image.jpg',
|
||||
description: 'Описание',
|
||||
author: const Author(
|
||||
authorSlug: 'author-slug',
|
||||
authorName: 'Автор',
|
||||
authorProfileIcon: 'https://example.com/photo.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
videoUrl: '',
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
title: 'Заголовок',
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
);
|
||||
final json = FixtureReader.readAsMap('feed/feed_blog_post_response.json');
|
||||
final expectedPost = FeedBlogPostModel.fromJson(json);
|
||||
|
||||
when(mockFeedService.getBlogPost(postId: postId)).thenAnswer((_) async => expectedPost);
|
||||
|
||||
@@ -246,36 +227,8 @@ void main() {
|
||||
const duration = 30;
|
||||
const minPrice = 1000;
|
||||
const maxPrice = 5000;
|
||||
final expectedPlans = PlanPaginationModel(
|
||||
data: [
|
||||
PlanModel(
|
||||
id: 1,
|
||||
slug: 'weight-loss-plan',
|
||||
name: 'Weight Loss Plan',
|
||||
image: 'https://example.com/plan.jpg',
|
||||
duration: duration,
|
||||
state: 'active',
|
||||
type: const PlanType(fit: false, slim: true, behavior: false, wellness: false),
|
||||
details: 'Weight loss plan description',
|
||||
packetsCount: 30,
|
||||
author: const Author(
|
||||
authorSlug: 'consultant-1',
|
||||
authorName: 'Consultant Name',
|
||||
authorProfileIcon: 'https://example.com/consultant.jpg',
|
||||
authorIsMe: false,
|
||||
),
|
||||
totalLikes: 100,
|
||||
totalViews: 1000,
|
||||
totalComments: 50,
|
||||
isFavorite: false,
|
||||
minPriceOfOptions: minPrice.toDouble(),
|
||||
maxPriceOfOptions: maxPrice.toDouble(),
|
||||
wasLikedByMe: false,
|
||||
),
|
||||
],
|
||||
links: const Links(first: '', last: '', prev: null, next: null),
|
||||
meta: const Meta(currentPage: 1, lastPage: 1, total: 1, perPage: 10, from: null, links: [Link(url: null, label: null, active: null)], to: null),
|
||||
);
|
||||
final json = FixtureReader.readAsMap('feed/plan_pagination_response.json');
|
||||
final expectedPlans = PlanPaginationModel.fromJson(json);
|
||||
|
||||
when(
|
||||
mockFeedService.getPlans(page: page, query: query, types: types, duration: duration, minPrice: minPrice, maxPrice: maxPrice),
|
||||
@@ -310,21 +263,8 @@ void main() {
|
||||
|
||||
test('getBlogPostComments - возвращает комментарии поста блога', () async {
|
||||
const id = '1';
|
||||
final expectedComments = CommentModel(
|
||||
data: [
|
||||
Comment(
|
||||
id: 1,
|
||||
authorName: 'User 1',
|
||||
authorSlug: 'user-1',
|
||||
authorProfileIcon: 'https://example.com/user1.jpg',
|
||||
body: 'Great post!',
|
||||
childrenComments: [],
|
||||
createdAt: DateTime(2024, 1, 15),
|
||||
),
|
||||
],
|
||||
links: const Links(first: '', last: '', prev: null, next: null),
|
||||
meta: const Meta(currentPage: 1, lastPage: 1, total: 1, perPage: 10, from: null, links: [Link(url: null, label: null, active: null)], to: null),
|
||||
);
|
||||
final json = FixtureReader.readAsMap('feed/comment_response.json');
|
||||
final expectedComments = CommentModel.fromJson(json);
|
||||
|
||||
when(mockFeedService.getBlogPostComments(id: id)).thenAnswer((_) async => expectedComments);
|
||||
|
||||
@@ -498,22 +438,8 @@ void main() {
|
||||
|
||||
test('getConsultants - возвращает список консультантов', () async {
|
||||
const name = 'Anna';
|
||||
final expectedConsultants = [
|
||||
const FeedConsultantModel(
|
||||
slug: 'consultant-1',
|
||||
name: 'Anna Ivanova',
|
||||
description: 'Test consultant description',
|
||||
totalScores: 5,
|
||||
photo: 'https://example.com/consultant1.jpg',
|
||||
badges: [],
|
||||
),
|
||||
];
|
||||
|
||||
final expectedPagination = FeedConsultantPaginationModel(
|
||||
data: expectedConsultants,
|
||||
links: const Links(first: '', last: '', prev: null, next: null),
|
||||
meta: const Meta(currentPage: 1, lastPage: 1, total: 1, perPage: 10, from: null, links: [Link(url: null, label: null, active: null)], to: null),
|
||||
);
|
||||
final json = FixtureReader.readAsMap('feed/consultant_pagination_response.json');
|
||||
final expectedPagination = FeedConsultantPaginationModel.fromJson(json);
|
||||
|
||||
when(mockFeedService.getConsultants(name: name)).thenAnswer((_) async => expectedPagination);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user