Skip to content

Commit

Permalink
feat: 878 - added the "obsolete" product field (#879)
Browse files Browse the repository at this point in the history
Impacted files:
* `api_get_product_test.dart`: tested the new product "obsolete" field on an obsolete and a non-obsolete product
* `product.dart`: added the "obsolete" field
* `product.g.dart`: wtf
* `product_fields.dart`: added the "OBSOLETE" product field
  • Loading branch information
monsieurtanuki authored Feb 6, 2024
1 parent 2167bf9 commit 4cc49cd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/src/model/product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,13 @@ class Product extends JsonObject {
@JsonKey(name: 'link', includeIfNull: false)
String? website;

/// Is the product obsolete?
@JsonKey(
toJson: JsonHelper.checkboxToJSON,
fromJson: JsonHelper.checkboxFromJSON,
)
bool? obsolete;

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'),
OBSOLETE(offTag: 'obsolete'),

/// All data as RAW from the server. E.g. packagings are only Strings there.
RAW(offTag: 'raw'),
Expand Down
26 changes: 26 additions & 0 deletions test/api_get_product_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,32 @@ void main() {
expect(result.product!.website, isNotNull);
expect(result.product!.website, isNotEmpty);

configuration = ProductQueryConfiguration(
'8076809517881',
fields: [ProductField.OBSOLETE],
version: ProductQueryVersion.v3,
);
result = await OpenFoodAPIClient.getProductV3(
configuration,
);
expect(result.status, ProductResultV3.statusSuccess);
expect(result.product, isNotNull);
expect(result.product!.obsolete, isNotNull);
expect(result.product!.obsolete, isTrue);

configuration = ProductQueryConfiguration(
'7300400481588',
fields: [ProductField.OBSOLETE],
version: ProductQueryVersion.v3,
);
result = await OpenFoodAPIClient.getProductV3(
configuration,
);
expect(result.status, ProductResultV3.statusSuccess);
expect(result.product, isNotNull);
expect(result.product!.obsolete, isNotNull);
expect(result.product!.obsolete, isFalse);

configuration = ProductQueryConfiguration(
'3033710065066',
fields: [
Expand Down

0 comments on commit 4cc49cd

Please sign in to comment.