You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.9 KiB
80 lines
2.9 KiB
import 'package:flutter_test/flutter_test.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 - check that config loads successfully with valid values
|
|
expect(config.apiBaseUrl, isNotEmpty);
|
|
expect(config.enableLogging, isTrue);
|
|
expect(config.immichBaseUrl, isNotEmpty);
|
|
expect(config.immichApiKey, isNotEmpty);
|
|
expect(config.nostrRelays, isNotEmpty);
|
|
});
|
|
|
|
/// Tests that loading 'prod' environment returns the correct configuration.
|
|
test('load prod config returns correct AppConfig', () {
|
|
// Arrange & Act
|
|
final config = ConfigLoader.load('prod');
|
|
|
|
// Assert - check that config loads successfully with valid values
|
|
expect(config.apiBaseUrl, isNotEmpty);
|
|
expect(config.enableLogging, isFalse);
|
|
expect(config.immichBaseUrl, isNotEmpty);
|
|
expect(config.immichApiKey, isNotEmpty);
|
|
expect(config.nostrRelays, isNotEmpty);
|
|
});
|
|
|
|
/// 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 - check that configs load successfully and are different
|
|
expect(devConfig.apiBaseUrl, isNotEmpty);
|
|
expect(devConfig.enableLogging, isTrue);
|
|
expect(devConfig.immichBaseUrl, isNotEmpty);
|
|
expect(devConfig.nostrRelays, isNotEmpty);
|
|
expect(prodConfig.apiBaseUrl, isNotEmpty);
|
|
expect(prodConfig.enableLogging, isFalse);
|
|
expect(prodConfig.immichBaseUrl, isNotEmpty);
|
|
expect(prodConfig.nostrRelays, isNotEmpty);
|
|
// Verify dev and prod configs are different
|
|
expect(devConfig.apiBaseUrl, isNot(equals(prodConfig.apiBaseUrl)));
|
|
});
|
|
|
|
/// 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));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|