Skip to content

Commit

Permalink
Add registration test
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Jul 10, 2024
1 parent 5667e99 commit 69c40d7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
4 changes: 2 additions & 2 deletions test/auth/auth_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {
expect(updateNeeded, false);
});

test('app version higher than min version', () async {
test('app version higher than min version - 1', () async {
// arrange
when(mockClient.get(tVersionUri)).thenAnswer((_) => Future(() => Response('"1.3"', 200)));
final updateNeeded = await authProvider.applicationUpdateRequired('1.1', testMetadata);
Expand All @@ -42,7 +42,7 @@ void main() {
expect(updateNeeded, true);
});

test('app version higher than min version', () async {
test('app version higher than min version - 2', () async {
// arrange
when(mockClient.get(tVersionUri)).thenAnswer((_) => Future(() => Response('"1.3.0"', 200)));
final updateNeeded = await authProvider.applicationUpdateRequired('1.1', testMetadata);
Expand Down
50 changes: 39 additions & 11 deletions test/auth/auth_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ void main() {

final responseRegistrationOk = {
'message': 'api user successfully registered',
'token': 'b01c44d3e3e016a615d2f82b16d31f8b924fb936'
'token': 'b01c44d3e3e016a615d2f82b16d31f8b924fb936',
};

MultiProvider getWidget() {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (ctx) => authProvider),
],
providers: [ChangeNotifierProvider(create: (ctx) => authProvider)],
child: Consumer<AuthProvider>(
builder: (ctx, auth, _) => const MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
Expand Down Expand Up @@ -123,7 +121,7 @@ void main() {
expect(find.byKey(const Key('toggleCustomServerButton')), findsOneWidget);
});

testWidgets('Tests the login - happy path', (WidgetTester tester) async {
testWidgets('Login - happy path', (WidgetTester tester) async {
// Arrange
await tester.pumpWidget(getWidget());

Expand All @@ -142,6 +140,38 @@ void main() {
body: json.encode({'username': 'testuser', 'password': '123456789'}),
));
});

testWidgets('Login - wront username & password', (WidgetTester tester) async {
// Arrange
await tester.binding.setSurfaceSize(const Size(1080, 1920));
tester.view.devicePixelRatio = 1.0;
final response = {
'non_field_errors': ['Username or password unknown'],
};

when(mockClient.post(
tLogin,
headers: anyNamed('headers'),
body: anyNamed('body'),
)).thenAnswer((_) => Future(() => Response(json.encode(response), 400)));
await tester.pumpWidget(getWidget());

// Act
await tester.enterText(find.byKey(const Key('inputUsername')), 'testuser');
await tester.enterText(find.byKey(const Key('inputPassword')), '123456789');
await tester.tap(find.byKey(const Key('actionButton')));
await tester.pumpAndSettle();

// Assert
expect(find.textContaining('An Error Occurred'), findsOne);
expect(find.textContaining('Non field errors'), findsOne);
expect(find.textContaining('Username or password unknown'), findsOne);
verify(mockClient.post(
tLogin,
headers: anyNamed('headers'),
body: json.encode({'username': 'testuser', 'password': '123456789'}),
));
});
});

group('Registration mode', () {
Expand Down Expand Up @@ -173,7 +203,7 @@ void main() {
expect(find.byKey(const Key('inputServer')), findsOneWidget);
});

testWidgets('Tests the registration - happy path', (WidgetTester tester) async {
testWidgets('Registration - happy path', (WidgetTester tester) async {
// Arrange
await tester.binding.setSurfaceSize(const Size(1080, 1920));
tester.view.devicePixelRatio = 1.0;
Expand All @@ -196,18 +226,16 @@ void main() {
));
});

testWidgets('Tests the registration - password problems', (WidgetTester tester) async {
testWidgets('Registration - password problems', (WidgetTester tester) async {
// Arrange
await tester.binding.setSurfaceSize(const Size(1080, 1920));
tester.view.devicePixelRatio = 1.0;
final response = {
'username': [
'This field must be unique.',
],
'username': ['This field must be unique.'],
'password': [
'This password is too common.',
'This password is entirely numeric.',
]
],
};

when(mockClient.post(
Expand Down

0 comments on commit 69c40d7

Please sign in to comment.