forked from openfoodfacts/smooth-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…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
Showing
3 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/smooth_app/test/users/registration_login_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |