40 lines
1.2 KiB
Dart
40 lines
1.2 KiB
Dart
|
|
import 'package:mnemo_cards_telegram_bot/bot_config.dart';
|
||
|
|
import 'package:test/test.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
group('BotConfig', () {
|
||
|
|
test('prefers CLI backend url when provided', () {
|
||
|
|
final parser = buildParser();
|
||
|
|
final results =
|
||
|
|
parser.parse(['--backend-url', 'https://api.example.com']);
|
||
|
|
|
||
|
|
final config =
|
||
|
|
BotConfig.fromArgs(results, environment: const <String, String>{});
|
||
|
|
|
||
|
|
expect(config.backendUrl, equals('https://api.example.com'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('falls back to environment variables when CLI arg missing', () {
|
||
|
|
final parser = buildParser();
|
||
|
|
final results = parser.parse(<String>[]);
|
||
|
|
|
||
|
|
final config = BotConfig.fromArgs(
|
||
|
|
results,
|
||
|
|
environment: const {'MNEMO_BACKEND_URL': 'https://env.example.com'},
|
||
|
|
);
|
||
|
|
|
||
|
|
expect(config.backendUrl, equals('https://env.example.com'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('uses default backend url when neither CLI nor env provided', () {
|
||
|
|
final parser = buildParser();
|
||
|
|
final results = parser.parse(<String>[]);
|
||
|
|
|
||
|
|
final config =
|
||
|
|
BotConfig.fromArgs(results, environment: const <String, String>{});
|
||
|
|
|
||
|
|
expect(config.backendUrl, equals(BotConfig.defaultBackendUrl));
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|