Skip to content

Commit 2f9871f

Browse files
committed
coderabbit suggestions
1 parent 3ff8429 commit 2f9871f

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Feature: Content access
22
User story:
3-
* As a user of the roam plugin
3+
* As a user of the Roam plugin
44
* Logged in through a given space's anonymous account
55
* I want to be able to access the content of that space
66
* In order to access the space information
@@ -12,18 +12,18 @@ Feature: Content access
1212

1313
Background:
1414
Given the database is blank
15-
And the user user1 opens the roam plugin in space s1
16-
And the user user2 opens the roam plugin in space s2
17-
And the user user3 opens the roam plugin in space s1
18-
And the user user3 opens the roam plugin in space s2
15+
And the user user1 opens the Roam plugin in space s1
16+
And the user user2 opens the Roam plugin in space s2
17+
And the user user3 opens the Roam plugin in space s1
18+
And the user user3 opens the Roam plugin in space s2
1919
And Document are added to the database:
2020
| @id | _space_id | source_local_id | _author_id | created | last_modified |
2121
| d1 | s1 | abc | user1 | 2025/01/01 | 2025/01/01 |
2222
| d2 | s1 | def | user2 | 2025/01/01 | 2025/01/01 |
2323
| d3 | s2 | ghi | user3 | 2025/01/01 | 2025/01/01 |
2424

2525
Scenario Outline: Per-space document access
26-
When the user user1 opens the roam plugin in space s1
26+
When the user user1 opens the Roam plugin in space s1
2727
Then the database should contain 3 Document
2828
And a user logged in space s2 should see 3 Document in the database
2929
And a user logged in space s1 should see 3 Document in the database

packages/database/features/getContext.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Feature: Get Context
22
User story:
3-
* As a user of the roam plugin
3+
* As a user of the Roam plugin
44
* I want to be able to create the Space, PlatformAccount, PlatformIdentity and SpaceAccess rows
55
* In order to access the space information
66

@@ -11,7 +11,7 @@ Feature: Get Context
1111
Given the database is blank
1212

1313
Scenario Outline: Calling the getContext steps
14-
When the user user1 opens the roam plugin in space abc
14+
When the user user1 opens the Roam plugin in space abc
1515
Then the database should contain 2 PlatformAccount
1616
And the database should contain 1 AgentIdentifier
1717
And the database should contain 2 SpaceAccess
@@ -22,7 +22,7 @@ Feature: Get Context
2222
And a user logged in space abc should see 2 PlatformAccount in the database
2323

2424
Scenario Outline: Calling getContext again
25-
When the user user1 opens the roam plugin in space abc
25+
When the user user1 opens the Roam plugin in space abc
2626
Then the database should contain 2 PlatformAccount
2727
And the database should contain 1 AgentIdentifier
2828
And the database should contain 2 SpaceAccess

packages/database/features/step_definitions/stepdefs.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
import assert from "assert";
22
import { Given, When, Then, world, type DataTable } from "@cucumber/cucumber";
33
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";
59
import { spaceAnonUserEmail } from "@repo/ui/lib/utils";
610
import {
711
fetchOrCreateSpaceId,
812
fetchOrCreatePlatformAccount,
913
} from "@repo/ui/lib/supabase/contextFunctions";
1014

1115
type Platform = Enums<"Platform">;
16+
const PLATFORMS: readonly Platform[] = Constants.public.Enums.Platform;
1217

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"]>(
1525
process.env.SUPABASE_URL!,
1626
process.env.SUPABASE_ANON_KEY!,
1727
);
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"]>(
2037
process.env.SUPABASE_URL!,
2138
process.env.SUPABASE_SERVICE_ROLE_KEY!,
2239
);
40+
};
2341

2442
const SPACE_ANONYMOUS_PASSWORD = "abcdefgh";
2543

@@ -94,19 +112,21 @@ Given(
94112
const userEmail = (userAccountId: string) => `${userAccountId}@example.com`;
95113

96114
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) => {
99117
// 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}`);
100120
const localRefs: Record<string, any> = world.localRefs || {};
101121
const spaceId = await fetchOrCreateSpaceId({
102122
password: SPACE_ANONYMOUS_PASSWORD,
103123
url: `https://roamresearch.com/#/app/${spaceName}`,
104124
name: spaceName,
105-
platform: "Roam",
125+
platform,
106126
});
107127
localRefs[spaceName] = spaceId;
108128
const userId = await fetchOrCreatePlatformAccount({
109-
platform: "Roam",
129+
platform,
110130
accountLocalId: userAccountId,
111131
name: userAccountId,
112132
email: userEmail(userAccountId),

packages/ui/src/lib/supabase/contextFunctions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const fetchOrCreateSpaceId = async (data: {
2424
});
2525
if (!response.ok)
2626
throw new Error(
27-
`Platform API failed: ${response.status} ${response.statusText} ${await response.text()}`,
27+
`Platform API failed: ${response.status} ${response.statusText}`,
2828
);
2929
const space = await response.json();
3030
if (typeof space.id !== "number") throw new Error("API did not return space");
@@ -71,6 +71,6 @@ export const fetchOrCreatePlatformAccount = async ({
7171
email_: email,
7272
});
7373

74-
if (result.error) throw Error(result.error.message); // account created but not connected, try again
74+
if (result.error) throw Error(result.error.message);
7575
return result.data;
7676
};

0 commit comments

Comments
 (0)