From afaa93fb41b66119b73a1c0c78a5db7943c98040 Mon Sep 17 00:00:00 2001 From: hmalik144 Date: Mon, 13 Feb 2023 18:09:51 +0000 Subject: [PATCH] - Replaced API - Updated available currencies - Updated unit tests - Fix for failure handling - Android release signing --- android/app/build.gradle | 23 +++- android/app/src/main/AndroidManifest.xml | 84 ++++++++----- .../h_mal/easycc/AppWidgetProvider.kt | 58 ++++----- android/app/src/main/res/values/strings.xml | 119 +----------------- .../main/res/xml/currency_app_widget_info.xml | 6 +- lib/Utils/constants.dart | 119 +----------------- lib/data/network/safe_api_call.dart | 4 +- lib/locator.dart | 1 + lib/main.dart | 2 + lib/main_view_model.dart | 4 +- pubspec.lock | 8 +- pubspec.yaml | 2 +- test/unit_test/repository_test.dart | 10 +- test/unit_test/viewmodel_test.dart | 4 +- 14 files changed, 122 insertions(+), 322 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 662ef74..cee600c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -21,6 +21,11 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } +def relStorePassword = System.getenv("storePassword") +def relKeyPassword = System.getenv("keyPassword") +def relKeyAlias = System.getenv("keyAlias") +def relStoreFile = System.getenv("storeFile") + apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" @@ -43,7 +48,6 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.appttude.h_mal.easycc" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. @@ -53,11 +57,22 @@ android { versionName flutterVersionName } + signingConfigs { + release { + storePassword relStorePassword + keyPassword relKeyPassword + keyAlias relKeyAlias + storeFile file(relStoreFile) + } + } + buildTypes { release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug + signingConfig signingConfigs.release + minifyEnabled true + shrinkResources true + useProguard true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 581ca1d..24ec3e3 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,57 +1,73 @@ - + + + android:icon="@mipmap/launcher_icon" + android:label="easycc"> + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" /> - - + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + - + + - - - - - - - - - - - - - - + diff --git a/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt index 20f59c8..2e063e4 100644 --- a/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt +++ b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt @@ -1,20 +1,17 @@ package com.appttude.h_mal.easycc import android.appwidget.AppWidgetManager -import android.content.ComponentName import android.content.Context -import android.content.Intent import android.content.SharedPreferences import android.net.Uri import android.widget.RemoteViews import android.widget.Toast import es.antonborri.home_widget.HomeWidgetBackgroundIntent import es.antonborri.home_widget.HomeWidgetLaunchIntent -import es.antonborri.home_widget.HomeWidgetPlugin import es.antonborri.home_widget.HomeWidgetProvider -class AppWidgetProvider : HomeWidgetProvider(){ +class AppWidgetProvider : HomeWidgetProvider() { override fun onUpdate( context: Context, appWidgetManager: AppWidgetManager, @@ -23,54 +20,46 @@ class AppWidgetProvider : HomeWidgetProvider(){ ) { appWidgetIds.forEach { widgetId -> val views = RemoteViews(context.packageName, R.layout.currency_app_widget).apply { - // Data from background operation received + val uri = createUpdateUri(widgetId) + val backgroundIntent = HomeWidgetBackgroundIntent.getBroadcast(context, uri) + // checks if forced update or period update + val forcedUpdate: Boolean = + widgetData.getBoolean("${widgetId}_forced_update", false) + + if (!forcedUpdate) { + widgetData.edit().putBoolean("${widgetId}_forced_update", true).apply() + backgroundIntent.send() + return@apply + } + val from: String? = widgetData.getString("${widgetId}_from", null) val to: String? = widgetData.getString("${widgetId}_to", null) val rate: String? = widgetData.getString("${widgetId}_rate", null) if (from.isNullOrBlank() or to.isNullOrBlank() or rate.isNullOrBlank()) { - Toast.makeText(context, "Unable to review data for widget", Toast.LENGTH_SHORT).show() + Toast.makeText(context, "Unable to review data for widget", Toast.LENGTH_SHORT) + .show() return@apply } val titleString = "${from}${to}" setTextViewText(R.id.exchangeName, titleString) setTextViewText(R.id.exchangeRate, rate.toString()) - - val uri = Uri.parse("myAppWidget://updatewidget").buildUpon() - .appendQueryParameter("id", widgetId.toString()) - .build() - setImageViewResource(R.id.refresh_icon, R.drawable.ic_refresh_white_24dp) - val backgroundIntent = HomeWidgetBackgroundIntent.getBroadcast(context, uri) setOnClickPendingIntent(R.id.refresh_icon, backgroundIntent) - val pendingIntent = HomeWidgetLaunchIntent.getActivity(context, - MainActivity::class.java) + val pendingIntent = HomeWidgetLaunchIntent.getActivity( + context, + MainActivity::class.java + ) + widgetData.edit().putBoolean("${widgetId}_forced_update", false).apply() setOnClickPendingIntent(R.id.widget_view, pendingIntent) } appWidgetManager.updateAppWidget(widgetId, views) } } - override fun onReceive(context: Context?, intent: Intent?) { - super.onReceive(context, intent) - - when (intent?.action) { - - } - val appWidgetManager = AppWidgetManager.getInstance(context); - val appWidgetIds = appWidgetManager.getAppWidgetIds( - context?.let { ComponentName(it, this::class.java) }) - val widgetDate = context?.let { HomeWidgetPlugin.getData(it) } - - appWidgetIds.forEach { widgetId -> - - - } - } - override fun onDeleted(context: Context?, appWidgetIds: IntArray?) { super.onDeleted(context, appWidgetIds) @@ -85,4 +74,11 @@ class AppWidgetProvider : HomeWidgetProvider(){ } } } + + // Send update broadcast to widget app class + private fun createUpdateUri(widgetId: Int): Uri? { + return Uri.parse("myAppWidget://updatewidget").buildUpon() + .appendQueryParameter("id", widgetId.toString()) + .build() + } } \ No newline at end of file diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 4d866f8..2ae28e7 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -2,160 +2,43 @@ - ALL - Albanian Lek - AFN - Afghan Afghani DZD - Algerian Dinar - AOA - Angolan Kwanza ARS - Argentine Peso - AMD - Armenian Dram - AWG - Aruban Florin AUD - Australian Dollar - AZN - Azerbaijani Manat - BSD - Bahamian Dollar - BHD - Bahraini Dinar - BDT - Bangladeshi Taka - BBD - Barbadian Dollar - BYR - Belarusian Ruble - BZD - Belize Dollar - BTN - Bhutanese Ngultrum BTC - Bitcoin - BOB - Bolivian Boliviano - BAM - Bosnia And Herzegovina Konvertibilna Marka - BWP - Botswana Pula BRL - Brazilian Real GBP - British Pound - BND - Brunei Dollar BGN - Bulgarian Lev - BIF - Burundi Franc - KHR - Cambodian Riel CAD - Canadian Dollar - CVE - Cape Verdean Escudo - KYD - Cayman Islands Dollar - XAF - Central African CFA Franc - XPF - CFP Franc - CLP - Chilean Peso CNY - Chinese Yuan - COP - Colombian Peso - KMF - Comorian Franc - CDF - Congolese Franc - CRC - Costa Rican Colon HRK - Croatian Kuna - CUP - Cuban Peso CZK - Czech Koruna DKK - Danish Krone - DJF - Djiboutian Franc - DOP - Dominican Peso - XCD - East Caribbean Dollar - EGP - Egyptian Pound - ERN - Eritrean Nakfa - ETB - Ethiopian Birr EUR - Euro - FKP - Falkland Islands Pound - FJD - Fijian Dollar - GMD - Gambian Dalasi - GEL - Georgian Lari - GHS - Ghanaian Cedi - GIP - Gibraltar Pound - GTQ - Guatemalan Quetzal - GNF - Guinean Franc - GYD - Guyanese Dollar - HTG - Haitian Gourde - HNL - Honduran Lempira HKD - Hong Kong Dollar HUF - Hungarian Forint ISK - Icelandic Kr\u00f3na INR - Indian Rupee IDR - Indonesian Rupiah - IRR - Iranian Rial - IQD - Iraqi Dinar ILS - Israeli New Sheqel - JMD - Jamaican Dollar JPY - Japanese Yen - JOD - Jordanian Dinar - KZT - Kazakhstani Tenge - KES - Kenyan Shilling - KWD - Kuwaiti Dinar - KGS - Kyrgyzstani Som - LAK - Lao Kip - LVL - Latvian Lats - LBP - Lebanese Lira - LSL - Lesotho Loti - LRD - Liberian Dollar - LYD - Libyan Dinar - MOP - Macanese Pataca - MKD - Macedonian Denar - MGA - Malagasy Ariary - MWK - Malawian Kwacha MYR - Malaysian Ringgit - MVR - Maldivian Rufiyaa - MRO - Mauritanian Ouguiya - MUR - Mauritian Rupee MXN - Mexican Peso - MDL - Moldovan Leu - MNT - Mongolian Tugrik MAD - Moroccan Dirham - MZN - Mozambican Metical - MMK - Myanma Kyat - NAD - Namibian Dollar - NPR - Nepalese Rupee - ANG - Netherlands Antillean Gulden TWD - New Taiwan Dollar NZD - New Zealand Dollar - NIO - Nicaraguan Cordoba - NGN - Nigerian Naira - KPW - North Korean Won NOK - Norwegian Krone - OMR - Omani Rial - TOP - Paanga - PKR - Pakistani Rupee - PAB - Panamanian Balboa - PGK - Papua New Guinean Kina - PYG - Paraguayan Guarani - PEN - Peruvian Nuevo Sol PHP - Philippine Peso PLN - Polish Zloty - QAR - Qatari Riyal RON - Romanian Leu RUB - Russian Ruble - RWF - Rwandan Franc - SHP - Saint Helena Pound - WST - Samoan Tala - STD - Sao Tome And Principe Dobra - SAR - Saudi Riyal - RSD - Serbian Dinar - SCR - Seychellois Rupee - SLL - Sierra Leonean Leone SGD - Singapore Dollar - SBD - Solomon Islands Dollar - SOS - Somali Shilling ZAR - South African Rand KRW - South Korean Won - XDR - Special Drawing Rights - LKR - Sri Lankan Rupee - SDG - Sudanese Pound - SRD - Surinamese Dollar - SZL - Swazi Lilangeni SEK - Swedish Krona CHF - Swiss Franc - SYP - Syrian Pound - TJS - Tajikistani Somoni - TZS - Tanzanian Shilling THB - Thai Baht - TTD - Trinidad and Tobago Dollar - TND - Tunisian Dinar TRY - Turkish New Lira - TMT - Turkmenistan Manat - AED - UAE Dirham - UGX - Ugandan Shilling - UAH - Ukrainian Hryvnia - USD - United States Dollar - UYU - Uruguayan Peso - UZS - Uzbekistani Som - VUV - Vanuatu Vatu - VEF - Venezuelan Bolivar - VND - Vietnamese Dong - XOF - West African CFA Franc - YER - Yemeni Rial - ZMW - Zambian Kwacha + USD - US Dollar \ No newline at end of file diff --git a/android/app/src/main/res/xml/currency_app_widget_info.xml b/android/app/src/main/res/xml/currency_app_widget_info.xml index 1e0409c..af77191 100644 --- a/android/app/src/main/res/xml/currency_app_widget_info.xml +++ b/android/app/src/main/res/xml/currency_app_widget_info.xml @@ -1,5 +1,6 @@ \ No newline at end of file + android:updatePeriodMillis="14400000" + android:widgetCategory="home_screen|keyguard" + tools:targetApi="jelly_bean_mr1" /> \ No newline at end of file diff --git a/lib/Utils/constants.dart b/lib/Utils/constants.dart index 4b54b68..c09ba0a 100644 --- a/lib/Utils/constants.dart +++ b/lib/Utils/constants.dart @@ -9,159 +9,42 @@ const Color colourFive = Color(0xFFC6E0FF); const double paddingGlobal = 12; final List listOfCurrencies = [ - 'ALL - Albanian Lek', - 'AFN - Afghan Afghani', 'DZD - Algerian Dinar', - 'AOA - Angolan Kwanza', 'ARS - Argentine Peso', - 'AMD - Armenian Dram', - 'AWG - Aruban Florin', 'AUD - Australian Dollar', - 'AZN - Azerbaijani Manat', - 'BSD - Bahamian Dollar', - 'BHD - Bahraini Dinar', - 'BDT - Bangladeshi Taka', - 'BBD - Barbadian Dollar', - 'BYR - Belarusian Ruble', - 'BZD - Belize Dollar', - 'BTN - Bhutanese Ngultrum', 'BTC - Bitcoin', - 'BOB - Bolivian Boliviano', - 'BAM - Bosnia And Herzegovina Konvertibilna Marka', - 'BWP - Botswana Pula', 'BRL - Brazilian Real', 'GBP - British Pound', - 'BND - Brunei Dollar', 'BGN - Bulgarian Lev', - 'BIF - Burundi Franc', - 'KHR - Cambodian Riel', 'CAD - Canadian Dollar', - 'CVE - Cape Verdean Escudo', - 'KYD - Cayman Islands Dollar', - 'XAF - Central African CFA Franc', - 'XPF - CFP Franc', - 'CLP - Chilean Peso', 'CNY - Chinese Yuan', - 'COP - Colombian Peso', - 'KMF - Comorian Franc', - 'CDF - Congolese Franc', - 'CRC - Costa Rican Colon', 'HRK - Croatian Kuna', - 'CUP - Cuban Peso', 'CZK - Czech Koruna', 'DKK - Danish Krone', - 'DJF - Djiboutian Franc', - 'DOP - Dominican Peso', - 'XCD - East Caribbean Dollar', - 'EGP - Egyptian Pound', - 'ERN - Eritrean Nakfa', - 'ETB - Ethiopian Birr', 'EUR - Euro', - 'FKP - Falkland Islands Pound', - 'FJD - Fijian Dollar', - 'GMD - Gambian Dalasi', - 'GEL - Georgian Lari', - 'GHS - Ghanaian Cedi', - 'GIP - Gibraltar Pound', - 'GTQ - Guatemalan Quetzal', - 'GNF - Guinean Franc', - 'GYD - Guyanese Dollar', - 'HTG - Haitian Gourde', - 'HNL - Honduran Lempira', 'HKD - Hong Kong Dollar', 'HUF - Hungarian Forint', 'ISK - Icelandic Kr\u00f3na', 'INR - Indian Rupee', 'IDR - Indonesian Rupiah', - 'IRR - Iranian Rial', - 'IQD - Iraqi Dinar', 'ILS - Israeli New Sheqel', - 'JMD - Jamaican Dollar', 'JPY - Japanese Yen', - 'JOD - Jordanian Dinar', - 'KZT - Kazakhstani Tenge', - 'KES - Kenyan Shilling', - 'KWD - Kuwaiti Dinar', - 'KGS - Kyrgyzstani Som', - 'LAK - Lao Kip', - 'LVL - Latvian Lats', - 'LBP - Lebanese Lira', - 'LSL - Lesotho Loti', - 'LRD - Liberian Dollar', - 'LYD - Libyan Dinar', - 'MOP - Macanese Pataca', - 'MKD - Macedonian Denar', - 'MGA - Malagasy Ariary', - 'MWK - Malawian Kwacha', 'MYR - Malaysian Ringgit', - 'MVR - Maldivian Rufiyaa', - 'MRO - Mauritanian Ouguiya', - 'MUR - Mauritian Rupee', 'MXN - Mexican Peso', - 'MDL - Moldovan Leu', - 'MNT - Mongolian Tugrik', 'MAD - Moroccan Dirham', - 'MZN - Mozambican Metical', - 'MMK - Myanma Kyat', - 'NAD - Namibian Dollar', - 'NPR - Nepalese Rupee', - 'ANG - Netherlands Antillean Gulden', 'TWD - New Taiwan Dollar', 'NZD - New Zealand Dollar', - 'NIO - Nicaraguan Cordoba', - 'NGN - Nigerian Naira', - 'KPW - North Korean Won', 'NOK - Norwegian Krone', - 'OMR - Omani Rial', - 'TOP - Paanga', - 'PKR - Pakistani Rupee', - 'PAB - Panamanian Balboa', - 'PGK - Papua New Guinean Kina', - 'PYG - Paraguayan Guarani', - 'PEN - Peruvian Nuevo Sol', 'PHP - Philippine Peso', 'PLN - Polish Zloty', - 'QAR - Qatari Riyal', 'RON - Romanian Leu', 'RUB - Russian Ruble', - 'RWF - Rwandan Franc', - 'SHP - Saint Helena Pound', - 'WST - Samoan Tala', - 'STD - Sao Tome And Principe Dobra', - 'SAR - Saudi Riyal', - 'RSD - Serbian Dinar', - 'SCR - Seychellois Rupee', - 'SLL - Sierra Leonean Leone', 'SGD - Singapore Dollar', - 'SBD - Solomon Islands Dollar', - 'SOS - Somali Shilling', 'ZAR - South African Rand', 'KRW - South Korean Won', - 'XDR - Special Drawing Rights', - 'LKR - Sri Lankan Rupee', - 'SDG - Sudanese Pound', - 'SRD - Surinamese Dollar', - 'SZL - Swazi Lilangeni', 'SEK - Swedish Krona', 'CHF - Swiss Franc', - 'SYP - Syrian Pound', - 'TJS - Tajikistani Somoni', - 'TZS - Tanzanian Shilling', 'THB - Thai Baht', - 'TTD - Trinidad and Tobago Dollar', - 'TND - Tunisian Dinar', 'TRY - Turkish New Lira', - 'TMT - Turkmenistan Manat', - 'AED - UAE Dirham', - 'UGX - Ugandan Shilling', - 'UAH - Ukrainian Hryvnia', - 'USD - United States Dollar', - 'UYU - Uruguayan Peso', - 'UZS - Uzbekistani Som', - 'VUV - Vanuatu Vatu', - 'VEF - Venezuelan Bolivar', - 'VND - Vietnamese Dong', - 'XOF - West African CFA Franc', - 'YER - Yemeni Rial', - 'ZMW - Zambian Kwacha' + 'USD - US Dollar' ]; \ No newline at end of file diff --git a/lib/data/network/safe_api_call.dart b/lib/data/network/safe_api_call.dart index d008140..38b9f46 100644 --- a/lib/data/network/safe_api_call.dart +++ b/lib/data/network/safe_api_call.dart @@ -17,8 +17,8 @@ mixin SafeApiCall { if (errorResponse?["message"] != null){ error = errorResponse!["message"]; - } else if (dioError.error != null){ - error = dioError.error; + } else if (dioError.message.isNotEmpty){ + error = dioError.message; } else { error = "Failed to retrieve data from api"; } diff --git a/lib/locator.dart b/lib/locator.dart index 8ba82fb..b0e1cbc 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -3,6 +3,7 @@ import 'package:easy_cc_flutter/data/network/currency_api.dart'; import 'package:easy_cc_flutter/data/repository/repository_impl.dart'; import 'package:easy_cc_flutter/main_view_model.dart'; import 'package:get_it/get_it.dart'; + import 'data/prefs/preference_provider.dart'; import 'data/repository/repository.dart'; diff --git a/lib/main.dart b/lib/main.dart index c4a6e3d..c412aa0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -62,6 +62,7 @@ Future updateWidget(String? widgetId, Repository repository) async { await HomeWidget.saveWidgetData("${widgetId}_from", from); await HomeWidget.saveWidgetData("${widgetId}_to", to); await HomeWidget.saveWidgetData("${widgetId}_rate", currency.rate.toString()); + await HomeWidget.saveWidgetData("${widgetId}_forced_update", true); await HomeWidget.updateWidget(name: 'AppWidgetProvider', iOSName: 'AppWidgetProvider'); } @@ -74,6 +75,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', + debugShowCheckedModeBanner: false, theme: ThemeData( // This is the theme of your application. // diff --git a/lib/main_view_model.dart b/lib/main_view_model.dart index 98e522f..6ab030c 100644 --- a/lib/main_view_model.dart +++ b/lib/main_view_model.dart @@ -40,8 +40,8 @@ class MainViewModel extends BaseViewmodel { (value) { conversionRate = value.rate != null ? value.rate! : 0.00; onSuccess(value); - }, onError: (exception, _) { - onError(exception.message); + }).catchError((e) { + onError(e.message); }); } diff --git a/pubspec.lock b/pubspec.lock index 53f0927..83f4454 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -379,7 +379,7 @@ packages: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.5" + version: "0.2.0" meta: dependency: transitive description: @@ -622,7 +622,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" + version: "1.9.1" stack_trace: dependency: transitive description: @@ -685,7 +685,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.12" + version: "0.4.13" timing: dependency: transitive description: @@ -734,7 +734,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.3" watcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5fa8453..2e911a3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 6.1.1+8 environment: sdk: '>=2.18.0-190.0.dev <3.0.0' diff --git a/test/unit_test/repository_test.dart b/test/unit_test/repository_test.dart index 2c8be75..935b2d0 100644 --- a/test/unit_test/repository_test.dart +++ b/test/unit_test/repository_test.dart @@ -25,6 +25,7 @@ import 'repository_test.mocks.dart'; onMissingStub: OnMissingStub.returnDefault), MockSpec>( as: #MockCurrencyResponse, onMissingStub: OnMissingStub.returnDefault), + MockSpec(onMissingStub: OnMissingStub.returnDefault), MockSpec(onMissingStub: OnMissingStub.returnDefault) ]) void main() { @@ -85,7 +86,7 @@ void main() { // When when(currencyApi.getConversion("AUD", "GBP")) - .thenAnswer((_) async => Future.error(MockDioError())); + .thenAnswer((_) async => Future.error(MockHttpException())); when(mockResponse.data).thenReturn(currencyResponse); when(backupCurrencyApi.getCurrencyRate("AUD", "GBP")) .thenAnswer((_) async => mockResponse); @@ -98,17 +99,18 @@ void main() { test('unable to retrieve rate from both APIs', () async { // Given - DioError backUpError = MockDioError(); + MockDioError backUpError = MockDioError(); // When - when(backUpError.error).thenReturn("Error message"); + when(backUpError.message).thenReturn("Error message"); when(currencyApi.getConversion("AUD", "GBP")) .thenAnswer((_) async => Future.error(MockDioError())); when(backupCurrencyApi.getCurrencyRate("AUD", "GBP")) .thenAnswer((_) async => Future.error(backUpError)); // Then - expect(() async => + expect( + () async => await sut.getConversationRateFromApi(fromCurrency, toCurrency), throwsA(predicate( (e) => e is HttpException && e.message == 'Error message'))); diff --git a/test/unit_test/viewmodel_test.dart b/test/unit_test/viewmodel_test.dart index 9e11ef7..2f47dc4 100644 --- a/test/unit_test/viewmodel_test.dart +++ b/test/unit_test/viewmodel_test.dart @@ -55,8 +55,8 @@ void main() { // Then String fromSelection = mainViewModel.getConversionPair(SelectionType.conversionFrom); String toSelection = mainViewModel.getConversionPair(SelectionType.conversionTo); - expect(fromSelection, "ALL - Albanian Lek"); - expect(toSelection, "ALL - Albanian Lek"); + expect(fromSelection, "DZD - Algerian Dinar"); + expect(toSelection, "DZD - Algerian Dinar"); }); test('set the currency rate from API', () async{