diff --git a/lib/src/mock_supabase_http_client.dart b/lib/src/mock_supabase_http_client.dart index ebeab1c..c5c5b45 100644 --- a/lib/src/mock_supabase_http_client.dart +++ b/lib/src/mock_supabase_http_client.dart @@ -499,6 +499,9 @@ class MockSupabaseHttpClient extends BaseClient { // Handle basic filtering queryParams.forEach((key, value) { + if (returningRows.isEmpty) { + return; + } if (key != 'select' && key != 'order' && key != 'limit' && diff --git a/test/mock_supabase_http_client_test.dart b/test/mock_supabase_http_client_test.dart index 63a158d..86fbf2b 100644 --- a/test/mock_supabase_http_client_test.dart +++ b/test/mock_supabase_http_client_test.dart @@ -122,6 +122,44 @@ void main() { expect(posts.length, 0); }); + test('Select after deleting all items', () async { + // Insert an item + await mockSupabase + .from('posts') + .insert({'id': 1, 'title': 'To be deleted'}); + await mockSupabase.from('posts').delete().eq('id', 1); + final posts = await mockSupabase.from('posts').select().eq('id', 1); + expect(posts.length, 0); + }); + + test('Select with a referenced table filter after deleting all items', + () async { + // Insert an item + await mockSupabase.from('posts').insert({ + 'id': 1, + 'title': 'To be deleted', + 'authors': {'id': 1, 'name': 'Author One'} + }); + await mockSupabase.from('posts').delete().eq('id', 1); + final posts = await mockSupabase + .from('posts') + .select('*, authors(*)') + .eq('authors.name', 'Author One'); + expect(posts.length, 0); + }); + + test('Select with chained filters where the first returns no rows', + () async { + // Insert an item + await mockSupabase.from('posts').insert({'id': 1, 'title': 'First post'}); + final posts = await mockSupabase + .from('posts') + .select() + .eq('id', 2) + .eq('title', 'First post'); + expect(posts.length, 0); + }); + test('Select all columns', () async { // Test selecting all records await mockSupabase.from('posts').insert([