-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 691 - implemented "imagesToJson" (#693)
* fix: 691 - implemented "imagesToJson" New file: * `api_json_to_from_test.dart`: unit tests about to/from json conversions Impacted files: * `api_search_products_test.dart`: unrelated fix * `json_helper.dart`: implemented method `imagesToJson`; refactored method `imagesFromJson` * `product_images.dart`: added fields width and height; added `hashcode` and `==` operator * fix: 691 - unrelated fix of 692 Impacted file: * `product.dart`: removed deprecated json annotation.
- Loading branch information
1 parent
2d3f76f
commit 316b19d
Showing
5 changed files
with
239 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
const BARCODE_DANISH_BUTTER_COOKIES = '5701184005007'; | ||
|
||
OpenFoodAPIConfiguration.globalQueryType = QueryType.PROD; | ||
|
||
group('$OpenFoodAPIClient json to/from conversions', () { | ||
test('images', () async { | ||
final ProductResultV3 productResult = | ||
await OpenFoodAPIClient.getProductV3( | ||
ProductQueryConfiguration( | ||
BARCODE_DANISH_BUTTER_COOKIES, | ||
fields: [ProductField.IMAGES], | ||
version: ProductQueryVersion.v3, | ||
), | ||
); | ||
expect(productResult.product, isNotNull); | ||
|
||
final List<ProductImage>? images = productResult.product!.images; | ||
expect(images, isNotNull); | ||
expect(images, isNotEmpty); | ||
|
||
final List<ProductImage>? imagesBackAndForth = JsonHelper.imagesFromJson( | ||
JsonHelper.imagesToJson(images), | ||
); | ||
expect(imagesBackAndForth, isNotNull); | ||
expect(imagesBackAndForth, isNotEmpty); | ||
|
||
expect(imagesBackAndForth!.length, images!.length); | ||
for (final ProductImage productImage1 in images) { | ||
int count = 0; | ||
for (final ProductImage productImage2 in imagesBackAndForth) { | ||
if (productImage1 == productImage2) { | ||
count++; | ||
} | ||
} | ||
expect(count, 1); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters