Backend (Go): - Project structure with chi router, pgxpool, goose migrations - JWT auth (access/refresh tokens) with Firebase token verification - NoopTokenVerifier for local dev without Firebase credentials - PostgreSQL user repository with atomic profile updates (transactions) - Mifflin-St Jeor calorie calculation based on profile data - REST API: POST /auth/login, /auth/refresh, /auth/logout, GET/PUT /profile, GET /health - Middleware: auth, CORS (localhost wildcard), logging, recovery, request_id - Unit tests (51 passing) and integration tests (testcontainers) - Docker Compose setup with postgres healthcheck and graceful shutdown Flutter client: - Riverpod state management with GoRouter navigation - Firebase Auth (email/password + Google sign-in with web popup support) - Platform-aware API URLs (web/Android/iOS) - Dio HTTP client with JWT auth interceptor and concurrent refresh handling - Secure token storage - Screens: Login, Register, Home (tabs: Menu, Recipes, Products, Profile) - Unit tests (17 passing) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
112 lines
3.3 KiB
Dart
112 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'package:food_ai/core/auth/auth_provider.dart';
|
|
import 'package:food_ai/features/auth/register_screen.dart';
|
|
|
|
class _TestAuthNotifier extends AuthNotifier {
|
|
_TestAuthNotifier()
|
|
: super.test(const AuthState(status: AuthStatus.unauthenticated));
|
|
|
|
@override
|
|
Future<void> signInWithEmail(String email, String password) async {}
|
|
|
|
@override
|
|
Future<void> signInWithGoogle() async {}
|
|
|
|
@override
|
|
Future<void> register(String email, String password, String name) async {}
|
|
|
|
@override
|
|
Future<void> signOut() async {}
|
|
}
|
|
|
|
Widget _buildTestWidget() {
|
|
final router = GoRouter(
|
|
initialLocation: '/auth/register',
|
|
routes: [
|
|
GoRoute(
|
|
path: '/auth/register',
|
|
builder: (_, __) => const RegisterScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/auth/login',
|
|
builder: (_, __) =>
|
|
const Scaffold(body: Text('Login Screen')),
|
|
),
|
|
GoRoute(
|
|
path: '/home',
|
|
builder: (_, __) =>
|
|
const Scaffold(body: Text('Home Screen')),
|
|
),
|
|
],
|
|
);
|
|
|
|
return ProviderScope(
|
|
overrides: [
|
|
authProvider.overrideWith(
|
|
(ref) => _TestAuthNotifier(),
|
|
),
|
|
],
|
|
child: MaterialApp.router(routerConfig: router),
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('renders all form fields', (tester) async {
|
|
await tester.pumpWidget(_buildTestWidget());
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Имя'), findsOneWidget);
|
|
expect(find.text('Email'), findsOneWidget);
|
|
expect(find.text('Пароль'), findsOneWidget);
|
|
expect(find.text('Подтверждение пароля'), findsOneWidget);
|
|
expect(find.text('Зарегистрироваться'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('validates empty name', (tester) async {
|
|
await tester.pumpWidget(_buildTestWidget());
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.text('Зарегистрироваться'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Введите имя'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('validates password mismatch', (tester) async {
|
|
await tester.pumpWidget(_buildTestWidget());
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Имя'), 'Test');
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Email'), 'test@test.com');
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Пароль'), 'password123');
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Подтверждение пароля'),
|
|
'different');
|
|
await tester.tap(find.text('Зарегистрироваться'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Пароли не совпадают'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('has link to login', (tester) async {
|
|
await tester.pumpWidget(_buildTestWidget());
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Уже есть аккаунт? Войти'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('shows registration title', (tester) async {
|
|
await tester.pumpWidget(_buildTestWidget());
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Регистрация'), findsOneWidget);
|
|
});
|
|
}
|