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
22 changes: 22 additions & 0 deletions __tests__/spaces-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ describe("node-sdk spaces (lifecycle) — request shaping", () => {
});
});

it("createSpace forwards visibility in the body", async () => {
const { client, projectInstance } = makeClient();
await createSpace(client, {
userId: "u1",
name: "My Space",
visibility: "private",
});
expect(projectInstance.post).toHaveBeenCalledWith("/spaces", {
userId: "u1",
name: "My Space",
visibility: "private",
});
});

it("fetchManySpaces hits /spaces with the full body as params", async () => {
const { client, projectInstance } = makeClient();
await fetchManySpaces(client, { sortBy: "newest", page: 1 });
Expand Down Expand Up @@ -100,6 +114,14 @@ describe("node-sdk spaces (lifecycle) — request shaping", () => {
});
});

it("updateSpace forwards visibility in the body", async () => {
const { client, projectInstance } = makeClient();
await updateSpace(client, { spaceId: "s1", visibility: "unlisted" });
expect(projectInstance.patch).toHaveBeenCalledWith("/spaces/s1", {
visibility: "unlisted",
});
});

it("deleteSpace deletes /spaces/:id", async () => {
const { client, projectInstance } = makeClient();
await deleteSpace(client, { spaceId: "s1" });
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/Space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { File } from "./File";

export type ReadingPermission = "anyone" | "members";
export type PostingPermission = "anyone" | "members" | "admins";
export type SpaceVisibility = "public" | "unlisted" | "private";

export type SpaceMemberRole = "admin" | "moderator" | "member";
export type SpaceMemberStatus = "pending" | "active" | "banned" | "rejected";
Expand All @@ -24,6 +25,7 @@ export interface SpacePreview {
slug: string | null;
avatarFileId: string | null;
readingPermission?: ReadingPermission;
visibility?: SpaceVisibility;
parentSpaceId?: string | null;
depth?: number;
avatarFile?: File;
Expand All @@ -41,6 +43,7 @@ export interface Space {
userId: string;
readingPermission: ReadingPermission;
postingPermission: PostingPermission;
visibility: SpaceVisibility;
requireJoinApproval: boolean;
parentSpaceId: string | null;
depth: number;
Expand Down
8 changes: 7 additions & 1 deletion src/modules/spaces/createSpace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { SublayHttpClient } from "../../core/client";
import { Space, ReadingPermission, PostingPermission } from "../../interfaces/Space";
import {
Space,
ReadingPermission,
PostingPermission,
SpaceVisibility,
} from "../../interfaces/Space";

export interface CreateSpaceProps {
userId: string;
Expand All @@ -8,6 +13,7 @@ export interface CreateSpaceProps {
description?: string;
readingPermission?: ReadingPermission;
postingPermission?: PostingPermission;
visibility?: SpaceVisibility;
requireJoinApproval?: boolean;
parentSpaceId?: string;
metadata?: Record<string, any>;
Expand Down
8 changes: 7 additions & 1 deletion src/modules/spaces/updateSpace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { SublayHttpClient } from "../../core/client";
import { Space, ReadingPermission, PostingPermission } from "../../interfaces/Space";
import {
Space,
ReadingPermission,
PostingPermission,
SpaceVisibility,
} from "../../interfaces/Space";

export interface UpdateSpaceProps {
spaceId: string;
Expand All @@ -8,6 +13,7 @@ export interface UpdateSpaceProps {
description?: string;
readingPermission?: ReadingPermission;
postingPermission?: PostingPermission;
visibility?: SpaceVisibility;
metadata?: Record<string, any>;
}

Expand Down
Loading