Skip to content

Commit a0dac47

Browse files
committed
seed function
1 parent 1badc4b commit a0dac47

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

packages/rls-demo/__tests__/hello-world.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,29 @@ let user1: any;
99
let user2: any;
1010
let user3: any;
1111

12+
const users = [
13+
{
14+
id: '550e8400-e29b-41d4-a716-446655440001',
15+
16+
name: 'Tutorial User 1'
17+
},
18+
{
19+
id: '550e8400-e29b-41d4-a716-446655440002',
20+
21+
name: 'Tutorial User 2'
22+
},
23+
{
24+
id: '550e8400-e29b-41d4-a716-446655440003',
25+
26+
name: 'Tutorial User 3'
27+
}
28+
];
29+
1230
beforeAll(async () => {
1331
({ pg, db, teardown } = await getConnections());
14-
user1 = await insertUser(pg, '[email protected]');
15-
user2 = await insertUser(pg, '[email protected]');
16-
user3 = await insertUser(pg, '[email protected]');
32+
user1 = await insertUser(pg, users[0].email, users[0].id);
33+
user2 = await insertUser(pg, users[1].email, users[1].id);
34+
user3 = await insertUser(pg, users[2].email, users[2].id);
1735
});
1836

1937
afterAll(async () => {

packages/rls-demo/test-utils/index.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,26 @@ import { PgTestClient } from "supabase-test";
44
* Helper function to insert a new user into auth.users
55
* @param client - The PgTestClient to use (pg or db)
66
* @param email - The user's email address
7-
* @param options - Optional additional fields and return options
8-
* @returns The inserted user object
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
99
*/
1010
export async function insertUser(
1111
client: PgTestClient,
1212
email: string,
13-
options?: {
14-
id?: string;
15-
returnFields?: string[];
16-
}
17-
): Promise<{ id: string; email: string; [key: string]: any }> {
18-
const returnFields = options?.returnFields || ['id', 'email'];
19-
const fields = returnFields.join(', ');
20-
21-
if (options?.id) {
13+
id?: string
14+
): Promise<{ id: string; email: string }> {
15+
if (id) {
2216
return await client.one(
2317
`INSERT INTO auth.users (id, email)
2418
VALUES ($1, $2)
25-
RETURNING ${fields}`,
26-
[options.id, email]
19+
RETURNING id, email`,
20+
[id, email]
2721
);
2822
} else {
2923
return await client.one(
3024
`INSERT INTO auth.users (id, email)
3125
VALUES (gen_random_uuid(), $1)
32-
RETURNING ${fields}`,
26+
RETURNING id, email`,
3327
[email]
3428
);
3529
}

0 commit comments

Comments
 (0)