|
| 1 | +import 'package:flagsmith/flagsmith.dart'; |
| 2 | +import 'package:test/test.dart'; |
| 3 | +import '../shared.dart'; |
| 4 | + |
| 5 | +class TestStorage extends InMemoryStorage { |
| 6 | + bool initCalled = false; |
| 7 | + |
| 8 | + @override |
| 9 | + Future<void> init() async { |
| 10 | + initCalled = true; |
| 11 | + return Future.value(); |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +void main() { |
| 16 | + group('FlagsmithClient with custom storage', () { |
| 17 | + test('Should initialize with custom storage', () async { |
| 18 | + final customStorage = TestStorage(); |
| 19 | + |
| 20 | + // Initialize the client with custom storage |
| 21 | + final client = await FlagsmithClient.init( |
| 22 | + apiKey: apiKey, |
| 23 | + config: const FlagsmithConfig( |
| 24 | + storageType: StorageType.custom, |
| 25 | + isDebug: true, |
| 26 | + ), |
| 27 | + storage: customStorage, |
| 28 | + seeds: <Flag>[ |
| 29 | + Flag.seed('feature', enabled: true), |
| 30 | + ], |
| 31 | + ); |
| 32 | + |
| 33 | + // Verify the client was initialized successfully |
| 34 | + expect(client, isA<FlagsmithClient>()); |
| 35 | + expect(customStorage.initCalled, isTrue); |
| 36 | + |
| 37 | + // Clean up |
| 38 | + client.close(); |
| 39 | + }); |
| 40 | + |
| 41 | + test('Should throw error when StorageType.custom is used without providing storage', () async { |
| 42 | + expect( |
| 43 | + () => FlagsmithClient.init( |
| 44 | + apiKey: apiKey, |
| 45 | + config: const FlagsmithConfig( |
| 46 | + storageType: StorageType.custom, |
| 47 | + isDebug: true, |
| 48 | + ), |
| 49 | + seeds: <Flag>[ |
| 50 | + Flag.seed('feature', enabled: true), |
| 51 | + ], |
| 52 | + ), |
| 53 | + throwsA(isA<FlagsmithConfigException>()), |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + }); |
| 58 | +} |
0 commit comments