Skip to content

Commit

Permalink
feat: #503 - added the "all to-be-completed products" configuration (#…
Browse files Browse the repository at this point in the history
…504)

New files:
* `api_getToBeCompletedProducts_test.dart`: Integration tests related to `ToBeCompletedQueryConfiguration`
* `ToBeCompletedConfiguration.dart`: Query Configuration for all the to-be-completed products.

Impacted file:
* `api_saveProduct_test.dart`: unrelated failing test skip
  • Loading branch information
monsieurtanuki authored Jul 2, 2022
1 parent 16e66af commit b7c16ed
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
39 changes: 39 additions & 0 deletions lib/utils/ToBeCompletedConfiguration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:openfoodfacts/utils/AbstractQueryConfiguration.dart';
import 'package:openfoodfacts/utils/CountryHelper.dart';

/// Query Configuration for all the to-be-completed products.
class ToBeCompletedQueryConfiguration extends AbstractQueryConfiguration {
ToBeCompletedQueryConfiguration({
final OpenFoodFactsLanguage? language,
final List<OpenFoodFactsLanguage> languages =
const <OpenFoodFactsLanguage>[],
final OpenFoodFactsCountry? country,
final List<ProductField>? fields,
final int? pageNumber,
final int? pageSize,
}) : super(
language: language,
languages: languages,
country: country,
fields: fields,
additionalParameters: _convertToParametersList(pageNumber, pageSize),
);

static List<Parameter> _convertToParametersList(
int? page,
int? pageSize,
) {
final List<Parameter> result = <Parameter>[];
if (page != null) {
result.add(PageNumber(page: page));
}
if (pageSize != null) {
result.add(PageSize(size: pageSize));
}
return result;
}

@override
String getUriPath() => '/state/to-be-completed.json';
}
27 changes: 27 additions & 0 deletions test/api_getToBeCompletedProducts_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart';
import 'package:openfoodfacts/utils/QueryType.dart';
import 'package:openfoodfacts/utils/ToBeCompletedConfiguration.dart';
import 'package:test/test.dart';

import 'test_constants.dart';

/// Integration tests related to [ToBeCompletedQueryConfiguration]
void main() {
OpenFoodAPIConfiguration.globalUser = TestConstants.PROD_USER;
OpenFoodAPIConfiguration.globalQueryType = QueryType.PROD;

group('$OpenFoodAPIClient get all to-be-completed products', () {
test('all types', () async {
final SearchResult result = await OpenFoodAPIClient.getProducts(
OpenFoodAPIConfiguration.globalUser,
ToBeCompletedQueryConfiguration(),
queryType: OpenFoodAPIConfiguration.globalQueryType,
);

expect(result.page, 1); // default
expect(result.products, isNotNull);
expect(result.count, greaterThan(1000000)); // 20220630: was 2403413
});
});
}
2 changes: 1 addition & 1 deletion test/api_saveProduct_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ void main() {
}
}
}
});
}, skip: 'Works randomly');

String _generateRandomString(int len) {
var r = Random();
Expand Down

0 comments on commit b7c16ed

Please sign in to comment.