diff --git a/test/api_get_product_test.dart b/test/api_get_product_test.dart index 3b2aa4ecae..267c3ab319 100644 --- a/test/api_get_product_test.dart +++ b/test/api_get_product_test.dart @@ -1148,16 +1148,13 @@ void main() { expect(result.product!.entryDates, hasLength(3)); }); - test('get new packagings field', () async { + group('$OpenFoodAPIClient get new packagings field', () { const String barcode = '3661344723290'; const String searchTerms = 'skyr les 2 vaches'; const OpenFoodFactsLanguage language = OpenFoodFactsLanguage.FRENCH; const OpenFoodFactsCountry country = OpenFoodFactsCountry.FRANCE; const ProductQueryVersion version = ProductQueryVersion.v3; - late ProductResultV3 productResult; - late SearchResult searchResult; - void checkProduct(final Product product) { void checkLocalizedTag(final LocalizedTag? tag) { expect(tag, isNotNull); @@ -1175,104 +1172,110 @@ void main() { } } - // checking PACKAGINGS as a single field on a barcode search - productResult = await OpenFoodAPIClient.getProductV3( - ProductQueryConfiguration( - barcode, - fields: [ProductField.PACKAGINGS], - language: language, - country: country, - version: version, - ), - ); - expect(productResult.status, ProductResultV3.statusSuccess); - expect(productResult.product, isNotNull); - checkProduct(productResult.product!); + test('as a single field on a barcode search', () async { + final ProductResultV3 productResult = + await OpenFoodAPIClient.getProductV3( + ProductQueryConfiguration( + barcode, + fields: [ProductField.PACKAGINGS], + language: language, + country: country, + version: version, + ), + ); + expect(productResult.status, ProductResultV3.statusSuccess); + expect(productResult.product, isNotNull); + checkProduct(productResult.product!); + }); - // checking PACKAGINGS as a part of ALL fields on a barcode search - productResult = await OpenFoodAPIClient.getProductV3( - ProductQueryConfiguration( - barcode, - fields: [ProductField.ALL], - language: language, - country: country, - version: version, - ), - ); - expect(productResult.status, ProductResultV3.statusSuccess); - expect(productResult.product, isNotNull); - checkProduct(productResult.product!); - - late bool found; - // checking PACKAGINGS as a single field on a search query - searchResult = await OpenFoodAPIClient.searchProducts( - null, - ProductSearchQueryConfiguration( - parametersList: [ - SearchTerms(terms: [searchTerms]) - ], - fields: [ProductField.PACKAGINGS, ProductField.BARCODE], - language: language, - country: country, - version: version, - ), - ); - expect(searchResult.products, isNotNull); - expect(searchResult.products, isNotEmpty); - found = false; - for (final Product product in searchResult.products!) { - if (product.barcode != barcode) { - continue; - } - found = true; - checkProduct(product); - } - expect(found, isTrue); - - // checking PACKAGINGS as a part of ALL fields on a search query - searchResult = await OpenFoodAPIClient.searchProducts( - null, - ProductSearchQueryConfiguration( - parametersList: [ - SearchTerms(terms: [searchTerms]) - ], - fields: [ProductField.ALL], - language: language, - country: country, - version: version, - ), - ); - expect(searchResult.products, isNotNull); - expect(searchResult.products, isNotEmpty); - found = false; - for (final Product product in searchResult.products!) { - if (product.barcode != barcode) { - continue; + test('as a part of ALL fields on a barcode search', () async { + final ProductResultV3 productResult = + await OpenFoodAPIClient.getProductV3( + ProductQueryConfiguration( + barcode, + fields: [ProductField.ALL], + language: language, + country: country, + version: version, + ), + ); + expect(productResult.status, ProductResultV3.statusSuccess); + expect(productResult.product, isNotNull); + checkProduct(productResult.product!); + }); + + test('as a single field on a search query', () async { + final SearchResult searchResult = await OpenFoodAPIClient.searchProducts( + null, + ProductSearchQueryConfiguration( + parametersList: [ + SearchTerms(terms: [searchTerms]) + ], + fields: [ProductField.PACKAGINGS, ProductField.BARCODE], + language: language, + country: country, + version: version, + ), + ); + expect(searchResult.products, isNotNull); + expect(searchResult.products, isNotEmpty); + bool found = false; + for (final Product product in searchResult.products!) { + if (product.barcode != barcode) { + continue; + } + found = true; + checkProduct(product); } - found = true; - checkProduct(product); - } - expect(found, isTrue); + expect(found, isTrue); + }); - // checking PACKAGINGS as a part of RAW fields on a search query - try { - searchResult = await OpenFoodAPIClient.searchProducts( + test('as a part of ALL fields on a search query', () async { + final SearchResult searchResult = await OpenFoodAPIClient.searchProducts( null, ProductSearchQueryConfiguration( parametersList: [ SearchTerms(terms: [searchTerms]) ], - fields: [ProductField.RAW], + fields: [ProductField.ALL], language: language, country: country, version: version, ), ); - } catch (e) { - // In RAW mode the packagings are mere String's instead of LocalizedTag's. - // Therefore we expect an Exception. - return; - } - fail('On Raw'); + expect(searchResult.products, isNotNull); + expect(searchResult.products, isNotEmpty); + bool found = false; + for (final Product product in searchResult.products!) { + if (product.barcode != barcode) { + continue; + } + found = true; + checkProduct(product); + } + expect(found, isTrue); + }); + + test('as a part of RAW fields on a search query', () async { + try { + await OpenFoodAPIClient.searchProducts( + null, + ProductSearchQueryConfiguration( + parametersList: [ + SearchTerms(terms: [searchTerms]) + ], + fields: [ProductField.RAW], + language: language, + country: country, + version: version, + ), + ); + } catch (e) { + // In RAW mode the packagings are mere String's instead of LocalizedTag's. + // Therefore we expect an Exception. + return; + } + fail('On Raw'); + }); }); } diff --git a/test/api_matched_product_v2_test.dart b/test/api_matched_product_v2_test.dart index 21d3a4fce1..268184a8de 100644 --- a/test/api_matched_product_v2_test.dart +++ b/test/api_matched_product_v2_test.dart @@ -54,7 +54,7 @@ void main() { BARCODE_ORIENTALES: _Score(100, MatchedProductStatusV2.VERY_GOOD_MATCH), BARCODE_HACK: _Score(100, MatchedProductStatusV2.VERY_GOOD_MATCH), BARCODE_SCHNITZEL: _Score(100, MatchedProductStatusV2.VERY_GOOD_MATCH), - BARCODE_CHIPOLATA: _Score(0, MatchedProductStatusV2.UNKNOWN_MATCH), + BARCODE_CHIPOLATA: _Score(100, MatchedProductStatusV2.VERY_GOOD_MATCH), BARCODE_FLEISCHWURST: _Score(100, MatchedProductStatusV2.VERY_GOOD_MATCH), BARCODE_POULET: _Score(0, MatchedProductStatusV2.UNKNOWN_MATCH), BARCODE_SAUCISSON: _Score(0, MatchedProductStatusV2.DOES_NOT_MATCH), @@ -63,13 +63,13 @@ void main() { BARCODE_CHORIZO: _Score(0, MatchedProductStatusV2.DOES_NOT_MATCH), }; final List expectedBarcodeOrder = [ + BARCODE_CHIPOLATA, BARCODE_FLEISCHWURST, BARCODE_KNACKI, BARCODE_CORDONBLEU, BARCODE_ORIENTALES, BARCODE_HACK, BARCODE_SCHNITZEL, - BARCODE_CHIPOLATA, BARCODE_POULET, BARCODE_SAUCISSON, BARCODE_PIZZA, diff --git a/test/api_save_product_v3_test.dart b/test/api_save_product_v3_test.dart index 3ccb10bc04..147e743cc6 100644 --- a/test/api_save_product_v3_test.dart +++ b/test/api_save_product_v3_test.dart @@ -71,7 +71,7 @@ void main() { expect(answer.field, isNotNull); expect(answer.field!.id, 'recycling'); expect(answer.field!.value, '${language.offTag}:$unknownRecycling'); - }, skip: 'Avoiding tests on TEST env'); + }); test('save packagings_complete', () async { final List values = [false, true, false]; @@ -117,9 +117,5 @@ void main() { expect(readStatus.product!.packagingsComplete, value); } }); - }, - timeout: Timeout( - // some tests can be slow here - Duration(seconds: 90), - )); + }, skip: 'Avoiding tests on TEST env'); }