41 lines
1.5 KiB
Dart
41 lines
1.5 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:motorcycle_dash/core/error_mapper.dart';
|
|
|
|
void main() {
|
|
group('ErrorMapper', () {
|
|
test('maps known Firebase failures to fixed user-safe messages', () {
|
|
expect(
|
|
ErrorMapper.map(FirebaseException(plugin: 'test', code: 'permission-denied')),
|
|
'You do not have permission to perform this action.',
|
|
);
|
|
expect(
|
|
ErrorMapper.map(FirebaseException(plugin: 'test', code: 'unavailable')),
|
|
'A network error occurred. Please check your connection and try again.',
|
|
);
|
|
});
|
|
|
|
test('maps typed connection failures without rendering exception text', () {
|
|
expect(
|
|
ErrorMapper.map(const SocketException('private host details')),
|
|
'A network error occurred. Please check your connection and try again.',
|
|
);
|
|
expect(
|
|
ErrorMapper.map(TimeoutException('private timeout details')),
|
|
'A network error occurred. Please check your connection and try again.',
|
|
);
|
|
});
|
|
|
|
test('fails closed for unknown and state errors', () {
|
|
const secret = 'sensitive-internal-detail';
|
|
|
|
expect(ErrorMapper.map(StateError(secret)), 'Something went wrong. Please try again.');
|
|
expect(ErrorMapper.map(Exception(secret)), 'Something went wrong. Please try again.');
|
|
expect(ErrorMapper.map(StateError(secret)), isNot(contains(secret)));
|
|
});
|
|
});
|
|
}
|