-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathenvironment_config_test.dart
More file actions
105 lines (76 loc) · 3.44 KB
/
Copy pathenvironment_config_test.dart
File metadata and controls
105 lines (76 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import 'package:flutter_test/flutter_test.dart';
import 'package:webtrit_phone/environment_config.dart';
void main() {
group('EnvRegistry', () {
late EnvRegistry registry;
setUp(() => registry = EnvRegistry());
test('string: override wins; empty and missing fall back to compile-time', () {
registry.apply({'A': 'override'});
expect(registry.string('A', 'default'), 'override');
registry.apply({'A': ''});
expect(registry.string('A', 'default'), 'default');
registry.apply({});
expect(registry.string('A', 'default'), 'default');
});
test('stringOrNull: empty and missing fall back (may be null)', () {
registry.apply({'A': ''});
expect(registry.stringOrNull('A', null), isNull);
expect(registry.stringOrNull('A', 'd'), 'd');
registry.apply({'A': 'x'});
expect(registry.stringOrNull('A', 'd'), 'x');
});
test('boolean: true/false honoured; malformed and empty fall back', () {
registry.apply({'B': 'TRUE'});
expect(registry.boolean('B', false), isTrue);
registry.apply({'B': 'false'});
expect(registry.boolean('B', true), isFalse);
registry.apply({'B': 'yes'}); // malformed -> compile-time
expect(registry.boolean('B', true), isTrue);
registry.apply({'B': ''}); // empty -> compile-time
expect(registry.boolean('B', true), isTrue);
registry.apply({});
expect(registry.boolean('B', false), isFalse);
});
test('integer: numeric honoured; malformed and empty fall back', () {
registry.apply({'N': '42'});
expect(registry.integer('N', 1), 42);
registry.apply({'N': 'abc'});
expect(registry.integer('N', 7), 7);
registry.apply({'N': ''});
expect(registry.integer('N', 7), 7);
});
test('has / clear', () {
registry.apply({'A': 'x'});
expect(registry.has('A'), isTrue);
registry.clear();
expect(registry.has('A'), isFalse);
});
});
group('EnvironmentConfig overrides', () {
tearDown(EnvironmentConfig.clearOverrides);
test('APP_NAME reflects an override and falls back when empty/cleared', () {
EnvironmentConfig.applyOverrides({EnvironmentConfig.APP_NAME__NAME: 'Custom'});
expect(EnvironmentConfig.APP_NAME, 'Custom');
EnvironmentConfig.applyOverrides({EnvironmentConfig.APP_NAME__NAME: ''});
expect(EnvironmentConfig.APP_NAME, 'WebTrit');
EnvironmentConfig.clearOverrides();
expect(EnvironmentConfig.APP_NAME, 'WebTrit');
});
test('a non-positive polling-interval override falls back to the default', () {
const name = EnvironmentConfig.USER_REPOSITORY_POLLING_INTERVAL_SECONDS__NAME;
EnvironmentConfig.applyOverrides({name: '0'});
expect(EnvironmentConfig.USER_REPOSITORY_POLLING_INTERVAL_SECONDS, 10);
EnvironmentConfig.applyOverrides({name: '-5'});
expect(EnvironmentConfig.USER_REPOSITORY_POLLING_INTERVAL_SECONDS, 10);
EnvironmentConfig.applyOverrides({name: '30'});
expect(EnvironmentConfig.USER_REPOSITORY_POLLING_INTERVAL_SECONDS, 30);
});
test('FIREBASE_ENABLED defaults to true and reflects a false override', () {
expect(EnvironmentConfig.FIREBASE_ENABLED, isTrue);
EnvironmentConfig.applyOverrides({EnvironmentConfig.FIREBASE_ENABLED__NAME: 'false'});
expect(EnvironmentConfig.FIREBASE_ENABLED, isFalse);
EnvironmentConfig.clearOverrides();
expect(EnvironmentConfig.FIREBASE_ENABLED, isTrue);
});
});
}