phase 0
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:app_boilerplate/config/app_config.dart';
|
||||
import 'package:app_boilerplate/config/config_loader.dart';
|
||||
|
||||
void main() {
|
||||
group('ConfigLoader', () {
|
||||
/// Tests that loading 'dev' environment returns the correct configuration.
|
||||
test('load dev config returns correct AppConfig', () {
|
||||
// Arrange & Act
|
||||
final config = ConfigLoader.load('dev');
|
||||
|
||||
// Assert
|
||||
expect(config.apiBaseUrl, equals('https://api-dev.example.com'));
|
||||
expect(config.enableLogging, isTrue);
|
||||
});
|
||||
|
||||
/// Tests that loading 'prod' environment returns the correct configuration.
|
||||
test('load prod config returns correct AppConfig', () {
|
||||
// Arrange & Act
|
||||
final config = ConfigLoader.load('prod');
|
||||
|
||||
// Assert
|
||||
expect(config.apiBaseUrl, equals('https://api.example.com'));
|
||||
expect(config.enableLogging, isFalse);
|
||||
});
|
||||
|
||||
/// Tests that loading configuration is case-insensitive.
|
||||
test('load config is case-insensitive', () {
|
||||
// Arrange & Act
|
||||
final devConfig = ConfigLoader.load('DEV');
|
||||
final prodConfig = ConfigLoader.load('PROD');
|
||||
|
||||
// Assert
|
||||
expect(devConfig.apiBaseUrl, equals('https://api-dev.example.com'));
|
||||
expect(devConfig.enableLogging, isTrue);
|
||||
expect(prodConfig.apiBaseUrl, equals('https://api.example.com'));
|
||||
expect(prodConfig.enableLogging, isFalse);
|
||||
});
|
||||
|
||||
/// Tests that loading an invalid environment throws InvalidEnvironmentException.
|
||||
test('load invalid environment throws InvalidEnvironmentException', () {
|
||||
// Arrange & Act & Assert
|
||||
expect(
|
||||
() => ConfigLoader.load('invalid'),
|
||||
throwsA(isA<InvalidEnvironmentException>()),
|
||||
);
|
||||
});
|
||||
|
||||
/// Tests that InvalidEnvironmentException contains the invalid environment.
|
||||
test('InvalidEnvironmentException contains invalid environment', () {
|
||||
// Arrange
|
||||
const invalidEnv = 'staging';
|
||||
|
||||
// Act
|
||||
try {
|
||||
ConfigLoader.load(invalidEnv);
|
||||
fail('Expected InvalidEnvironmentException to be thrown');
|
||||
} catch (e) {
|
||||
// Assert
|
||||
expect(e, isA<InvalidEnvironmentException>());
|
||||
final exception = e as InvalidEnvironmentException;
|
||||
expect(exception.environment, equals(invalidEnv));
|
||||
expect(exception.toString(), contains(invalidEnv));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user