forked from eatvio/eatvio_app
feat(tests): added services tests and fixtures
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import 'package:eatvio_app/features/complaining/models/complain_model.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_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ComplainingService>()])
|
||||
void main() {
|
||||
group('ComplainingService', () {
|
||||
late MockComplainingService mockComplainingService;
|
||||
|
||||
setUp(() {
|
||||
mockComplainingService = MockComplainingService();
|
||||
});
|
||||
|
||||
test('sendPlanComplain - отправляет жалобу на план', () async {
|
||||
const slug = 'test-plan';
|
||||
const category = 'spam';
|
||||
const complainModel = ComplainModel(description: 'Test complaint', tags: []);
|
||||
|
||||
when(mockComplainingService.sendPlanComplain(slug: slug, category: category, body: complainModel))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockComplainingService.sendPlanComplain(slug: slug, category: category, body: complainModel);
|
||||
|
||||
verify(mockComplainingService.sendPlanComplain(slug: slug, category: category, body: complainModel)).called(1);
|
||||
});
|
||||
|
||||
test('sendRecipeComplain - отправляет жалобу на рецепт', () async {
|
||||
const slug = 'test-recipe';
|
||||
const category = 'spam';
|
||||
const complainModel = ComplainModel(description: 'Test complaint', tags: []);
|
||||
|
||||
when(mockComplainingService.sendRecipeComplain(slug: slug, category: category, body: complainModel))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockComplainingService.sendRecipeComplain(slug: slug, category: category, body: complainModel);
|
||||
|
||||
verify(mockComplainingService.sendRecipeComplain(slug: slug, category: category, body: complainModel)).called(1);
|
||||
});
|
||||
|
||||
test('sendBlogPostsComplain - отправляет жалобу на пост блога', () async {
|
||||
const id = 1;
|
||||
const category = 'spam';
|
||||
const complainModel = ComplainModel(description: 'Test complaint', tags: []);
|
||||
|
||||
when(mockComplainingService.sendBlogPostsComplain(id: id, category: category, body: complainModel))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockComplainingService.sendBlogPostsComplain(id: id, category: category, body: complainModel);
|
||||
|
||||
verify(mockComplainingService.sendBlogPostsComplain(id: id, category: category, body: complainModel)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user