Skip to content

Commit

Permalink
feat: new product field comparedToCategory (#474)
Browse files Browse the repository at this point in the history
Impacted files:
* api_getProduct_test.dart: added a test for new fields (only field "comparedToCategory" for the moment)
* Product.dart: added field comparedToCategory
* Product.g.dart: generated
* ProductFields.dart: added field COMPARED_TO_CATEGORY
  • Loading branch information
monsieurtanuki committed Jun 3, 2022
1 parent 5b1d128 commit 1d59448
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/model/Product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ class Product extends JsonObject {
@JsonKey(name: 'nutrition_grade_fr', includeIfNull: false)
String? nutriscore;

@JsonKey(name: 'compared_to_category', includeIfNull: false)
String? comparedToCategory;
@JsonKey(name: 'categories', includeIfNull: false)
String? categories;
@JsonKey(name: 'categories_tags', includeIfNull: false)
Expand Down
2 changes: 2 additions & 0 deletions lib/model/Product.g.dart

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

2 changes: 2 additions & 0 deletions lib/utils/ProductFields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum ProductField {
NUTRIMENT_ENERGY_UNIT,
NUTRIMENT_DATA_PER,
NUTRISCORE,
COMPARED_TO_CATEGORY,
CATEGORIES,
CATEGORIES_TAGS,
CATEGORIES_TAGS_IN_LANGUAGES,
Expand Down Expand Up @@ -117,6 +118,7 @@ extension ProductFieldExtension on ProductField {
ProductField.CATEGORIES: 'categories',
ProductField.CATEGORIES_TAGS: 'categories_tags',
ProductField.CATEGORIES_TAGS_IN_LANGUAGES: 'categories_tags_',
ProductField.COMPARED_TO_CATEGORY: 'compared_to_category',
ProductField.LABELS: 'labels',
ProductField.LABELS_TAGS: 'labels_tags',
ProductField.LABELS_TAGS_IN_LANGUAGES: 'labels_tags_',
Expand Down
17 changes: 17 additions & 0 deletions test/api_getProduct_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,23 @@ void main() {
expect(result.product?.quantity, '5.5 Liter');
});

test('get new product fields', () async {
final ProductQueryConfiguration configuration = ProductQueryConfiguration(
BARCODE_DANISH_BUTTER_COOKIES,
fields: [
ProductField.COMPARED_TO_CATEGORY,
],
);

final ProductResult result = await OpenFoodAPIClient.getProduct(
configuration,
);

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

group('no nutrition data', () {
// This is barcode refers to a test product
const String barcode = '111111555555';
Expand Down

0 comments on commit 1d59448

Please sign in to comment.