forked from eatvio/eatvio_app
feat(test): comments, auth, feed
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import 'package:eatvio_app/core/comments/models/comment_update_model.dart';
|
||||
import 'package:eatvio_app/core/comments/repositories/comments_repository.dart';
|
||||
import 'package:eatvio_app/core/comments/services/comments_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'comments_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<CommentsService>()])
|
||||
void main() {
|
||||
group('CommentsRepository', () {
|
||||
late CommentsRepository commentsRepository;
|
||||
late MockCommentsService mockCommentsService;
|
||||
|
||||
setUp(() {
|
||||
mockCommentsService = MockCommentsService();
|
||||
commentsRepository = CommentsRepository(service: mockCommentsService);
|
||||
});
|
||||
|
||||
test('deleteComment - успешное удаление комментария', () async {
|
||||
const commentId = 1;
|
||||
|
||||
when(mockCommentsService.deleteComment(commentId))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await commentsRepository.deleteComment(id: commentId);
|
||||
|
||||
verify(mockCommentsService.deleteComment(commentId)).called(1);
|
||||
});
|
||||
|
||||
test('deleteComment - пробрасывает исключение', () async {
|
||||
const commentId = 1;
|
||||
|
||||
when(mockCommentsService.deleteComment(commentId))
|
||||
.thenThrow(Exception('Ошибка удаления'));
|
||||
|
||||
expect(
|
||||
() => commentsRepository.deleteComment(id: commentId),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
|
||||
test('updateComment - успешное обновление комментария', () async {
|
||||
const commentId = 1;
|
||||
const newBody = 'Обновлённый текст комментария';
|
||||
final updateModel = CommentUpdateModel(body: newBody);
|
||||
|
||||
when(mockCommentsService.updateComment(commentId, updateModel))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await commentsRepository.updateComment(id: commentId, body: newBody);
|
||||
|
||||
verify(mockCommentsService.updateComment(
|
||||
commentId,
|
||||
argThat(
|
||||
predicate<CommentUpdateModel>(
|
||||
(m) => m.body == newBody,
|
||||
),
|
||||
),
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('updateComment - пробрасывает исключение', () async {
|
||||
const commentId = 1;
|
||||
const newBody = 'Обновлённый текст';
|
||||
|
||||
when(mockCommentsService.updateComment(
|
||||
commentId,
|
||||
any,
|
||||
)).thenThrow(Exception('Ошибка обновления'));
|
||||
|
||||
expect(
|
||||
() => commentsRepository.updateComment(id: commentId, body: newBody),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user