Skip to content

Commit

Permalink
fix: openfoodfacts#1239 Create a test for registration and login (ope…
Browse files Browse the repository at this point in the history
…nfoodfacts#3069)

* fix: fixes 1286

* Upgraded openfoodfacts to 1.25.0

* added registration and login test

* Added wrong credential & duplicate login test

Co-authored-by: Marvin Möltgen <39344769+M123-dev@users.noreply.github.com>
  • Loading branch information
abughalib and M123-dev authored Oct 3, 2022
1 parent dbf0d7b commit 6644d59
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/smooth_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ packages:
name: json_annotation
url: "https://pub.dartlang.org"
source: hosted
version: "4.6.0"
version: "4.7.0"
latlong2:
dependency: "direct main"
description:
Expand Down Expand Up @@ -839,7 +839,7 @@ packages:
name: openfoodfacts
url: "https://pub.dartlang.org"
source: hosted
version: "1.24.0"
version: "1.25.0"
openfoodfacts_flutter_lints:
dependency: "direct dev"
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies:
latlong2: 0.8.1
matomo_tracker: 1.4.1
modal_bottom_sheet: 2.1.0
openfoodfacts: 1.24.0
openfoodfacts: 1.25.0
# openfoodfacts:
# path: ../../../openfoodfacts-dart
package_info_plus: 1.4.3+1
Expand Down
63 changes: 63 additions & 0 deletions packages/smooth_app/test/users/registration_login_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'dart:math';
import 'package:flutter_test/flutter_test.dart';
import 'package:openfoodfacts/model/SignUpStatus.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:openfoodfacts/utils/QueryType.dart';

void main() {
const QueryType queryType = QueryType.TEST;
final String name = _generateRandomString(4);
final String email = '$name@example.com';
const String password = 'test_password';

group('Create User & Login', () {
test('Create User', () async {
final SignUpStatus signUpResponse = await OpenFoodAPIClient.register(
user: User(userId: name, password: password),
name: name,
email: email,
orgName: null,
queryType: queryType,
newsletter: false,
);

expect(signUpResponse.status, 201);
});

test('Login User', () async {
final bool loginResponse = await OpenFoodAPIClient.login(
User(userId: name, password: password),
queryType: queryType,
);

expect(loginResponse, true);
});

test('Wrong Credential User Login', () async {
final bool loginResponse = await OpenFoodAPIClient.login(
User(userId: name, password: 'somerandomnewpassword'),
queryType: queryType,
);
expect(loginResponse, false);
});
test('Duplicate Registration', () async {
final SignUpStatus signUpResponse = await OpenFoodAPIClient.register(
user: User(userId: name, password: password),
name: name,
email: email,
orgName: null,
queryType: queryType,
newsletter: false,
);
expect(signUpResponse.status, 400);
});
});
}

String _generateRandomString(int length) {
final Random r = Random();
return String.fromCharCodes(
List<int>.generate(length, (int index) => r.nextInt(26) + 65),
).toLowerCase() +
(DateTime.now().microsecondsSinceEpoch).toString();
}

0 comments on commit 6644d59

Please sign in to comment.