Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions apps/website/app/utils/supabase/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,10 @@ export const createGroupInvitation = async ({
.eq("member_id", userData.id)
.maybeSingle();
if (membershipReq.data?.admin !== true) return null;
/* eslint-disable @typescript-eslint/naming-convention */
const { data, error } = await client.rpc("create_secret_token", {
/* eslint-disable @typescript-eslint/naming-convention */
v_payload: { groupId, type: "groupInvitation", admin },
expiry_interval: "60d",
/* eslint-enable @typescript-eslint/naming-convention */
});
/* eslint-enable @typescript-eslint/naming-convention */
if (error || !data) return null;
return data;
};
Expand All @@ -114,12 +110,27 @@ export const acceptGroupInvitation = async (
export const createGroup = async (
client: DGSupabaseClient,
name: string,
): Promise<string | null> => {
): Promise<{ groupId: string | null; error: string | null }> => {
const result = await client.functions.invoke<{ group_id: string }>(
"create-group",
{ body: { name } },
);
return result.data?.group_id || null;
if (result.error) {
let message =
typeof result.error === "string"
? result.error
: (result.error as { message: string }).message;
try {
const body = (await (
result.error as { context?: Response }
).context?.json()) as { msg?: string } | undefined;
if (body?.msg) message = body.msg;
} catch {
// ignore parse errors
}
return { groupId: null, error: message };
}
return { groupId: result.data?.group_id ?? null, error: null };
};

export const removeFromGroup = async ({
Expand Down
6 changes: 5 additions & 1 deletion apps/website/test/integration/groupInvitation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ describe(

it("executes the full invitation flow", async () => {
// Step 1: user1 creates a group
const groupId = await createGroup(client1, "vitest-invite-group");
const { groupId, error: createError } = await createGroup(
client1,
"vitest-invite-group",
);
expect(createError, "createGroup should not error").toBeNull();
expect(groupId, "createGroup should return a group ID").toBeTruthy();
createdGroupId = groupId;

Expand Down
6 changes: 5 additions & 1 deletion apps/website/test/integration/leaveGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ describe("leave group flow", { tags: ["database"] }, () => {

it("lists group members", async () => {
// Step 1: user1 creates a group
const groupId = await createGroup(client1, "vitest-invite-group");
const { groupId, error: createError } = await createGroup(
client1,
"vitest-invite-group",
);
assert(createError === null, createError!);
assert(groupId !== null, "createGroup should return a group ID");
createdGroupId = groupId;

Expand Down
6 changes: 5 additions & 1 deletion apps/website/test/integration/listGroupMembers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ describe("list group members flow", { tags: ["database"] }, () => {

it("lists group members", async () => {
// Step 1: user1 creates a group
const groupId = await createGroup(client1, "vitest-invite-group");
const { groupId, error: createError } = await createGroup(
client1,
"vitest-invite-group",
);
assert(createError === null, createError!);
assert(groupId !== null, "createGroup should return a group ID");
createdGroupId = groupId;

Expand Down
6 changes: 5 additions & 1 deletion apps/website/test/integration/listMyGroups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ describe("list group members flow", { tags: ["database"] }, () => {

it("lists group members", async () => {
// Step 1: user1 creates a group
const groupId = await createGroup(client1, "vitest-invite-group");
const { groupId, error: createError } = await createGroup(
client1,
"vitest-invite-group",
);
assert(createError === null, createError!);
assert(groupId !== null, "createGroup should return a group ID");
createdGroupId = groupId;

Expand Down
Loading