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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "rsbuild dev --open",
"build": "rsbuild build",
"preview": "rsbuild preview",
"test": "RSTEST=1 rstest",
"typecheck": "tsc -p tsconfig.json --noEmit",
"prettier:check": "prettier --list-different .",
"prettier:fix": "prettier --write ."
Expand All @@ -29,6 +30,7 @@
"devDependencies": {
"@rsbuild/core": "^1.6.6",
"@rsbuild/plugin-react": "^1.4.2",
"@rstest/core": "^0.7.9",
"@tailwindcss/postcss": "^4.1.17",
"@types/react": "^19.2.5",
"@types/react-dom": "^19.2.3",
Expand Down
3 changes: 3 additions & 0 deletions rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { defineConfig } from "@rsbuild/core";
import { pluginReact } from "@rsbuild/plugin-react";

const isTest = process.env.RSTEST === "1";

export default defineConfig({
plugins: [pluginReact()],
server: {
...(isTest ? { host: "127.0.0.1", port: 0 } : {}),
proxy: {
"/api": {
target: process.env.API_PROXY_TARGET ?? "http://127.0.0.1:8788",
Expand Down
25 changes: 25 additions & 0 deletions rstest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { defineConfig } from "@rstest/core";
import type { RsbuildPlugin } from "@rsbuild/core";

const rstestServerPlugin = (): RsbuildPlugin => ({
name: "rstest:server-host",
setup(api) {
api.modifyRsbuildConfig((config) => {
config.server = {
...config.server,
host: "127.0.0.1",
port: 0,
strictPort: false,
middlewareMode: true,
};
return config;
});
},
});

export default defineConfig({
testMatch: ["tests/**/*.test.js"],
environment: "node",
browser: { enabled: false },
plugins: [rstestServerPlugin()],
});
141 changes: 141 additions & 0 deletions src/lib/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type {
ChamberProposalPageDto,
ChamberChatPeerDto,
ChamberChatSignalDto,
ChamberThreadDetailDto,
ChamberThreadDto,
ChamberThreadMessageDto,
ChamberChatMessageDto,
CourtCaseDetailDto,
FactionDto,
FormationProposalPageDto,
Expand Down Expand Up @@ -114,6 +120,60 @@ export async function apiChamber(id: string): Promise<GetChamberResponse> {
return await apiGet<GetChamberResponse>(`/api/chambers/${id}`);
}

export async function apiChamberThreads(
id: string,
): Promise<{ items: ChamberThreadDto[] }> {
return await apiGet<{ items: ChamberThreadDto[] }>(
`/api/chambers/${id}/threads`,
);
}

export async function apiChamberThreadDetail(
chamberId: string,
threadId: string,
): Promise<ChamberThreadDetailDto> {
return await apiGet<ChamberThreadDetailDto>(
`/api/chambers/${chamberId}/threads/${threadId}`,
);
}

export async function apiChamberChatSignalPost(
chamberId: string,
input: {
peerId: string;
kind: "offer" | "answer" | "candidate";
targetPeerId?: string;
payload: Record<string, unknown>;
},
): Promise<{ ok: true }> {
return await apiPost<{ ok: true }>(`/api/chambers/${chamberId}/chat/signal`, {
peerId: input.peerId,
kind: input.kind,
targetPeerId: input.targetPeerId,
payload: input.payload,
});
}

export async function apiChamberChatSignalPoll(
chamberId: string,
peerId: string,
): Promise<{ messages: ChamberChatSignalDto[] }> {
const qs = new URLSearchParams({ peerId });
return await apiGet<{ messages: ChamberChatSignalDto[] }>(
`/api/chambers/${chamberId}/chat/signal?${qs.toString()}`,
);
}

export async function apiChamberChatPresence(
chamberId: string,
peerId: string,
): Promise<{ peers: ChamberChatPeerDto[] }> {
const qs = new URLSearchParams({ peerId });
return await apiGet<{ peers: ChamberChatPeerDto[] }>(
`/api/chambers/${chamberId}/chat/presence?${qs.toString()}`,
);
}

export async function apiProposals(input?: {
stage?: string;
}): Promise<GetProposalsResponse> {
Expand Down Expand Up @@ -189,6 +249,87 @@ export async function apiChamberVote(input: {
);
}

export async function apiChamberThreadCreate(input: {
chamberId: string;
title: string;
body: string;
idempotencyKey?: string;
}): Promise<{
ok: true;
type: "chamber.thread.create";
thread: ChamberThreadDto;
}> {
return await apiPost(
"/api/command",
{
type: "chamber.thread.create",
payload: {
chamberId: input.chamberId,
title: input.title,
body: input.body,
},
idempotencyKey: input.idempotencyKey,
},
input.idempotencyKey
? { headers: { "idempotency-key": input.idempotencyKey } }
: undefined,
);
}

export async function apiChamberThreadReply(input: {
chamberId: string;
threadId: string;
body: string;
idempotencyKey?: string;
}): Promise<{
ok: true;
type: "chamber.thread.reply";
threadId: string;
message: ChamberThreadMessageDto;
replies: number;
}> {
return await apiPost(
"/api/command",
{
type: "chamber.thread.reply",
payload: {
chamberId: input.chamberId,
threadId: input.threadId,
body: input.body,
},
idempotencyKey: input.idempotencyKey,
},
input.idempotencyKey
? { headers: { "idempotency-key": input.idempotencyKey } }
: undefined,
);
}

export async function apiChamberChatPost(input: {
chamberId: string;
message: string;
idempotencyKey?: string;
}): Promise<{
ok: true;
type: "chamber.chat.post";
message: ChamberChatMessageDto;
}> {
return await apiPost(
"/api/command",
{
type: "chamber.chat.post",
payload: {
chamberId: input.chamberId,
message: input.message,
},
idempotencyKey: input.idempotencyKey,
},
input.idempotencyKey
? { headers: { "idempotency-key": input.idempotencyKey } }
: undefined,
);
}

export async function apiFormationJoin(input: {
proposalId: string;
role?: string;
Expand Down
Loading