Shuffle/app/test/helpers/fakes.dart
cschlaefke adf61b3ba2 test: add pumpApp helpers, fakes and coverage matrix template
Refs #31

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 20:21:55 +01:00

55 lines
1.9 KiB
Dart

import 'package:flutter_riverpod/misc.dart' show Override;
import 'package:mocktail/mocktail.dart';
import 'package:shuffle/core/config/app_config.dart';
import 'package:shuffle/core/config/app_config_provider.dart';
import 'package:shuffle/core/supabase/supabase_client_provider.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
/// Mock des Supabase-Clients. Kein Netzwerk: nicht gestubbte Aufrufe schlagen
/// mit einem mocktail-Fehler fehl, statt still zu laufen.
class MockSupabaseClient extends Mock implements SupabaseClient {}
/// Mock der Auth-Schnittstelle (`client.auth`).
class MockGoTrueClient extends Mock implements GoTrueClient {}
/// Feste Test-Konfiguration ohne echte Zugangsdaten.
AppConfig testAppConfig({
String environment = 'test',
String supabaseUrl = 'http://localhost:54321',
String supabaseAnonKey = 'test-anon-key',
String siteUrl = 'http://localhost:3000',
String legalPrivacyUrl = 'https://example.test/privacy',
String legalTermsUrl = 'https://example.test/terms',
String termsVersion = 'test-1',
}) => AppConfig(
environment: environment,
supabaseUrl: supabaseUrl,
supabaseAnonKey: supabaseAnonKey,
siteUrl: siteUrl,
legalPrivacyUrl: legalPrivacyUrl,
legalTermsUrl: legalTermsUrl,
termsVersion: termsVersion,
);
/// Ein Mock-Client samt Auth-Mock: `client.auth` liefert [auth].
class SupabaseMocks {
SupabaseMocks() {
when(() => client.auth).thenReturn(auth);
}
final client = MockSupabaseClient();
final auth = MockGoTrueClient();
}
/// Standard-Overrides für Tests: feste [AppConfig] und ein Supabase-Mock.
///
/// Zusätzliche [overrides] kommen hinten dran und haben Vorrang.
List<Override> testOverrides({
AppConfig? config,
SupabaseClient? supabase,
List<Override> overrides = const [],
}) => [
appConfigProvider.overrideWithValue(config ?? testAppConfig()),
supabaseClientProvider.overrideWithValue(supabase ?? MockSupabaseClient()),
...overrides,
];