Skip to content

Commit

Permalink
feat: 895 - added product field 'expiration_date' (#898)
Browse files Browse the repository at this point in the history
Impacted files:
* `api_get_product_test.dart`: added test for new product field about `'expiration_date'`
* `product.dart`: added product field for `'expiration_date'`
* `product.g.dart`: generated
* `product_fields.dart`: added product field for `'expiration_date'`
  • Loading branch information
monsieurtanuki authored Apr 1, 2024
1 parent 88dada6 commit 7ec0a7e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/src/model/product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ class Product extends JsonObject {
)
bool? obsolete;

/// Expiration date / best before. Just a string, no format control.
@JsonKey(name: 'expiration_date', includeIfNull: false)
String? expirationDate;

Product(
{this.barcode,
this.productName,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/model/product.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/utils/product_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enum ProductField implements OffTagged {
ORIGINS(offTag: 'origins'),
NOVA_GROUP(offTag: 'nova_group'),
WEBSITE(offTag: 'link'),
EXPIRATION_DATE(offTag: 'expiration_date'),
OBSOLETE(offTag: 'obsolete'),

/// All data as RAW from the server. E.g. packagings are only Strings there.
Expand Down
7 changes: 6 additions & 1 deletion test/api_get_product_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,10 @@ void main() {

configuration = ProductQueryConfiguration(
'7300400481588',
fields: [ProductField.WEBSITE],
fields: [
ProductField.WEBSITE,
ProductField.EXPIRATION_DATE,
],
version: ProductQueryVersion.v3,
);
result = await OpenFoodAPIClient.getProductV3(
Expand All @@ -1038,6 +1041,8 @@ void main() {
expect(result.product, isNotNull);
expect(result.product!.website, isNotNull);
expect(result.product!.website, isNotEmpty);
expect(result.product!.expirationDate, isNotNull);
expect(result.product!.expirationDate, isNotEmpty);

configuration = ProductQueryConfiguration(
'8076809517881',
Expand Down

0 comments on commit 7ec0a7e

Please sign in to comment.