@@ -648,6 +648,61 @@ void main() {
648648 });
649649 });
650650
651+ group ('count' , () {
652+ test ('count' , () async {
653+ await mockSupabase.from ('posts' ).insert ([
654+ {'title' : 'First post' },
655+ {'title' : 'Second post' }
656+ ]);
657+ final count = await mockSupabase.from ('posts' ).count ();
658+ final some = await mockSupabase.from ('posts' ).select ().count ();
659+ expect (count, 2 );
660+ });
661+
662+ test ('count with data' , () async {
663+ await mockSupabase.from ('posts' ).insert ([
664+ {'title' : 'First post' },
665+ {'title' : 'Second post' }
666+ ]);
667+ final response = await mockSupabase.from ('posts' ).select ().count ();
668+ expect (response.data.length, 2 );
669+ expect (response.data.first['title' ], 'First post' );
670+ expect (response.count, 2 );
671+ });
672+
673+ test ('count with filter' , () async {
674+ await mockSupabase.from ('posts' ).insert ([
675+ {'title' : 'First post' },
676+ {'title' : 'Second post' }
677+ ]);
678+ final response = await mockSupabase
679+ .from ('posts' )
680+ .select ()
681+ .eq ('title' , 'First post' )
682+ .count ();
683+ expect (response.data.length, 1 );
684+ expect (response.data.first['title' ], 'First post' );
685+ expect (response.count, 1 );
686+ });
687+
688+ test ('count with filter and modifier' , () async {
689+ await mockSupabase.from ('posts' ).insert ([
690+ {'title' : 'First post' , 'author_id' : 1 },
691+ {'title' : 'Second post' , 'author_id' : 2 },
692+ {'title' : 'Third post' , 'author_id' : 1 }
693+ ]);
694+ final response = await mockSupabase
695+ .from ('posts' )
696+ .select ()
697+ .eq ('author_id' , 1 )
698+ .limit (1 )
699+ .count ();
700+ expect (response.data.length, 1 );
701+ expect (response.data.first['title' ], 'First post' );
702+ expect (response.count, 2 );
703+ });
704+ });
705+
651706 group ('non-ASCII characters tests' , () {
652707 test ('Insert Japanese text' , () async {
653708 await mockSupabase.from ('posts' ).insert ({'title' : 'こんにちは' });
0 commit comments