From d0f6db181fc1b8f92ffc8c648a0003c755938e89 Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 16 May 2025 18:39:39 +0700 Subject: [PATCH] TF-3719 Write unit test for cast `getChanges` throw exception Signed-off-by: dab246 --- .../thread_repository_impl_test.dart | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/features/thread/data/repository/thread_repository_impl_test.dart b/test/features/thread/data/repository/thread_repository_impl_test.dart index 8d2329e8a..30eb8efee 100644 --- a/test/features/thread/data/repository/thread_repository_impl_test.dart +++ b/test/features/thread/data/repository/thread_repository_impl_test.dart @@ -752,6 +752,56 @@ void main() { verify(stateDataSource.saveState(any, any, any)); }); + test( + 'when local has mail in cache and getLatestChanges is true ' + 'and email change throw exception ' + 'should not update mail in cache', () async { + // Arrange + final localEmails = List.generate( + ThreadConstants.defaultLimit.value.toInt(), + (index) => Email(id: EmailId(Id('local_$index'))), + ); + when(threadDataSource.getAllEmailCache( + any, + any, + filterOption: anyNamed('filterOption'), + inMailboxId: anyNamed('inMailboxId'), + limit: anyNamed('limit'), + sort: anyNamed('sort'), + )).thenAnswer((_) => Future.value(localEmails)); + + when(stateDataSource.getState(any, any, any)) + .thenAnswer((_) => Future.value(State('local_state'))); + + when(threadDataSource.getChanges( + any, + any, + any, + propertiesCreated: anyNamed('propertiesCreated'), + propertiesUpdated: anyNamed('propertiesUpdated'), + )).thenThrow(Exception('Too many items in get method')); + + // Assert + expectLater( + () => threadRepository + .getAllEmail( + SessionFixtures.aliceSession, + AccountFixtures.aliceAccountId, + getLatestChanges: true, + ) + .toList(), + throwsA(isA().having((e) => e.toString(), 'description', contains('Too many items in get method'))), + ); + verifyNever(threadDataSource.update( + any, + any, + created: anyNamed('created'), + destroyed: anyNamed('destroyed'), + updated: anyNamed('updated'), + )); + verifyNever(stateDataSource.saveState(any, any, any)); + }); + test( 'when getChanges has more changes should fetch all changes ' 'and first email change has destroyed mail '