TF-2838 calendar event reject repo implementation

This commit is contained in:
DatDang
2024-04-29 09:46:45 +07:00
committed by Dat H. Pham
parent f9cde9568f
commit 90e17cf075
2 changed files with 37 additions and 0 deletions
@@ -4,6 +4,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_accept_response.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_maybe_response.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_reject_response.dart';
import 'package:tmail_ui_user/features/email/data/datasource/calendar_event_datasource.dart';
import 'package:tmail_ui_user/features/email/domain/repository/calendar_event_repository.dart';
import 'package:tmail_ui_user/features/email/presentation/model/blob_calendar_event.dart';
@@ -28,4 +29,9 @@ class CalendarEventRepositoryImpl extends CalendarEventRepository {
Future<CalendarEventMaybeResponse> maybeEventInvitation(AccountId accountId, Set<Id> blobIds) {
return _calendarEventDataSource[DataSourceType.network]!.maybeEventInvitation(accountId, blobIds);
}
@override
Future<CalendarEventRejectResponse> rejectEventInvitation(AccountId accountId, Set<Id> blobIds) {
return _calendarEventDataSource[DataSourceType.network]!.rejectEventInvitation(accountId, blobIds);
}
}
@@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/properties/event_id.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_accept_response.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_maybe_response.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_reject_response.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:tmail_ui_user/features/email/data/datasource/calendar_event_datasource.dart';
@@ -81,4 +82,34 @@ void main() {
throwsA(isA<NotMaybeableCalendarEventException>()));
});
});
group('calendar event reject repository test:', () {
final calendarEventRejectResponseresponse = CalendarEventRejectResponse(
accountId,
null,
rejected: [EventId(blobId.value)]);
test('should return response when data source return response', () async {
// arrange
when(calendarEventNetworkDataSource.rejectEventInvitation(any, any))
.thenAnswer((_) async => calendarEventRejectResponseresponse);
// act
final response = await calendarEventRepository.rejectEventInvitation(accountId, {blobId});
// assert
expect(response, calendarEventRejectResponseresponse);
});
test('should throw exception when data source throw exception', () {
// arrange
when(calendarEventNetworkDataSource.rejectEventInvitation(any, any))
.thenThrow(NotRejectableCalendarEventException());
// assert
expect(
() => calendarEventRepository.rejectEventInvitation(accountId, {blobId}),
throwsA(isA<NotRejectableCalendarEventException>()));
});
});
}