Skip to content

Commit

Permalink
fix: more read-only tests on PROD env (#683)
Browse files Browse the repository at this point in the history
Impacted files:
* `api_get_robotoff_test.dart`: switched to PROD env
* `api_matched_product_v1_test.dart`: switched to PROD env
* `api_search_products_test.dart`: more resilient towards `null` result count
* `ordered_nutrient_test.dart`: switched to PROD env
  • Loading branch information
monsieurtanuki committed Jan 9, 2023
1 parent 793b164 commit cd5cf06
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
12 changes: 3 additions & 9 deletions test/api_get_robotoff_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import 'package:test/test.dart';
import 'test_constants.dart';

void main() {
OpenFoodAPIConfiguration.globalQueryType = QueryType.TEST;
OpenFoodAPIConfiguration.globalQueryType = QueryType.PROD;

group('$OpenFoodAPIClient get robotoff questions', () {
test('get questions for Noix de Saint-Jacques EN', () async {
RobotoffQuestionResult result =
await OpenFoodAPIClient.getRobotoffQuestionsForProduct(
'3274570800026',
'en',
user: TestConstants.TEST_USER,
user: TestConstants.PROD_USER,
count: 1,
);

Expand All @@ -37,7 +37,7 @@ void main() {
await OpenFoodAPIClient.getRobotoffQuestionsForProduct(
'3274570800026',
'fr',
user: TestConstants.TEST_USER,
user: TestConstants.PROD_USER,
);

if (result.status != 'no_questions') {
Expand Down Expand Up @@ -65,7 +65,6 @@ void main() {
TestConstants.PROD_USER,
types: [type],
count: 2,
queryType: QueryType.PROD,
);

expect(result.status, isNotNull);
Expand All @@ -81,7 +80,6 @@ void main() {
'fr',
TestConstants.PROD_USER,
count: 2,
queryType: QueryType.PROD,
);

expect(result.status, isNotNull);
Expand All @@ -95,7 +93,6 @@ void main() {
final InsightsResult result = await OpenFoodAPIClient.getRandomInsight(
TestConstants.PROD_USER,
type: InsightType.CATEGORY,
queryType: QueryType.PROD,
);

expect(result.status, isNotNull);
Expand All @@ -109,15 +106,13 @@ void main() {
final InsightsResult result1 = await OpenFoodAPIClient.getRandomInsight(
TestConstants.PROD_USER,
type: InsightType.CATEGORY,
queryType: QueryType.PROD,
);

final String barcode = result1.insights![0].barcode!;

final InsightsResult result = await OpenFoodAPIClient.getProductInsights(
barcode,
TestConstants.PROD_USER,
queryType: QueryType.PROD,
);

expect(result.status, isNotNull);
Expand All @@ -132,7 +127,6 @@ void main() {
InsightsResult result = await OpenFoodAPIClient.getProductInsights(
fakeBarcode,
TestConstants.PROD_USER,
queryType: QueryType.PROD,
);

expect(result.status, isNotNull);
Expand Down
4 changes: 2 additions & 2 deletions test/api_matched_product_v1_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'test_constants.dart';
void main() {
const int HTTP_OK = 200;

OpenFoodAPIConfiguration.globalQueryType = QueryType.TEST;
OpenFoodAPIConfiguration.globalQueryType = QueryType.PROD;

/// Tests around Matched Product v1.
group('$OpenFoodAPIClient matched product v1', () {
Expand Down Expand Up @@ -55,7 +55,7 @@ void main() {
);
final ProductResultV3 result = await OpenFoodAPIClient.getProductV3(
configurations,
user: TestConstants.TEST_USER,
user: TestConstants.PROD_USER,
);
expect(result.status, ProductResultV3.statusSuccess);
expect(result.barcode, barcode);
Expand Down
5 changes: 4 additions & 1 deletion test/api_search_products_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ void main() {
);

expect(result.products, isNotNull);
if (result.count == null) {
expect(result.products!.length, 0);
}
for (final Product product in result.products!) {
if (veganStatus != null) {
expect(
Expand All @@ -234,7 +237,7 @@ void main() {
);
}
}
return result.count;
return result.count ?? 0;
}

test('check vegan search', () async {
Expand Down
2 changes: 1 addition & 1 deletion test/ordered_nutrient_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:test/test.dart';

/// Tests related to [OrderedNutrient] and [OrderedNutrients]
void main() {
OpenFoodAPIConfiguration.globalQueryType = QueryType.TEST;
OpenFoodAPIConfiguration.globalQueryType = QueryType.PROD;

// Very long list, experimentally created from the 3 initial URLs.
// Don't hesitate to edit this list if you have clear functional ideas
Expand Down

0 comments on commit cd5cf06

Please sign in to comment.