|
1 | 1 | import assert from "assert"; |
2 | 2 | import { Given, When, Then, world, type DataTable } from "@cucumber/cucumber"; |
3 | 3 | import { createClient } from "@supabase/supabase-js"; |
4 | | -import type { Database, Enums } from "@repo/database/types.gen.ts"; |
| 4 | +import { |
| 5 | + Constants, |
| 6 | + type Database, |
| 7 | + type Enums, |
| 8 | +} from "@repo/database/types.gen.ts"; |
5 | 9 | import { spaceAnonUserEmail } from "@repo/ui/lib/utils"; |
6 | 10 | import { |
7 | 11 | fetchOrCreateSpaceId, |
8 | 12 | fetchOrCreatePlatformAccount, |
9 | 13 | } from "@repo/ui/lib/supabase/contextFunctions"; |
10 | 14 |
|
11 | 15 | type Platform = Enums<"Platform">; |
| 16 | +const PLATFORMS: readonly Platform[] = Constants.public.Enums.Platform; |
12 | 17 |
|
13 | | -const getAnonymousClient = () => |
14 | | - createClient<Database, "public", Database["public"]>( |
| 18 | +const getAnonymousClient = () => { |
| 19 | + if (!process.env.SUPABASE_URL || !process.env.SUPABASE_ANON_KEY) { |
| 20 | + throw new Error( |
| 21 | + "Missing required environment variables: SUPABASE_URL and SUPABASE_ANON_KEY", |
| 22 | + ); |
| 23 | + } |
| 24 | + return createClient<Database, "public", Database["public"]>( |
15 | 25 | process.env.SUPABASE_URL!, |
16 | 26 | process.env.SUPABASE_ANON_KEY!, |
17 | 27 | ); |
18 | | -const getServiceClient = () => |
19 | | - createClient<Database, "public", Database["public"]>( |
| 28 | +}; |
| 29 | + |
| 30 | +const getServiceClient = () => { |
| 31 | + if (!process.env.SUPABASE_URL || !process.env.SUPABASE_SERVICE_ROLE_KEY) { |
| 32 | + throw new Error( |
| 33 | + "Missing required environment variables: SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY", |
| 34 | + ); |
| 35 | + } |
| 36 | + return createClient<Database, "public", Database["public"]>( |
20 | 37 | process.env.SUPABASE_URL!, |
21 | 38 | process.env.SUPABASE_SERVICE_ROLE_KEY!, |
22 | 39 | ); |
| 40 | +}; |
23 | 41 |
|
24 | 42 | const SPACE_ANONYMOUS_PASSWORD = "abcdefgh"; |
25 | 43 |
|
@@ -94,19 +112,21 @@ Given( |
94 | 112 | const userEmail = (userAccountId: string) => `${userAccountId}@example.com`; |
95 | 113 |
|
96 | 114 | When( |
97 | | - "the user {word} opens the roam plugin in space {word}", |
98 | | - async (userAccountId, spaceName) => { |
| 115 | + "the user {word} opens the {word} plugin in space {word}", |
| 116 | + async (userAccountId, platform, spaceName) => { |
99 | 117 | // assumption: turbo dev is running. TODO: Make into hooks |
| 118 | + if (PLATFORMS.indexOf(platform) < 0) |
| 119 | + throw new Error(`Platform must be one of ${PLATFORMS}`); |
100 | 120 | const localRefs: Record<string, any> = world.localRefs || {}; |
101 | 121 | const spaceId = await fetchOrCreateSpaceId({ |
102 | 122 | password: SPACE_ANONYMOUS_PASSWORD, |
103 | 123 | url: `https://roamresearch.com/#/app/${spaceName}`, |
104 | 124 | name: spaceName, |
105 | | - platform: "Roam", |
| 125 | + platform, |
106 | 126 | }); |
107 | 127 | localRefs[spaceName] = spaceId; |
108 | 128 | const userId = await fetchOrCreatePlatformAccount({ |
109 | | - platform: "Roam", |
| 129 | + platform, |
110 | 130 | accountLocalId: userAccountId, |
111 | 131 | name: userAccountId, |
112 | 132 | email: userEmail(userAccountId), |
|
0 commit comments