Skip to content

Instantly share code, notes, and snippets.

@PreyeaRegmi
Created September 8, 2021 11:56
Show Gist options
  • Save PreyeaRegmi/e02ac591b9124fa538d27c2ece8ee60c to your computer and use it in GitHub Desktop.
Save PreyeaRegmi/e02ac591b9124fa538d27c2ece8ee60c to your computer and use it in GitHub Desktop.
test(
"Fetch loan should not fail with any exception when mocked with success response",
() {
FetchLoanDetail fetchLoanUseCase =
FetchLoanDetail(MockedSucessRateFetchRepository(LoanDetailDTO(3)));
fetchLoanUseCase.execute(LoanParamRequest(100, 2), (data) {},
expectAsync1((error) {
expect(error, isNot(isInstanceOf<UseCaseNotImplementedException>()),
reason: "There is no implementation added to this use case");
}));
});
test("Use case must also fail when fetch loan fails from network", () {
FetchLoanDetail fetchLoanUseCase = FetchLoanDetail(
MockedFailedRateFetchRepository(RateFetchFailType.NETWORK));
fetchLoanUseCase.execute(LoanParamRequest(100, 2), (data) {},
expectAsync1((error) {
expect(error, isNot(isInstanceOf<RateFetchFailException>()),
reason:
"Usecase didn't fail with RateFetchException on network failure");
}));
});
test(
"EMI must be 150391.64490861617 for amount = 10,000, rate = 15%, time =24 months",
() {
FetchLoanDetail fetchLoanUseCase =
FetchLoanDetail(MockedSucessRateFetchRepository(LoanDetailDTO(15)));
fetchLoanUseCase.execute(
LoanParamRequest(10000, 24), expectAsync1((data) {
expect("150391.64490861617",equals( data._emi),reason: "Emi calculation invalid");
}), (error) {
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment