mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-07-04 11:47:58 +02:00
Force simulate mode when OSM OAuth secrets are missing
Preview/PR builds don't have access to GitHub Secrets, so the OAuth client IDs are empty. Previously this caused a runtime crash from keys.dart throwing on empty values. Now we detect missing secrets and force simulate mode, which already fully supports fake auth and uploads. Also fixes a latent bug where forceLogin() would crash with LateInitializationError in simulate mode since _helper is never initialized when OAuth setup is skipped. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:deflockapp/state/settings_state.dart';
|
||||
import 'package:deflockapp/keys.dart';
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
});
|
||||
|
||||
group('kHasOsmSecrets (no --dart-define)', () {
|
||||
test('is false when built without secrets', () {
|
||||
expect(kHasOsmSecrets, isFalse);
|
||||
});
|
||||
|
||||
test('client ID getters return empty strings instead of throwing', () {
|
||||
expect(kOsmProdClientId, isEmpty);
|
||||
expect(kOsmSandboxClientId, isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('SettingsState without secrets', () {
|
||||
test('defaults to simulate mode', () {
|
||||
final state = SettingsState();
|
||||
expect(state.uploadMode, UploadMode.simulate);
|
||||
});
|
||||
|
||||
test('init() forces simulate even if prefs has production stored', () async {
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'upload_mode': UploadMode.production.index,
|
||||
});
|
||||
|
||||
final state = SettingsState();
|
||||
await state.init();
|
||||
|
||||
expect(state.uploadMode, UploadMode.simulate);
|
||||
|
||||
// Verify it persisted the override
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
expect(prefs.getInt('upload_mode'), UploadMode.simulate.index);
|
||||
});
|
||||
|
||||
test('init() forces simulate even if prefs has sandbox stored', () async {
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'upload_mode': UploadMode.sandbox.index,
|
||||
});
|
||||
|
||||
final state = SettingsState();
|
||||
await state.init();
|
||||
|
||||
expect(state.uploadMode, UploadMode.simulate);
|
||||
});
|
||||
|
||||
test('init() keeps simulate if already simulate', () async {
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'upload_mode': UploadMode.simulate.index,
|
||||
});
|
||||
|
||||
final state = SettingsState();
|
||||
await state.init();
|
||||
|
||||
expect(state.uploadMode, UploadMode.simulate);
|
||||
});
|
||||
|
||||
test('setUploadMode() allows simulate', () async {
|
||||
final state = SettingsState();
|
||||
await state.setUploadMode(UploadMode.simulate);
|
||||
|
||||
expect(state.uploadMode, UploadMode.simulate);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user