Skip to content

Commit

Permalink
feat: #602 - added the "website" product field (#603)
Browse files Browse the repository at this point in the history
Impacted files:
* `api_getProduct_test.dart`: added a test on the new "website" product field
* `Product.dart`: added the "website" field
* `Product.g.dart`: generated
* `ProductFields.dart`: added the "website" field
  • Loading branch information
monsieurtanuki authored Oct 25, 2022
1 parent 313fd28 commit e9fe00a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions lib/model/Product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ class Product extends JsonObject {
@JsonKey(name: 'nova_group', includeIfNull: false)
int? novaGroup;

/// Link to the product page on the official site of the producer
@JsonKey(name: 'link', includeIfNull: false)
String? website;

Product(
{this.barcode,
this.productName,
Expand Down
4 changes: 3 additions & 1 deletion lib/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/utils/ProductFields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ enum ProductField implements OffTagged {
MANUFACTURING_PLACES(offTag: 'manufacturing_places'),
ORIGINS(offTag: 'origins'),
NOVA_GROUP(offTag: 'nova_group'),
WEBSITE(offTag: 'link'),
ALL(offTag: '');

const ProductField({
Expand Down
27 changes: 20 additions & 7 deletions test/api_getProduct_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1832,20 +1832,33 @@ void main() {
));

test('get new product fields', () async {
final ProductQueryConfiguration configuration = ProductQueryConfiguration(
late ProductQueryConfiguration configuration;
late ProductResult result;

configuration = ProductQueryConfiguration(
BARCODE_DANISH_BUTTER_COOKIES,
fields: [
ProductField.COMPARED_TO_CATEGORY,
],
fields: [ProductField.COMPARED_TO_CATEGORY],
);

final ProductResult result = await OpenFoodAPIClient.getProduct(
result = await OpenFoodAPIClient.getProduct(
configuration,
queryType: QueryType.PROD,
);

expect(result.status, 1);
expect(result.product, isNotNull);
expect(result.product!.comparedToCategory, isNotNull);

configuration = ProductQueryConfiguration(
'7300400481588',
fields: [ProductField.WEBSITE],
);
result = await OpenFoodAPIClient.getProduct(
configuration,
queryType: QueryType.PROD,
);
expect(result.status, 1);
expect(result.product, isNotNull);
expect(result.product!.website, isNotNull);
expect(result.product!.website, isNotEmpty);
});

group('no nutrition data', () {
Expand Down

0 comments on commit e9fe00a

Please sign in to comment.