feat: implement Iteration 0 foundation (backend + Flutter client)

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>
This commit is contained in:
dbastrikin
2026-02-20 13:14:58 +02:00
commit 24219b611e
140 changed files with 13062 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
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/login_screen.dart';
class _TestAuthNotifier extends AuthNotifier {
_TestAuthNotifier(super.initialState) : super.test();
@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({AuthState? initialState}) {
final authState = initialState ??
const AuthState(status: AuthStatus.unauthenticated);
final router = GoRouter(
initialLocation: '/auth/login',
routes: [
GoRoute(
path: '/auth/login',
builder: (_, __) => const LoginScreen(),
),
GoRoute(
path: '/auth/register',
builder: (_, __) =>
const Scaffold(body: Text('Register Screen')),
),
GoRoute(
path: '/home',
builder: (_, __) =>
const Scaffold(body: Text('Home Screen')),
),
],
);
return ProviderScope(
overrides: [
authProvider.overrideWith(
(ref) => _TestAuthNotifier(authState),
),
],
child: MaterialApp.router(routerConfig: router),
);
}
void main() {
testWidgets('renders email and password fields and buttons',
(tester) async {
await tester.pumpWidget(_buildTestWidget());
await tester.pumpAndSettle();
expect(find.text('Email'), findsOneWidget);
expect(find.text('Пароль'), findsOneWidget);
expect(find.text('Войти'), findsOneWidget);
expect(find.text('Войти через Google'), findsOneWidget);
expect(find.text('Нет аккаунта? Регистрация'), findsOneWidget);
});
testWidgets('validates empty email', (tester) async {
await tester.pumpWidget(_buildTestWidget());
await tester.pumpAndSettle();
await tester.tap(find.text('Войти'));
await tester.pumpAndSettle();
expect(find.text('Введите email'), findsOneWidget);
});
testWidgets('validates invalid email format', (tester) async {
await tester.pumpWidget(_buildTestWidget());
await tester.pumpAndSettle();
await tester.enterText(
find.widgetWithText(TextFormField, 'Email'), 'abc');
await tester.tap(find.text('Войти'));
await tester.pumpAndSettle();
expect(find.text('Некорректный email'), findsOneWidget);
});
testWidgets('validates short password', (tester) async {
await tester.pumpWidget(_buildTestWidget());
await tester.pumpAndSettle();
await tester.enterText(
find.widgetWithText(TextFormField, 'Email'), 'test@test.com');
await tester.enterText(
find.widgetWithText(TextFormField, 'Пароль'), '123');
await tester.tap(find.text('Войти'));
await tester.pumpAndSettle();
expect(find.text('Минимум 6 символов'), findsOneWidget);
});
testWidgets('shows FoodAI branding', (tester) async {
await tester.pumpWidget(_buildTestWidget());
await tester.pumpAndSettle();
expect(find.text('FoodAI'), findsOneWidget);
expect(find.text('Управляйте питанием\nс помощью AI'), findsOneWidget);
});
}

View File

@@ -0,0 +1,111 @@
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);
});
}