diff --git a/lib/features/email/presentation/bindings/calendar_event_interactor_bindings.dart b/lib/features/email/presentation/bindings/calendar_event_interactor_bindings.dart index be1e270481..90271d7712 100644 --- a/lib/features/email/presentation/bindings/calendar_event_interactor_bindings.dart +++ b/lib/features/email/presentation/bindings/calendar_event_interactor_bindings.dart @@ -11,6 +11,7 @@ import 'package:tmail_ui_user/features/email/data/repository/calendar_event_repo import 'package:tmail_ui_user/features/email/domain/repository/calendar_event_repository.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_accept_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/maybe_calendar_event_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_reject_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/parse_calendar_event_interactor.dart'; import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart'; import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart'; @@ -38,6 +39,7 @@ class CalendarEventInteractorBindings extends InteractorsBindings { Get.lazyPut(() => ParseCalendarEventInteractor(Get.find())); Get.lazyPut(() => AcceptCalendarEventInteractor(Get.find())); Get.lazyPut(() => MaybeCalendarEventInteractor(Get.find())); + Get.lazyPut(() => RejectCalendarEventInteractor(Get.find())); } @override diff --git a/lib/features/email/presentation/controller/single_email_controller.dart b/lib/features/email/presentation/controller/single_email_controller.dart index 4586c8178d..2d4ab4f4fd 100644 --- a/lib/features/email/presentation/controller/single_email_controller.dart +++ b/lib/features/email/presentation/controller/single_email_controller.dart @@ -38,6 +38,7 @@ import 'package:tmail_ui_user/features/email/domain/model/move_to_mailbox_reques import 'package:tmail_ui_user/features/email/domain/model/send_receipt_to_sender_request.dart'; import 'package:tmail_ui_user/features/email/domain/state/calendar_event_accept_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/calendar_event_maybe_state.dart'; +import 'package:tmail_ui_user/features/email/domain/state/calendar_event_reject_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/calendar_event_reply_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/download_attachments_state.dart'; @@ -53,6 +54,7 @@ import 'package:tmail_ui_user/features/email/domain/state/unsubscribe_email_stat import 'package:tmail_ui_user/features/email/domain/state/view_attachment_for_web_state.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_accept_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/maybe_calendar_event_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_reject_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/download_attachments_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/export_attachment_interactor.dart'; @@ -127,6 +129,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin { ParseCalendarEventInteractor? _parseCalendarEventInteractor; AcceptCalendarEventInteractor? _acceptCalendarEventInteractor; MaybeCalendarEventInteractor? _maybeCalendarEventInteractor; + RejectCalendarEventInteractor? _rejectCalendarEventInteractor; final emailContents = RxnString(); final attachments = [].obs; @@ -393,6 +396,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin { _parseCalendarEventInteractor = getBinding(); _acceptCalendarEventInteractor = getBinding(); _maybeCalendarEventInteractor = getBinding(); + _rejectCalendarEventInteractor = getBinding(); } void _injectCalendarEventBindings(Session? session, AccountId? accountId) { @@ -1698,6 +1702,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin { case EventActionType.maybe: _maybeCalendarEventAction(); break; + case EventActionType.no: + _rejectCalendarEventAction(); + break; default: break; } @@ -1715,6 +1722,18 @@ class SingleEmailController extends BaseController with AppLoaderMixin { } } + void _rejectCalendarEventAction() { + if (_rejectCalendarEventInteractor == null + || _displayingEventBlobId == null + || mailboxDashBoardController.accountId.value == null) { + consumeState(Stream.value(Left(CalendarEventRejectFailure()))); + } else { + consumeState(_rejectCalendarEventInteractor!.execute( + mailboxDashBoardController.accountId.value!, + {_displayingEventBlobId!})); + } + } + void _maybeCalendarEventAction() { if (_maybeCalendarEventInteractor == null || _displayingEventBlobId == null diff --git a/test/features/email/presentation/controller/single_email_controller_test.dart b/test/features/email/presentation/controller/single_email_controller_test.dart index 57791021cb..9b0bfc9808 100644 --- a/test/features/email/presentation/controller/single_email_controller_test.dart +++ b/test/features/email/presentation/controller/single_email_controller_test.dart @@ -19,6 +19,7 @@ import 'package:tmail_ui_user/features/email/domain/state/parse_calendar_event_s import 'package:tmail_ui_user/features/email/domain/state/view_attachment_for_web_state.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_accept_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/maybe_calendar_event_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_reject_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/download_attachments_interactor.dart'; import 'package:tmail_ui_user/features/email/domain/usecases/export_attachment_interactor.dart'; @@ -79,6 +80,7 @@ const fallbackGenerators = { MockSpec(), MockSpec(), MockSpec(), + MockSpec(), ]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -322,5 +324,32 @@ void main() { verify(maybeCalendarEventInteractor.execute(testAccountId, {blobId})).called(1); }); }); + + group('reject test:', () { + final rejectCalendarEventInteractor = MockRejectCalendarEventInteractor(); + + test('should call execute on RejectCalendarEventInteractor ' + 'when onCalendarEventReplyAction is called on EventActionType.yes', () async { + // arrange + when(mailboxDashboardController.selectedEmail).thenReturn(Rxn(null)); + when(mailboxDashboardController.emailUIAction).thenReturn(Rxn(null)); + when(mailboxDashboardController.viewState).thenReturn(Rx(Right(UIState.idle))); + singleEmailController.onInit(); + Get.put(rejectCalendarEventInteractor); + mailboxDashboardController.accountId.refresh(); + singleEmailController.handleSuccessViewState( + ParseCalendarEventSuccess([ + BlobCalendarEvent( + blobId: blobId, + calendarEventList: [calendarEvent])])); + + // act + singleEmailController.onCalendarEventReplyAction(EventActionType.no); + await untilCalled(rejectCalendarEventInteractor.execute(any, any)); + + // assert + verify(rejectCalendarEventInteractor.execute(testAccountId, {blobId})).called(1); + }); + }); }); }