55 lines
1.9 KiB
Dart
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,
|
|
];
|