forked from eatvio/eatvio_app
feat(dependencies): add rxdart package and improve string extension methods for better handling of empty strings and gender parsing
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
import 'package:eatvio_app/features/complaining/models/complain_model.dart';
|
||||
import 'package:eatvio_app/features/complaining/repositories/complaining_repository.dart';
|
||||
import 'package:eatvio_app/features/complaining/services/complaining_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'complaining_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ComplainingService>()])
|
||||
void main() {
|
||||
group('ComplainingRepository', () {
|
||||
late ComplainingRepository repository;
|
||||
late MockComplainingService mockService;
|
||||
|
||||
setUp(() {
|
||||
mockService = MockComplainingService();
|
||||
repository = ComplainingRepository(service: mockService);
|
||||
});
|
||||
|
||||
test('sendPlanComplain - успешная отправка жалобы на план', () async {
|
||||
const slug = 'test-plan';
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1', 'tag2'],
|
||||
);
|
||||
|
||||
when(mockService.sendPlanComplain(slug: slug, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendPlanComplain(slug: slug, category: category, body: body);
|
||||
|
||||
verify(mockService.sendPlanComplain(slug: slug, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendRecipeComplain - успешная отправка жалобы на рецепт', () async {
|
||||
const slug = 'test-recipe';
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1'],
|
||||
);
|
||||
|
||||
when(mockService.sendRecipeComplain(slug: slug, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendRecipeComplain(slug: slug, category: category, body: body);
|
||||
|
||||
verify(mockService.sendRecipeComplain(slug: slug, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendBlogPostsComplain - успешная отправка жалобы на пост', () async {
|
||||
const id = 1;
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: [],
|
||||
);
|
||||
|
||||
when(mockService.sendBlogPostsComplain(id: id, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendBlogPostsComplain(id: id, category: category, body: body);
|
||||
|
||||
verify(mockService.sendBlogPostsComplain(id: id, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendProfileComplain - успешная отправка жалобы на профиль', () async {
|
||||
const slug = 'test-profile';
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1'],
|
||||
);
|
||||
|
||||
when(mockService.sendProfileComplain(slug: slug, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendProfileComplain(slug: slug, category: category, body: body);
|
||||
|
||||
verify(mockService.sendProfileComplain(slug: slug, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendDietComplain - успешная отправка жалобы на диету', () async {
|
||||
const id = 1;
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1'],
|
||||
);
|
||||
|
||||
when(mockService.sendDietComplain(id: id, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendDietComplain(id: id, category: category, body: body);
|
||||
|
||||
verify(mockService.sendDietComplain(id: id, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendCommentComplain - успешная отправка жалобы на комментарий', () async {
|
||||
const id = 1;
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1'],
|
||||
);
|
||||
|
||||
when(mockService.sendCommentComplain(id: id, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendCommentComplain(id: id, category: category, body: body);
|
||||
|
||||
verify(mockService.sendCommentComplain(id: id, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendPlanComplain - пробрасывает исключение', () async {
|
||||
const slug = 'test-plan';
|
||||
const category = 'spam';
|
||||
const body = ComplainModel();
|
||||
|
||||
when(mockService.sendPlanComplain(slug: slug, category: category, body: body))
|
||||
.thenThrow(Exception('Ошибка отправки жалобы'));
|
||||
|
||||
expect(
|
||||
() => repository.sendPlanComplain(slug: slug, category: category, body: body),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user