updated unit tests

This commit is contained in:
2023-02-08 12:39:50 +00:00
parent ec1e3a704e
commit b40635c34a

View File

@@ -64,11 +64,10 @@ void main() {
ResponseObject responseObject = ResponseObject.fromJson( ResponseObject responseObject = ResponseObject.fromJson(
await readJson("test/resources/success_call_api")); await readJson("test/resources/success_call_api"));
Currency currencyObject = Currency("AUD", "GBP", 0.601188); Currency currencyObject = Currency("AUD", "GBP", 0.601188);
String currency = "AUD_GBP";
// When // When
when(mockResponse.data).thenReturn(responseObject); when(mockResponse.data).thenReturn(responseObject);
when(currencyApi.getConversion(currency)) when(currencyApi.getConversion("AUD", "GBP"))
.thenAnswer((_) async => mockResponse); .thenAnswer((_) async => mockResponse);
// Then // Then
@@ -83,10 +82,9 @@ void main() {
CurrencyResponse currencyResponse = CurrencyResponse.fromJson( CurrencyResponse currencyResponse = CurrencyResponse.fromJson(
await readJson("test/resources/success_call_backup_api")); await readJson("test/resources/success_call_backup_api"));
Currency currencyObject = Currency("AUD", "GBP", 0.601188); Currency currencyObject = Currency("AUD", "GBP", 0.601188);
String currency = "AUD_GBP";
// When // When
when(currencyApi.getConversion(currency)) when(currencyApi.getConversion("AUD", "GBP"))
.thenAnswer((_) async => Future.error(MockDioError())); .thenAnswer((_) async => Future.error(MockDioError()));
when(mockResponse.data).thenReturn(currencyResponse); when(mockResponse.data).thenReturn(currencyResponse);
when(backupCurrencyApi.getCurrencyRate("AUD", "GBP")) when(backupCurrencyApi.getCurrencyRate("AUD", "GBP"))
@@ -100,12 +98,11 @@ void main() {
test('unable to retrieve rate from both APIs', () async { test('unable to retrieve rate from both APIs', () async {
// Given // Given
String currency = "AUD_GBP";
DioError backUpError = MockDioError(); DioError backUpError = MockDioError();
// When // When
when(backUpError.error).thenReturn("Error message"); when(backUpError.error).thenReturn("Error message");
when(currencyApi.getConversion(currency)) when(currencyApi.getConversion("AUD", "GBP"))
.thenAnswer((_) async => Future.error(MockDioError())); .thenAnswer((_) async => Future.error(MockDioError()));
when(backupCurrencyApi.getCurrencyRate("AUD", "GBP")) when(backupCurrencyApi.getCurrencyRate("AUD", "GBP"))
.thenAnswer((_) async => Future.error(backUpError)); .thenAnswer((_) async => Future.error(backUpError));