Skip to content

Commit ce37ae0

Browse files
committed
test: migrate storage keys to enum
- Migrated to enum - Added tests for enum values
1 parent d8f1484 commit ce37ae0

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

test/src/storage_keys_test.dart

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1-
// ignore_for_file: prefer_const_constructors
2-
import 'package:ht_kv_storage_service/src/storage_keys.dart';
1+
// ignore_for_file: lines_longer_than_80_chars
2+
3+
import 'package:ht_kv_storage_service/ht_kv_storage_service.dart';
34
import 'package:test/test.dart';
45

56
void main() {
6-
group('StorageKeys', () {
7-
test('constants have correct values', () {
8-
expect(StorageKeys.pendingSignInEmail, equals('pending_signin_email'));
9-
expect(StorageKeys.hasSeenOnboarding, equals('has_seen_onboarding'));
7+
group('StorageKey Enum', () {
8+
test('stringValue getter returns correct values', () {
9+
// Check the stringValue getter for each enum member
10+
expect(
11+
StorageKey.pendingSignInEmail.stringValue,
12+
equals('pending_signin_email'),
13+
);
14+
expect(
15+
StorageKey.hasSeenOnboarding.stringValue,
16+
equals('has_seen_onboarding'),
17+
);
1018
});
1119

12-
// Since the constructor is private, we cannot test instantiation directly,
13-
// which is the intended behavior.
20+
// Test that all enum values are covered in the stringValue getter's switch statement.
21+
// This helps prevent forgetting to update the getter when adding new keys.
22+
test('stringValue getter covers all enum values', () {
23+
for (final key in StorageKey.values) {
24+
// Expecting the getter not to throw an error is a basic check that
25+
// the switch statement handles all cases.
26+
expect(() => key.stringValue, returnsNormally);
27+
}
28+
});
1429
});
1530
}

0 commit comments

Comments
 (0)