Skip to content

Commit

Permalink
TF-2840 calendar event reject integrate interactor to SingleEmailCont…
Browse files Browse the repository at this point in the history
…roller
  • Loading branch information
tddang-linagora committed May 7, 2024
1 parent d9cc077 commit 3206bf0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -38,6 +39,7 @@ class CalendarEventInteractorBindings extends InteractorsBindings {
Get.lazyPut(() => ParseCalendarEventInteractor(Get.find<CalendarEventRepository>()));
Get.lazyPut(() => AcceptCalendarEventInteractor(Get.find<CalendarEventRepository>()));
Get.lazyPut(() => MaybeCalendarEventInteractor(Get.find<CalendarEventRepository>()));
Get.lazyPut(() => RejectCalendarEventInteractor(Get.find<CalendarEventRepository>()));
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -127,6 +129,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
ParseCalendarEventInteractor? _parseCalendarEventInteractor;
AcceptCalendarEventInteractor? _acceptCalendarEventInteractor;
MaybeCalendarEventInteractor? _maybeCalendarEventInteractor;
RejectCalendarEventInteractor? _rejectCalendarEventInteractor;

final emailContents = RxnString();
final attachments = <Attachment>[].obs;
Expand Down Expand Up @@ -393,6 +396,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
_parseCalendarEventInteractor = getBinding<ParseCalendarEventInteractor>();
_acceptCalendarEventInteractor = getBinding<AcceptCalendarEventInteractor>();
_maybeCalendarEventInteractor = getBinding<MaybeCalendarEventInteractor>();
_rejectCalendarEventInteractor = getBinding<RejectCalendarEventInteractor>();
}

void _injectCalendarEventBindings(Session? session, AccountId? accountId) {
Expand Down Expand Up @@ -1698,6 +1702,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
case EventActionType.maybe:
_maybeCalendarEventAction();
break;
case EventActionType.no:
_rejectCalendarEventAction();
break;
default:
break;
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -79,6 +80,7 @@ const fallbackGenerators = {
MockSpec<PrintEmailInteractor>(),
MockSpec<AcceptCalendarEventInteractor>(),
MockSpec<MaybeCalendarEventInteractor>(),
MockSpec<RejectCalendarEventInteractor>(),
])
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -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>(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);
});
});
});
}

0 comments on commit 3206bf0

Please sign in to comment.