Skip to content

Commit 92db398

Browse files
committed
add insert user for supabase-test
1 parent 4f24223 commit 92db398

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { PgTestClient } from 'pgsql-test';
2+
3+
/**
4+
* Helper function to insert a new user into auth.users
5+
* @param client - The PgTestClient to use (pg or db)
6+
* @param email - The user's email address
7+
* @param id - Optional user ID (UUID). If not provided, a random UUID will be generated.
8+
* @returns The inserted user object with id and email
9+
*/
10+
export async function insertUser(
11+
client: PgTestClient,
12+
email: string,
13+
id?: string
14+
): Promise<{ id: string; email: string }> {
15+
if (id) {
16+
return await client.one(
17+
`INSERT INTO auth.users (id, email)
18+
VALUES ($1, $2)
19+
RETURNING id, email`,
20+
[id, email]
21+
);
22+
} else {
23+
return await client.one(
24+
`INSERT INTO auth.users (id, email)
25+
VALUES (gen_random_uuid(), $1)
26+
RETURNING id, email`,
27+
[email]
28+
);
29+
}
30+
}

packages/supabase-test/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Re-export everything from pgsql-test
22
export * from 'pgsql-test';
33

4+
// Re-export everything from helpers.ts
5+
export * from './helpers';
6+
47
// Export Supabase-specific getConnections with defaults baked in
58
export { getConnections } from './connect';
69
export type { GetConnectionOpts, GetConnectionResult } from './connect';

0 commit comments

Comments
 (0)