Skip to content

Commit 3843ceb

Browse files
committed
add the database tag to the test
1 parent 7d1742b commit 3843ceb

1 file changed

Lines changed: 85 additions & 78 deletions

File tree

apps/website/test/integration/group-invitation.test.ts

Lines changed: 85 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -34,90 +34,97 @@ const signedInClient = async (spaceId: number): Promise<DGSupabaseClient> => {
3434
return client;
3535
};
3636

37-
describe("group invitation flow (website functions)", () => {
38-
let spaceId1: number;
39-
let spaceId2: number;
40-
let client1: DGSupabaseClient;
41-
let client2: DGSupabaseClient;
42-
let createdGroupId: string | null = null;
37+
describe(
38+
"group invitation flow (website functions)",
39+
{ tags: ["database"] },
40+
() => {
41+
let spaceId1: number;
42+
let spaceId2: number;
43+
let client1: DGSupabaseClient;
44+
let client2: DGSupabaseClient;
45+
let createdGroupId: string | null = null;
4346

44-
beforeAll(async () => {
45-
const s1 = await fetchOrCreateSpaceDirect({
46-
name: "vitest-s1",
47-
url: "https://roamresearch.com/#/app/vitest-s1",
48-
platform: "Roam",
49-
password: PASSWORD,
50-
});
51-
if (!s1.data)
52-
throw new Error(`Failed to create space 1: ${s1.error?.message}`);
53-
spaceId1 = s1.data.id;
54-
await fetchOrCreatePlatformAccount({
55-
platform: "Roam",
56-
accountLocalId: "vitest-user1",
57-
name: "vitest-user1",
58-
email: "vitest-user1@example.com",
59-
spaceId: spaceId1,
60-
password: PASSWORD,
61-
});
47+
beforeAll(async () => {
48+
const s1 = await fetchOrCreateSpaceDirect({
49+
name: "vitest-s1",
50+
url: "https://roamresearch.com/#/app/vitest-s1",
51+
platform: "Roam",
52+
password: PASSWORD,
53+
});
54+
if (!s1.data)
55+
throw new Error(`Failed to create space 1: ${s1.error?.message}`);
56+
spaceId1 = s1.data.id;
57+
await fetchOrCreatePlatformAccount({
58+
platform: "Roam",
59+
accountLocalId: "vitest-user1",
60+
name: "vitest-user1",
61+
email: "vitest-user1@example.com",
62+
spaceId: spaceId1,
63+
password: PASSWORD,
64+
});
65+
66+
const s2 = await fetchOrCreateSpaceDirect({
67+
name: "vitest-s2",
68+
url: "https://roamresearch.com/#/app/vitest-s2",
69+
platform: "Roam",
70+
password: PASSWORD,
71+
});
72+
if (!s2.data)
73+
throw new Error(`Failed to create space 2: ${s2.error?.message}`);
74+
spaceId2 = s2.data.id;
75+
await fetchOrCreatePlatformAccount({
76+
platform: "Roam",
77+
accountLocalId: "vitest-user2",
78+
name: "vitest-user2",
79+
email: "vitest-user2@example.com",
80+
spaceId: spaceId2,
81+
password: PASSWORD,
82+
});
6283

63-
const s2 = await fetchOrCreateSpaceDirect({
64-
name: "vitest-s2",
65-
url: "https://roamresearch.com/#/app/vitest-s2",
66-
platform: "Roam",
67-
password: PASSWORD,
84+
client1 = await signedInClient(spaceId1);
85+
client2 = await signedInClient(spaceId2);
6886
});
69-
if (!s2.data)
70-
throw new Error(`Failed to create space 2: ${s2.error?.message}`);
71-
spaceId2 = s2.data.id;
72-
await fetchOrCreatePlatformAccount({
73-
platform: "Roam",
74-
accountLocalId: "vitest-user2",
75-
name: "vitest-user2",
76-
email: "vitest-user2@example.com",
77-
spaceId: spaceId2,
78-
password: PASSWORD,
87+
88+
afterAll(async () => {
89+
if (createdGroupId) {
90+
await serviceClient().auth.admin.deleteUser(createdGroupId);
91+
}
7992
});
8093

81-
client1 = await signedInClient(spaceId1);
82-
client2 = await signedInClient(spaceId2);
83-
});
94+
it("executes the full invitation flow", async () => {
95+
// Step 1: user1 creates a group
96+
const groupId = await createGroup(client1, "vitest-invite-group");
97+
expect(groupId, "createGroup should return a group ID").toBeTruthy();
98+
createdGroupId = groupId;
8499

85-
afterAll(async () => {
86-
if (createdGroupId) {
87-
await serviceClient().auth.admin.deleteUser(createdGroupId);
88-
}
89-
});
100+
// Step 2: user1 creates an invitation token
101+
const token = await createGroupInvitation({
102+
client: client1,
103+
groupId: groupId!,
104+
admin: false,
105+
});
106+
expect(token, "createGroupInvitation should return a token").toBeTruthy();
90107

91-
it("executes the full invitation flow", async () => {
92-
// Step 1: user1 creates a group
93-
const groupId = await createGroup(client1, "vitest-invite-group");
94-
expect(groupId, "createGroup should return a group ID").toBeTruthy();
95-
createdGroupId = groupId;
108+
// Step 3: user2 accepts the invitation
109+
const error = await acceptGroupInvitation(client2, token!);
110+
expect(
111+
error,
112+
"acceptGroupInvitation should return null on success",
113+
).toBeNull();
96114

97-
// Step 2: user1 creates an invitation token
98-
const token = await createGroupInvitation({
99-
client: client1,
100-
groupId: groupId!,
101-
admin: false,
115+
// Step 4: verify user2 is in group_membership
116+
const { data: user2 } = await client2.auth.getUser();
117+
const { data: membership } = await serviceClient()
118+
.from("group_membership")
119+
.select("admin")
120+
.eq("group_id", groupId!)
121+
.eq("member_id", user2.user!.id)
122+
.maybeSingle();
123+
expect(
124+
membership,
125+
"user2 should appear in group_membership",
126+
).toBeTruthy();
127+
expect(membership?.admin).toBe(false);
102128
});
103-
expect(token, "createGroupInvitation should return a token").toBeTruthy();
104-
105-
// Step 3: user2 accepts the invitation
106-
const error = await acceptGroupInvitation(client2, token!);
107-
expect(
108-
error,
109-
"acceptGroupInvitation should return null on success",
110-
).toBeNull();
111-
112-
// Step 4: verify user2 is in group_membership
113-
const { data: user2 } = await client2.auth.getUser();
114-
const { data: membership } = await serviceClient()
115-
.from("group_membership")
116-
.select("admin")
117-
.eq("group_id", groupId!)
118-
.eq("member_id", user2.user!.id)
119-
.maybeSingle();
120-
expect(membership, "user2 should appear in group_membership").toBeTruthy();
121-
expect(membership?.admin).toBe(false);
122-
});
123-
});
129+
},
130+
);

0 commit comments

Comments
 (0)