Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Lowercased country code #343

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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),
));
}