Created
February 1, 2022 16:27
-
-
Save AbedElazizShe/eced1f02e05d90a7261fe4b58a243618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:domain/domain.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
import 'package:mockito/annotations.dart'; | |
import 'package:mockito/mockito.dart'; | |
import '../../mock/mock_article_model.dart'; | |
import 'get_articles_use_case_test.mocks.dart'; | |
@GenerateMocks([ | |
ArticlesRepository, | |
]) | |
void main() { | |
late ArticlesRepository articlesRepository; | |
late GetArticlesUseCase getArticlesUseCase; | |
setUp(() { | |
articlesRepository = MockArticlesRepository(); | |
getArticlesUseCase = GetArticlesUseCase(articlesRepository); | |
}); | |
test( | |
'should retrieve articles from MOST_EMAILED remote when there is no cached data and RequestType is RequestType.mostEmailed', | |
() { | |
final List<ArticleModel> results = mockArticles; | |
const String requestTypeValue = 'most-emailed'; | |
// Get from cache while empty | |
when(articlesRepository.getCachedArticles(requestTypeValue)) | |
.thenAnswer((_) async => <ArticleModel>[]); | |
when(articlesRepository.saveArticles( | |
json.encode(results), requestTypeValue)) | |
.thenAnswer((_) async => 1); | |
when(articlesRepository.getMostEmailedArticles()) | |
.thenAnswer((_) async => results); | |
getArticlesUseCase.call( | |
requestType: RequestType.mostEmailed, | |
onSuccess: (List<ArticleModel> articles) { | |
verify(articlesRepository.getMostEmailedArticles()).called(1); | |
expect(articles, isNotNull); | |
expect(articles, results); | |
}, | |
onFailure: () {}); | |
}); | |
// TODO: Test all scenarios | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment