Skip to content

Commit 32d10a4

Browse files
committed
Test empty local storage
1 parent 23ffc0e commit 32d10a4

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,5 @@ packages/**/pubspec.lock
7878
!**/ios/**/default.mode2v3
7979
!**/ios/**/default.pbxuser
8080
!**/ios/**/default.perspectivev3
81+
82+
/packages/*/coverage

packages/supabase_flutter/lib/src/local_storage_stub.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// coverage:ignore-file
12
Future<bool> hasAccessToken(_) => throw UnimplementedError();
23

34
Future<String?> accessToken(_) async => throw UnimplementedError();

packages/supabase_flutter/test/supabase_flutter_test.dart

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,79 @@ void main() {
172172
expect(pkceHttpClient.lastRequestBody['auth_code'], 'my-code-verifier');
173173
});
174174
});
175+
group('EmptyLocalStorage', () {
176+
late EmptyLocalStorage localStorage;
177+
178+
setUp(() async {
179+
mockAppLink();
180+
181+
localStorage = const EmptyLocalStorage();
182+
// Initialize the Supabase singleton
183+
await Supabase.initialize(
184+
url: supabaseUrl,
185+
anonKey: supabaseKey,
186+
debug: false,
187+
authOptions: FlutterAuthClientOptions(
188+
localStorage: localStorage,
189+
pkceAsyncStorage: MockAsyncStorage(),
190+
),
191+
);
192+
});
193+
194+
test('initialize does nothing', () async {
195+
// Should not throw any exceptions
196+
await localStorage.initialize();
197+
});
198+
199+
test('hasAccessToken returns false', () async {
200+
final result = await localStorage.hasAccessToken();
201+
expect(result, false);
202+
});
203+
204+
test('accessToken returns null', () async {
205+
final result = await localStorage.accessToken();
206+
expect(result, null);
207+
});
208+
209+
test('removePersistedSession does nothing', () async {
210+
// Should not throw any exceptions
211+
await localStorage.removePersistedSession();
212+
});
213+
214+
test('persistSession does nothing', () async {
215+
// Should not throw any exceptions
216+
await localStorage.persistSession('test-session-string');
217+
});
218+
219+
test('all methods work together in a typical flow', () async {
220+
// Initialize the storage
221+
await localStorage.initialize();
222+
223+
// Check if there's a token (should be false)
224+
final hasToken = await localStorage.hasAccessToken();
225+
expect(hasToken, false);
226+
227+
// Get the token (should be null)
228+
final token = await localStorage.accessToken();
229+
expect(token, null);
230+
231+
// Try to persist a session
232+
await localStorage.persistSession('test-session-data');
233+
234+
// Check if there's a token after persisting (should still be false)
235+
final hasTokenAfterPersist = await localStorage.hasAccessToken();
236+
expect(hasTokenAfterPersist, false);
237+
238+
// Get the token after persisting (should still be null)
239+
final tokenAfterPersist = await localStorage.accessToken();
240+
expect(tokenAfterPersist, null);
241+
242+
// Try to remove the session
243+
await localStorage.removePersistedSession();
244+
245+
// Check if there's a token after removing (should still be false)
246+
final hasTokenAfterRemove = await localStorage.hasAccessToken();
247+
expect(hasTokenAfterRemove, false);
248+
});
249+
});
175250
}

0 commit comments

Comments
 (0)