Skip to content

Commit

Permalink
fix: Lowercased country code (#343)
Browse files Browse the repository at this point in the history
Impacted files:
* `api_saveProduct_test.dart`: unrelated - raised time out for "save" tests
* `CountryHelper.dart`: lowercased the country code for conversions
  • Loading branch information
monsieurtanuki committed Dec 28, 2021
1 parent 87ad993 commit bdf6451
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
5 changes: 4 additions & 1 deletion lib/utils/CountryHelper.dart
Expand Up @@ -1007,11 +1007,14 @@ extension OpenFoodFactsCoutryExtension on OpenFoodFactsCountry {

/// Helper class around [OpenFoodFactsCountry]
class CountryHelper {
/// Converts an ISO 2 code into an [OpenFoodFactsCountry]
/// Converts an ISO 2 code into an [OpenFoodFactsCountry] (case-insensitive).
///
/// E.g. 'fr' and 'FR' will give the same result: OpenFoodFactsCountry.FRANCE.
static OpenFoodFactsCountry? fromJson(String? code) {
if (code == null) {
return null;
}
code = code.toLowerCase();
for (final OpenFoodFactsCountry key in OpenFoodFactsCountry.values) {
if (key.iso2Code == code) {
return key;
Expand Down
24 changes: 8 additions & 16 deletions test/api_saveProduct_test.dart
Expand Up @@ -85,11 +85,7 @@ void main() {
);

testProductResult1(result2);
},
timeout: Timeout(
// this guy is rather slow
Duration(seconds: 90),
));
});

/// Returns a timestamp up to the minute level.
String _getMinuteTimestamp() =>
Expand Down Expand Up @@ -189,11 +185,7 @@ void main() {

expect(frenchGermanResult.product, isNotNull);
expect(frenchGermanResult.product!.productName, frenchProductName);
},
timeout: Timeout(
// this guy is rather slow
Duration(seconds: 90),
));
});

test('add new product test 2', () async {
Product product = Product(
Expand Down Expand Up @@ -229,11 +221,7 @@ void main() {

expect(status.status, 1);
expect(status.statusVerbose, 'fields saved');
},
timeout: Timeout(
// this guy is rather slow
Duration(seconds: 90),
));
});

test('add new product test 4', () async {
Product product = Product(
Expand Down Expand Up @@ -434,5 +422,9 @@ void main() {
);
expect(status.isWrongUsernameOrPassword(), isTrue);
});
});
},
timeout: Timeout(
// some tests can be slow here
Duration(seconds: 90),
));
}

0 comments on commit bdf6451

Please sign in to comment.