11import assert from "assert" ;
22import { describe , it , beforeAll , afterAll } from "vitest" ;
33import { createClient } from "@supabase/supabase-js" ;
4- import type { Database } from "@repo/database/dbTypes" ;
4+ import type { Database , Tables } from "@repo/database/dbTypes" ;
55import type { DGSupabaseClient } from "@repo/database/lib/client" ;
66import {
77 fetchOrCreateSpaceDirect ,
@@ -14,7 +14,7 @@ const ANON_KEY = process.env.SUPABASE_PUBLISHABLE_KEY!;
1414const SERVICE_KEY = process . env . SUPABASE_SECRET_KEY ! ;
1515const PASSWORD = "abcdefgh" ;
1616
17- type GroupSpaceInfo = Database [ "public" ] [ "CompositeTypes" ] [ "group_space_info" ] ;
17+ type PseudoAccountInfo = Tables < "my_pseudo_accounts" > ;
1818
1919const freshClient = ( ) : DGSupabaseClient =>
2020 createClient < Database , "public" > ( SUPABASE_URL , ANON_KEY ) ;
@@ -121,19 +121,17 @@ describe("list group members flow", { tags: ["database"] }, () => {
121121
122122 const expectedSpaceIds = [ spaceId1 , spaceId2 ] ;
123123 // Step 3: user1 lists group members
124- const { data : data1 , error : error1 } = await client1 . rpc (
125- "spaces_in_group" ,
126- {
127- p_group_id : createdGroupId , // eslint-disable-line @typescript-eslint/naming-convention
128- } ,
129- ) ;
124+ const { data : data1 , error : error1 } = await client1
125+ . from ( "my_pseudo_accounts" )
126+ . select ( )
127+ . eq ( "group_id" , createdGroupId ) ;
130128
131129 assert ( error1 === null , error1 ? error1 . message : "" ) ;
132130 assert ( data1 !== null , "group spaces should not be empty" ) ;
133131 assert ( data1 . length === 2 , "There should be two spaces" ) ;
134132 const spacesSeenBy1 = Object . fromEntries (
135- data1 . filter ( ( gm ) => gm . id !== null ) . map ( ( gm ) => [ gm . id , gm ] ) ,
136- ) as Record < number , GroupSpaceInfo > ;
133+ data1 . filter ( ( gm ) => gm . space_id !== null ) . map ( ( gm ) => [ gm . space_id , gm ] ) ,
134+ ) as Record < number , PseudoAccountInfo > ;
137135 assert (
138136 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
139137 expectedSpaceIds . every ( ( id ) => spacesSeenBy1 [ id ] !== undefined ) ,
@@ -145,17 +143,15 @@ describe("list group members flow", { tags: ["database"] }, () => {
145143 ) ,
146144 ) ;
147145 // Step 4: user2 lists group members
148- const { data : data2 , error : error2 } = await client2 . rpc (
149- "spaces_in_group" ,
150- {
151- p_group_id : createdGroupId , // eslint-disable-line @typescript-eslint/naming-convention
152- } ,
153- ) ;
146+ const { data : data2 , error : error2 } = await client2
147+ . from ( "my_pseudo_accounts" )
148+ . select ( )
149+ . eq ( "group_id" , createdGroupId ) ;
154150 assert ( error2 === null , error2 ? error2 . message : "" ) ;
155151 assert ( data2 !== null , "group spaces should not be empty" ) ;
156152 assert ( data2 . length === 2 , "There should be two spaces" ) ;
157153 const spacesSeenBy2 = new Set (
158- data2 . map ( ( gm ) => gm . id ) . filter ( ( id ) => id !== null ) ,
154+ data2 . map ( ( gm ) => gm . space_id ) . filter ( ( id ) => id !== null ) ,
159155 ) ;
160156 assert (
161157 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
@@ -173,19 +169,19 @@ describe("list group members flow", { tags: ["database"] }, () => {
173169 } ) ;
174170 assert ( ! errorPublishSpace2 ) ;
175171 // Step 6: that space is now seen as published by 1.
176- const { data : data1b , error : error1b } = await client1 . rpc (
177- "spaces_in_group" ,
178- {
179- p_group_id : createdGroupId , // eslint-disable-line @typescript-eslint/naming-convention
180- } ,
181- ) ;
172+ const { data : data1b , error : error1b } = await client1
173+ . from ( "my_pseudo_accounts" )
174+ . select ( )
175+ . eq ( "group_id" , createdGroupId ) ;
182176
183177 assert ( error1b === null , error1b ? error1b . message : "" ) ;
184178 assert ( data1b !== null , "group spaces should not be empty" ) ;
185179 assert ( data1b . length === 2 , "There should be two spaces" ) ;
186180 const spacesSeenBy1b = Object . fromEntries (
187- data1b . filter ( ( gm ) => gm . id !== null ) . map ( ( gm ) => [ gm . id , gm ] ) ,
188- ) as Record < number , GroupSpaceInfo > ;
181+ data1b
182+ . filter ( ( gm ) => gm . space_id !== null )
183+ . map ( ( gm ) => [ gm . space_id , gm ] ) ,
184+ ) as Record < number , PseudoAccountInfo > ;
189185 assert (
190186 spacesSeenBy1b [ spaceId2 ] ?. sharing_permissions ,
191187 "Second space should now be seen as shared" ,
0 commit comments