- Umgebungen (Name, API-URL, Keycloak-Issuer) kommen aus assets/hl_server_config.json statt hartcodiertem BackendConfig.prod; Testumgebung 192.168.1.9:3001 ist dort hinterlegt - AppBloc laedt die Config, aktiviert die gespeicherte Wahl (Fallback Default) und registriert das Networking; Wechsel persistiert per SharedPreferences und registriert neu - Bloc-Baum ist pro Umgebung gekeyt: beim Wechsel entstehen alle Blocs mit dem neuen API-Client neu - Login-Screen: Zahnrad oben rechts oeffnet Einstellungen mit Umgebungs- Cards (Name + IP:Port); Hinweis auf aktive Umgebung unter dem Button - Fahrzeugauswahl pro Umgebung getrennt (eigene DB = eigene Car-IDs) - Tests fuer Config-Parsing, Auswahl-Fallback, Card-Wechsel, Re-Registrierung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.4 KiB
Dart
74 lines
2.4 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:holzleitner_api/holzleitner_api.dart';
|
|
import 'package:hl_lieferservice/data/network/backend_config.dart';
|
|
import 'package:hl_lieferservice/data/network/network_locator.dart';
|
|
import 'package:hl_lieferservice/data/network/backend_environment.dart';
|
|
|
|
void main() {
|
|
ServerCatalog load() => ServerCatalog.fromJson(
|
|
jsonDecode(File('assets/hl_server_config.json').readAsStringSync())
|
|
as Map<String, dynamic>,
|
|
);
|
|
|
|
test('ausgelieferte Config enthält Produktion (Default) und Test', () {
|
|
final catalog = load();
|
|
|
|
expect(catalog.defaultEnvironment.id, 'production');
|
|
expect(catalog.byId('production')!.hostAndPort, '192.168.1.9:3000');
|
|
expect(catalog.byId('test')!.hostAndPort, '192.168.1.9:3001');
|
|
expect(catalog.keycloakClientId, 'holzleitner-app');
|
|
});
|
|
|
|
test('configFor übernimmt Umgebung und globale Keycloak-Daten', () {
|
|
final catalog = load();
|
|
final config = catalog.configFor(catalog.byId('test')!);
|
|
|
|
expect(config.apiBaseUrl, 'http://192.168.1.9:3001');
|
|
expect(config.keycloakRedirectUrl, 'holzleitner://oauth2redirect');
|
|
});
|
|
|
|
test('unbekannte Default-Umgebung wird abgelehnt', () {
|
|
expect(
|
|
() => ServerCatalog.fromJson({
|
|
'defaultEnvironment': 'nope',
|
|
'keycloak': {'clientId': 'c', 'redirectUrl': 'r://x'},
|
|
'environments': [
|
|
{
|
|
'id': 'a',
|
|
'name': 'A',
|
|
'apiBaseUrl': 'http://h:1/',
|
|
'keycloakIssuerUrl': 'http://k/realms/x',
|
|
},
|
|
],
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
});
|
|
|
|
test('registerNetworking ersetzt beim Umgebungswechsel die Instanzen', () {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
final catalog = load();
|
|
final locator = GetIt.asNewInstance();
|
|
|
|
registerNetworking(
|
|
locator: locator,
|
|
config: catalog.configFor(catalog.byId('production')!),
|
|
);
|
|
final firstApi = locator<HolzleitnerApi>();
|
|
|
|
registerNetworking(
|
|
locator: locator,
|
|
config: catalog.configFor(catalog.byId('test')!),
|
|
);
|
|
|
|
expect(locator<BackendConfig>().apiBaseUrl, 'http://192.168.1.9:3001');
|
|
expect(identical(locator<HolzleitnerApi>(), firstApi), isFalse);
|
|
expect(locator<HolzleitnerApi>().dio.options.baseUrl,
|
|
'http://192.168.1.9:3001');
|
|
});
|
|
}
|