79 lines
3.1 KiB
Dart
79 lines
3.1 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:motorcycle_dash/firebase_options.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
group('DefaultFirebaseOptions QA Safety Guard Tests (Finding 2)', () {
|
|
test('production options target motoapp-d22e0', () {
|
|
expect(DefaultFirebaseOptions.android.projectId, equals('motoapp-d22e0'));
|
|
expect(DefaultFirebaseOptions.web.projectId, equals('motoapp-d22e0'));
|
|
expect(DefaultFirebaseOptions.ios.projectId, equals('motoapp-d22e0'));
|
|
});
|
|
|
|
test('androidQa options strictly target demo-motorsignal-qa and non-prod credentials', () {
|
|
expect(DefaultFirebaseOptions.androidQa.projectId, equals('demo-motorsignal-qa'));
|
|
expect(DefaultFirebaseOptions.androidQa.apiKey, equals('demo-key'));
|
|
expect(DefaultFirebaseOptions.androidQa.appId, equals('1:123456789:android:qa'));
|
|
expect(DefaultFirebaseOptions.androidQa.storageBucket, equals('demo-motorsignal-qa.appspot.com'));
|
|
});
|
|
|
|
test('validateFirebaseOptions throws StateError if QA mode attempts to use production Firebase', () {
|
|
// Create a simulated production options instance
|
|
const prodOptions = FirebaseOptions(
|
|
apiKey: 'fake-prod-key',
|
|
appId: '1:809431485362:android:06fdcd9ca12ff9342472ab',
|
|
messagingSenderId: '809431485362',
|
|
projectId: 'motoapp-d22e0',
|
|
);
|
|
|
|
const nonDemoOptions = FirebaseOptions(
|
|
apiKey: 'fake-prod-key',
|
|
appId: '1:809431485362:android:06fdcd9ca12ff9342472ab',
|
|
messagingSenderId: '809431485362',
|
|
projectId: 'custom-live-project',
|
|
);
|
|
|
|
const validQaOptions = DefaultFirebaseOptions.androidQa;
|
|
|
|
// When isQa is false, production options are accepted
|
|
if (!DefaultFirebaseOptions.isQa) {
|
|
expect(() => DefaultFirebaseOptions.validateFirebaseOptions(prodOptions), returnsNormally);
|
|
}
|
|
|
|
// If isQa is true or when testing validate logic directly:
|
|
// Verify that validateFirebaseOptions enforces demo-* project prefix in QA
|
|
if (DefaultFirebaseOptions.isQa) {
|
|
expect(
|
|
() => DefaultFirebaseOptions.validateFirebaseOptions(prodOptions),
|
|
throwsA(isA<StateError>().having(
|
|
(e) => e.message,
|
|
'message',
|
|
contains('Android QA flavor cannot connect to production Firebase'),
|
|
)),
|
|
);
|
|
|
|
expect(
|
|
() => DefaultFirebaseOptions.validateFirebaseOptions(nonDemoOptions),
|
|
throwsA(isA<StateError>()),
|
|
);
|
|
|
|
expect(
|
|
() => DefaultFirebaseOptions.validateFirebaseOptions(validQaOptions),
|
|
returnsNormally,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('currentPlatform returns androidQa when isQa is true on Android', () {
|
|
if (DefaultFirebaseOptions.isQa && defaultTargetPlatform == TargetPlatform.android) {
|
|
final options = DefaultFirebaseOptions.currentPlatform;
|
|
expect(options.projectId, equals('demo-motorsignal-qa'));
|
|
expect(options.projectId, isNot(equals('motoapp-d22e0')));
|
|
}
|
|
});
|
|
});
|
|
}
|