The Coline App SDK: apps, tools, file types and surfaces that run inside Coline workspaces, and public websites with Coline Sites. TypeScript, with an in-memory test workspace. MIT.
| 4 |
| 5 | function jsonResponse(payload: unknown, status = 200): Response { |
| 6 | return new Response(JSON.stringify(payload), { |
| 7 | status, |
| 8 | headers: { "Content-Type": "application/json" }, |
| 9 | }); |
| 10 | } |
| 11 |
| 12 | function mockClient(fetchMock: ReturnType<typeof vi.fn>) { |
| 13 | return new ColineApiClient({ |
| 14 | baseUrl: "https://api.coline.app", |
| 15 | apiKey: "col_ws_test_key", |
| 16 | fetch: fetchMock as typeof globalThis.fetch, |
| 17 | }); |
| 18 | } |
| 19 |
| 20 | function expectUrl(fetchMock: ReturnType<typeof vi.fn>, callIndex: number, expected: string) { |
| 21 | const arg0 = fetchMock.mock.calls[callIndex]?.[0]; |
| 22 | const url = typeof arg0 === "string" ? arg0 : (arg0 as Request).url; |
| 23 | expect(url).toBe(expected); |
| 24 | } |
| 25 |
| 26 | function expectMethod(fetchMock: ReturnType<typeof vi.fn>, callIndex: number, expected: string) { |
| 27 | const arg0 = fetchMock.mock.calls[callIndex]?.[0]; |
| 28 | const arg1 = fetchMock.mock.calls[callIndex]?.[1] as RequestInit | undefined; |
| 29 | // coreRequest passes (url_string, requestInit), openapi-fetch passes (Request) |
| 30 | const method = typeof arg0 === "string" ? arg1?.method : (arg0 as Request).method; |
| 31 | expect(method).toBe(expected); |
| 32 | } |
| 33 |
| 34 | function getRequestHeaders(fetchMock: ReturnType<typeof vi.fn>, callIndex: number): Headers { |
| 35 | const arg0 = fetchMock.mock.calls[callIndex]?.[0]; |
| 36 | const arg1 = fetchMock.mock.calls[callIndex]?.[1] as RequestInit | undefined; |
| 37 | if (typeof arg0 === "string") { |
| 38 | return new Headers(arg1?.headers as HeadersInit); |
| 39 | } |
| 40 | return new Headers((arg0 as Request).headers); |
| 41 | } |
| 42 |
| 43 | // --------------------------------------------------------------------------- |
| 44 | // Notes |
| 45 | // --------------------------------------------------------------------------- |
| 46 |
| 47 | describe("Notes API", () => { |
| 48 | it("lists workspace notes with query params", async () => { |
| 49 | const fetchMock = vi.fn().mockResolvedValue( |
| 50 | jsonResponse({ data: { notes: [], cursor: null } }), |
| 51 | ); |
| 52 | const client = mockClient(fetchMock); |
| 53 |
| 54 | await client.listWorkspaceNotes("ws_123", { q: "roadmap", limit: 10 }); |
| 55 |
| 56 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/notes?q=roadmap&limit=10"); |
| 57 | expectMethod(fetchMock, 0, "GET"); |
| 58 | }); |
| 59 |
| 60 | it("creates a note with title and body", async () => { |
| 61 | const fetchMock = vi.fn().mockResolvedValue( |
| 62 | jsonResponse({ |
| 63 | data: { |
| 64 | note: { id: "note_1", title: "Roadmap", body: "Q3 goals" }, |
| 65 | }, |
| 66 | }), |
| 67 | ); |
| 68 | const client = mockClient(fetchMock); |
| 69 |
| 70 | const result = await client.createWorkspaceNote("ws_123", { |
| 71 | title: "Roadmap", |
| 72 | body: "Q3 goals", |
| 73 | }); |
| 74 |
| 75 | expect(result.note.id).toBe("note_1"); |
| 76 | expectMethod(fetchMock, 0, "POST"); |
| 77 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/notes"); |
| 78 | }); |
| 79 |
| 80 | it("gets a single note", async () => { |
| 81 | const fetchMock = vi.fn().mockResolvedValue( |
| 82 | jsonResponse({ |
| 83 | data: { note: { id: "note_1" }, body: "content" }, |
| 84 | }), |
| 85 | ); |
| 86 | const client = mockClient(fetchMock); |
| 87 |
| 88 | await client.getWorkspaceNote("ws_123", "note_1"); |
| 89 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/notes/note_1"); |
| 90 | }); |
| 91 |
| 92 | it("updates a note", async () => { |
| 93 | const fetchMock = vi.fn().mockResolvedValue( |
| 94 | jsonResponse({ data: { note: { id: "note_1", title: "Updated" } } }), |
| 95 | ); |
| 96 | const client = mockClient(fetchMock); |
| 97 |
| 98 | await client.updateWorkspaceNote("ws_123", "note_1", { title: "Updated" }); |
| 99 | expectMethod(fetchMock, 0, "PUT"); |
| 100 | }); |
| 101 |
| 102 | it("deletes a note", async () => { |
| 103 | const fetchMock = vi.fn().mockResolvedValue( |
| 104 | jsonResponse({ data: { ok: true } }), |
| 105 | ); |
| 106 | const client = mockClient(fetchMock); |
| 107 |
| 108 | const result = await client.deleteWorkspaceNote("ws_123", "note_1"); |
| 109 | expect(result.ok).toBe(true); |
| 110 | expectMethod(fetchMock, 0, "DELETE"); |
| 111 | }); |
| 112 | }); |
| 113 |
| 114 | // --------------------------------------------------------------------------- |
| 115 | // Docs |
| 116 | // --------------------------------------------------------------------------- |
| 117 |
| 118 | describe("Docs API", () => { |
| 119 | it("lists workspace docs with search", async () => { |
| 120 | const fetchMock = vi.fn().mockResolvedValue( |
| 121 | jsonResponse({ data: { docs: [], cursor: null } }), |
| 122 | ); |
| 123 | const client = mockClient(fetchMock); |
| 124 |
| 125 | await client.listWorkspaceDocs("ws_123", { q: "api", limit: 5 }); |
| 126 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/docs?q=api&limit=5"); |
| 127 | }); |
| 128 |
| 129 | it("creates a doc with content and layout", async () => { |
| 130 | const fetchMock = vi.fn().mockResolvedValue( |
| 131 | jsonResponse({ |
| 132 | data: { doc: { id: "doc_1", title: "API Guide" } }, |
| 133 | }), |
| 134 | ); |
| 135 | const client = mockClient(fetchMock); |
| 136 |
| 137 | await client.createWorkspaceDoc("ws_123", { |
| 138 | title: "API Guide", |
| 139 | content: { type: "doc", content: [] }, |
| 140 | }); |
| 141 |
| 142 | expectMethod(fetchMock, 0, "POST"); |
| 143 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/docs"); |
| 144 | }); |
| 145 |
| 146 | it("gets, updates, and deletes a doc", async () => { |
| 147 | const fetchMock = vi |
| 148 | .fn() |
| 149 | .mockResolvedValueOnce(jsonResponse({ data: { doc: { id: "doc_1" } } })) |
| 150 | .mockResolvedValueOnce(jsonResponse({ data: { doc: { id: "doc_1", title: "New" } } })) |
| 151 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true } })); |
| 152 |
| 153 | const client = mockClient(fetchMock); |
| 154 |
| 155 | await client.getWorkspaceDoc("ws_123", "doc_1"); |
| 156 | await client.updateWorkspaceDoc("ws_123", "doc_1", { title: "New" }); |
| 157 | await client.deleteWorkspaceDoc("ws_123", "doc_1"); |
| 158 |
| 159 | expectMethod(fetchMock, 0, "GET"); |
| 160 | expectMethod(fetchMock, 1, "PATCH"); |
| 161 | expectMethod(fetchMock, 2, "DELETE"); |
| 162 | }); |
| 163 | }); |
| 164 |
| 165 | // --------------------------------------------------------------------------- |
| 166 | // Channels & Messages |
| 167 | // --------------------------------------------------------------------------- |
| 168 |
| 169 | describe("Channels & Messages API", () => { |
| 170 | it("lists workspace channels", async () => { |
| 171 | const fetchMock = vi.fn().mockResolvedValue( |
| 172 | jsonResponse({ data: { channels: [] } }), |
| 173 | ); |
| 174 | const client = mockClient(fetchMock); |
| 175 |
| 176 | await client.listWorkspaceChannels("ws_123"); |
| 177 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/channels"); |
| 178 | }); |
| 179 |
| 180 | it("lists channel messages with pagination", async () => { |
| 181 | const fetchMock = vi.fn().mockResolvedValue( |
| 182 | jsonResponse({ data: { messages: [], cursor: null } }), |
| 183 | ); |
| 184 | const client = mockClient(fetchMock); |
| 185 |
| 186 | await client.listChannelMessages("ws_123", "ch_1", { limit: 25 }); |
| 187 | expectUrl( |
| 188 | fetchMock, |
| 189 | 0, |
| 190 | "https://api.coline.app/api/v1/workspaces/ws_123/channels/ch_1/messages?limit=25", |
| 191 | ); |
| 192 | }); |
| 193 |
| 194 | it("sends a channel message", async () => { |
| 195 | const fetchMock = vi.fn().mockResolvedValue( |
| 196 | jsonResponse({ data: { message: { id: "msg_1" } } }), |
| 197 | ); |
| 198 | const client = mockClient(fetchMock); |
| 199 |
| 200 | await client.sendChannelMessage("ws_123", "ch_1", { content: [{ type: "text", text: "Hello" }] }); |
| 201 | expectMethod(fetchMock, 0, "POST"); |
| 202 | }); |
| 203 |
| 204 | it("gets, edits, and deletes a message", async () => { |
| 205 | const fetchMock = vi |
| 206 | .fn() |
| 207 | .mockResolvedValueOnce(jsonResponse({ data: { message: { id: "msg_1" } } })) |
| 208 | .mockResolvedValueOnce(jsonResponse({ data: { message: { id: "msg_1", plaintext: "Updated" } } })) |
| 209 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true } })); |
| 210 |
| 211 | const client = mockClient(fetchMock); |
| 212 |
| 213 | await client.getMessage("ws_123", "msg_1"); |
| 214 | await client.editMessage("ws_123", "msg_1", { content: [{ type: "text", text: "Updated" }] }); |
| 215 | await client.deleteMessage("ws_123", "msg_1"); |
| 216 |
| 217 | expectMethod(fetchMock, 0, "GET"); |
| 218 | expectMethod(fetchMock, 1, "PATCH"); |
| 219 | expectMethod(fetchMock, 2, "DELETE"); |
| 220 | }); |
| 221 |
| 222 | it("manages threads (get + reply)", async () => { |
| 223 | const fetchMock = vi |
| 224 | .fn() |
| 225 | .mockResolvedValueOnce(jsonResponse({ data: { thread: { id: "msg_1" }, replies: [] } })) |
| 226 | .mockResolvedValueOnce(jsonResponse({ data: { message: { id: "msg_2" } } })); |
| 227 |
| 228 | const client = mockClient(fetchMock); |
| 229 |
| 230 | await client.getThread("ws_123", "msg_1"); |
| 231 | await client.replyToThread("ws_123", "msg_1", { content: [{ type: "text", text: "Reply" }] }); |
| 232 |
| 233 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/messages/msg_1/thread"); |
| 234 | expectMethod(fetchMock, 1, "POST"); |
| 235 | }); |
| 236 |
| 237 | it("adds and removes reactions", async () => { |
| 238 | const fetchMock = vi |
| 239 | .fn() |
| 240 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true, emoji: "👍" } })) |
| 241 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true } })); |
| 242 |
| 243 | const client = mockClient(fetchMock); |
| 244 |
| 245 | await client.addReaction("ws_123", "msg_1", "👍"); |
| 246 | await client.removeReaction("ws_123", "msg_1", "👍"); |
| 247 |
| 248 | expectMethod(fetchMock, 0, "PUT"); |
| 249 | expectMethod(fetchMock, 1, "DELETE"); |
| 250 | expectUrl( |
| 251 | fetchMock, |
| 252 | 0, |
| 253 | "https://api.coline.app/api/v1/workspaces/ws_123/messages/msg_1/reactions/%F0%9F%91%8D", |
| 254 | ); |
| 255 | }); |
| 256 |
| 257 | it("pins and unpins messages", async () => { |
| 258 | const fetchMock = vi |
| 259 | .fn() |
| 260 | .mockResolvedValueOnce(jsonResponse({ data: { pinned: true } })) |
| 261 | .mockResolvedValueOnce(jsonResponse({ data: { pinned: false } })); |
| 262 |
| 263 | const client = mockClient(fetchMock); |
| 264 |
| 265 | await client.pinMessage("ws_123", "msg_1"); |
| 266 | await client.unpinMessage("ws_123", "msg_1"); |
| 267 |
| 268 | expectMethod(fetchMock, 0, "PUT"); |
| 269 | expectMethod(fetchMock, 1, "DELETE"); |
| 270 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/messages/msg_1/pin"); |
| 271 | }); |
| 272 | }); |
| 273 |
| 274 | // --------------------------------------------------------------------------- |
| 275 | // Direct Messages |
| 276 | // --------------------------------------------------------------------------- |
| 277 |
| 278 | describe("DMs API", () => { |
| 279 | it("lists DMs and DM messages", async () => { |
| 280 | const fetchMock = vi |
| 281 | .fn() |
| 282 | .mockResolvedValueOnce(jsonResponse({ data: { dms: [] } })) |
| 283 | .mockResolvedValueOnce(jsonResponse({ data: { messages: [], cursor: null } })); |
| 284 |
| 285 | const client = mockClient(fetchMock); |
| 286 |
| 287 | await client.listWorkspaceDms("ws_123"); |
| 288 | await client.listDmMessages("ws_123", "dm_1", { limit: 10, cursor: "abc" }); |
| 289 |
| 290 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/dms"); |
| 291 | expectUrl(fetchMock, 1, "https://api.coline.app/api/v1/workspaces/ws_123/dms/dm_1/messages?limit=10&cursor=abc"); |
| 292 | }); |
| 293 |
| 294 | it("sends a DM", async () => { |
| 295 | const fetchMock = vi.fn().mockResolvedValue( |
| 296 | jsonResponse({ data: { message: { id: "msg_1" } } }), |
| 297 | ); |
| 298 | const client = mockClient(fetchMock); |
| 299 |
| 300 | await client.sendDmMessage("ws_123", "dm_1", { content: [{ type: "text", text: "Hey" }] }); |
| 301 | expectMethod(fetchMock, 0, "POST"); |
| 302 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/dms/dm_1/messages"); |
| 303 | }); |
| 304 | }); |
| 305 |
| 306 | // --------------------------------------------------------------------------- |
| 307 | // Calendar Events |
| 308 | // --------------------------------------------------------------------------- |
| 309 |
| 310 | describe("Calendar API", () => { |
| 311 | it("lists calendar events in a date range", async () => { |
| 312 | const fetchMock = vi.fn().mockResolvedValue( |
| 313 | jsonResponse({ data: { events: [] } }), |
| 314 | ); |
| 315 | const client = mockClient(fetchMock); |
| 316 |
| 317 | await client.listCalendarEvents("ws_123", { |
| 318 | start: "2026-04-01T00:00:00Z", |
| 319 | end: "2026-04-30T23:59:59Z", |
| 320 | }); |
| 321 |
| 322 | expectUrl( |
| 323 | fetchMock, |
| 324 | 0, |
| 325 | "https://api.coline.app/api/v1/workspaces/ws_123/calendar/events?start=2026-04-01T00%3A00%3A00Z&end=2026-04-30T23%3A59%3A59Z", |
| 326 | ); |
| 327 | }); |
| 328 |
| 329 | it("creates a calendar event", async () => { |
| 330 | const fetchMock = vi.fn().mockResolvedValue( |
| 331 | jsonResponse({ data: { event: { id: "evt_1", title: "Standup" } } }), |
| 332 | ); |
| 333 | const client = mockClient(fetchMock); |
| 334 |
| 335 | await client.createCalendarEvent("ws_123", { |
| 336 | title: "Standup", |
| 337 | startsAt: "2026-04-05T09:00:00Z", |
| 338 | endsAt: "2026-04-05T09:30:00Z", |
| 339 | timeZone: "America/New_York", |
| 340 | }); |
| 341 |
| 342 | expectMethod(fetchMock, 0, "POST"); |
| 343 | }); |
| 344 |
| 345 | it("gets, updates, and deletes a calendar event", async () => { |
| 346 | const fetchMock = vi |
| 347 | .fn() |
| 348 | .mockResolvedValueOnce(jsonResponse({ data: { event: { id: "evt_1" } } })) |
| 349 | .mockResolvedValueOnce(jsonResponse({ data: { event: { id: "evt_1", title: "Updated" } } })) |
| 350 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true } })); |
| 351 |
| 352 | const client = mockClient(fetchMock); |
| 353 |
| 354 | await client.getCalendarEvent("ws_123", "evt_1"); |
| 355 | await client.updateCalendarEvent("ws_123", "evt_1", { title: "Updated" }); |
| 356 | await client.deleteCalendarEvent("ws_123", "evt_1"); |
| 357 |
| 358 | expectMethod(fetchMock, 0, "GET"); |
| 359 | expectMethod(fetchMock, 1, "PATCH"); |
| 360 | expectMethod(fetchMock, 2, "DELETE"); |
| 361 | }); |
| 362 | }); |
| 363 |
| 364 | // --------------------------------------------------------------------------- |
| 365 | // Search |
| 366 | // --------------------------------------------------------------------------- |
| 367 |
| 368 | describe("Search API", () => { |
| 369 | it("searches a workspace", async () => { |
| 370 | const fetchMock = vi.fn().mockResolvedValue( |
| 371 | jsonResponse({ data: { results: [], total: 0 } }), |
| 372 | ); |
| 373 | const client = mockClient(fetchMock); |
| 374 |
| 375 | await client.searchWorkspace("ws_123", { query: "onboarding" }); |
| 376 |
| 377 | expectMethod(fetchMock, 0, "POST"); |
| 378 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/search"); |
| 379 | }); |
| 380 | }); |
| 381 |
| 382 | // --------------------------------------------------------------------------- |
| 383 | // Drives & Files |
| 384 | // --------------------------------------------------------------------------- |
| 385 |
| 386 | describe("Drives & Files API", () => { |
| 387 | it("lists workspace drives", async () => { |
| 388 | const fetchMock = vi.fn().mockResolvedValue( |
| 389 | jsonResponse({ data: { drives: [] } }), |
| 390 | ); |
| 391 | const client = mockClient(fetchMock); |
| 392 |
| 393 | await client.listWorkspaceDrives("ws_123"); |
| 394 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/drives"); |
| 395 | }); |
| 396 |
| 397 | it("lists drive files with filters", async () => { |
| 398 | const fetchMock = vi.fn().mockResolvedValue( |
| 399 | jsonResponse({ data: { files: [], cursor: null } }), |
| 400 | ); |
| 401 | const client = mockClient(fetchMock); |
| 402 |
| 403 | await client.listDriveFiles("ws_123", "drive_1", { |
| 404 | fileType: ".note", |
| 405 | trashed: false, |
| 406 | limit: 20, |
| 407 | }); |
| 408 |
| 409 | expectUrl( |
| 410 | fetchMock, |
| 411 | 0, |
| 412 | "https://api.coline.app/api/v1/workspaces/ws_123/drives/drive_1/files?fileType=.note&trashed=false&limit=20", |
| 413 | ); |
| 414 | }); |
| 415 |
| 416 | it("gets, updates, and deletes a file", async () => { |
| 417 | const fetchMock = vi |
| 418 | .fn() |
| 419 | .mockResolvedValueOnce(jsonResponse({ data: { file: { id: "file_1" } } })) |
| 420 | .mockResolvedValueOnce(jsonResponse({ data: { file: { id: "file_1", name: "renamed" } } })) |
| 421 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true } })); |
| 422 |
| 423 | const client = mockClient(fetchMock); |
| 424 |
| 425 | await client.getFile("ws_123", "file_1"); |
| 426 | await client.updateFile("ws_123", "file_1", { name: "renamed" }); |
| 427 | await client.deleteFile("ws_123", "file_1"); |
| 428 |
| 429 | expectMethod(fetchMock, 0, "GET"); |
| 430 | expectMethod(fetchMock, 1, "PATCH"); |
| 431 | expectMethod(fetchMock, 2, "DELETE"); |
| 432 | }); |
| 433 | }); |
| 434 |
| 435 | // --------------------------------------------------------------------------- |
| 436 | // Taskboards & Tasks |
| 437 | // --------------------------------------------------------------------------- |
| 438 |
| 439 | describe("Taskboards & Tasks API", () => { |
| 440 | it("lists workspace taskboards", async () => { |
| 441 | const fetchMock = vi.fn().mockResolvedValue( |
| 442 | jsonResponse({ data: { taskboards: [] } }), |
| 443 | ); |
| 444 | const client = mockClient(fetchMock); |
| 445 |
| 446 | await client.listWorkspaceTaskboards("ws_123"); |
| 447 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/taskboards"); |
| 448 | }); |
| 449 |
| 450 | it("lists tasks with filters", async () => { |
| 451 | const fetchMock = vi.fn().mockResolvedValue( |
| 452 | jsonResponse({ data: { tasks: [] } }), |
| 453 | ); |
| 454 | const client = mockClient(fetchMock); |
| 455 |
| 456 | await client.listTaskboardTasks("ws_123", "board_1", { |
| 457 | q: "bug", |
| 458 | statusId: "status_1", |
| 459 | assigneeUserId: "user_1", |
| 460 | limit: 50, |
| 461 | }); |
| 462 |
| 463 | expectUrl( |
| 464 | fetchMock, |
| 465 | 0, |
| 466 | "https://api.coline.app/api/v1/workspaces/ws_123/taskboards/board_1/tasks?q=bug&statusId=status_1&assigneeUserId=user_1&limit=50", |
| 467 | ); |
| 468 | }); |
| 469 |
| 470 | it("creates a task", async () => { |
| 471 | const fetchMock = vi.fn().mockResolvedValue( |
| 472 | jsonResponse({ data: { task: { id: "task_1", title: "Fix bug" } } }), |
| 473 | ); |
| 474 | const client = mockClient(fetchMock); |
| 475 |
| 476 | await client.createTaskboardTask("ws_123", "board_1", { |
| 477 | title: "Fix bug", |
| 478 | priority: "high", |
| 479 | }); |
| 480 |
| 481 | expectMethod(fetchMock, 0, "POST"); |
| 482 | }); |
| 483 |
| 484 | it("updates and deletes a task", async () => { |
| 485 | const fetchMock = vi |
| 486 | .fn() |
| 487 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true } })) |
| 488 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true } })); |
| 489 |
| 490 | const client = mockClient(fetchMock); |
| 491 |
| 492 | await client.updateTaskboardTask("ws_123", "board_1", "task_1", { |
| 493 | title: "Fixed bug", |
| 494 | priority: "low", |
| 495 | }); |
| 496 | await client.deleteTaskboardTask("ws_123", "board_1", "task_1"); |
| 497 |
| 498 | expectMethod(fetchMock, 0, "PATCH"); |
| 499 | expectMethod(fetchMock, 1, "DELETE"); |
| 500 | expectUrl( |
| 501 | fetchMock, |
| 502 | 0, |
| 503 | "https://api.coline.app/api/v1/workspaces/ws_123/taskboards/board_1/tasks/task_1", |
| 504 | ); |
| 505 | }); |
| 506 |
| 507 | it("batch creates tasks", async () => { |
| 508 | const fetchMock = vi |
| 509 | .fn() |
| 510 | .mockResolvedValueOnce(jsonResponse({ data: { task: { id: "task_1" } } })) |
| 511 | .mockResolvedValueOnce(jsonResponse({ data: { task: { id: "task_2" } } })); |
| 512 |
| 513 | const client = mockClient(fetchMock); |
| 514 |
| 515 | const results = await client.batchCreateTasks("ws_123", "board_1", [ |
| 516 | { title: "Task A" }, |
| 517 | { title: "Task B" }, |
| 518 | ]); |
| 519 |
| 520 | expect(results).toHaveLength(2); |
| 521 | expect(results[0]?.status).toBe("fulfilled"); |
| 522 | expect(results[1]?.status).toBe("fulfilled"); |
| 523 | }); |
| 524 |
| 525 | it("batch updates tasks", async () => { |
| 526 | const fetchMock = vi |
| 527 | .fn() |
| 528 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true } })) |
| 529 | .mockResolvedValueOnce( |
| 530 | jsonResponse({ error: { code: "NOT_FOUND", message: "Not found" } }, 404), |
| 531 | ); |
| 532 |
| 533 | const client = mockClient(fetchMock); |
| 534 |
| 535 | const results = await client.batchUpdateTasks("ws_123", "board_1", [ |
| 536 | { taskId: "task_1", title: "Updated" }, |
| 537 | { taskId: "task_999", title: "Missing" }, |
| 538 | ]); |
| 539 |
| 540 | expect(results[0]?.status).toBe("fulfilled"); |
| 541 | expect(results[1]?.status).toBe("rejected"); |
| 542 | }); |
| 543 |
| 544 | it("batch deletes tasks", async () => { |
| 545 | const fetchMock = vi.fn().mockResolvedValue( |
| 546 | jsonResponse({ data: { ok: true } }), |
| 547 | ); |
| 548 | const client = mockClient(fetchMock); |
| 549 |
| 550 | const results = await client.batchDeleteTasks("ws_123", "board_1", ["task_1", "task_2"]); |
| 551 | expect(results).toHaveLength(2); |
| 552 | expect(fetchMock).toHaveBeenCalledTimes(2); |
| 553 | }); |
| 554 | }); |
| 555 |
| 556 | // --------------------------------------------------------------------------- |
| 557 | // Members |
| 558 | // --------------------------------------------------------------------------- |
| 559 |
| 560 | describe("Members API", () => { |
| 561 | it("lists workspace members", async () => { |
| 562 | const fetchMock = vi.fn().mockResolvedValue( |
| 563 | jsonResponse({ |
| 564 | data: { |
| 565 | members: [ |
| 566 | { id: "user_1", workspaceMemberId: "wm_1", email: "alice@example.com", firstName: "Alice", lastName: null, avatarUrl: null, joinedAt: "2026-01-01", roles: ["admin"] }, |
| 567 | ], |
| 568 | }, |
| 569 | }), |
| 570 | ); |
| 571 | const client = mockClient(fetchMock); |
| 572 |
| 573 | const result = await client.listWorkspaceMembers("ws_123"); |
| 574 | expect(result.members).toHaveLength(1); |
| 575 | expect(result.members[0]?.firstName).toBe("Alice"); |
| 576 | }); |
| 577 | }); |
| 578 |
| 579 | // --------------------------------------------------------------------------- |
| 580 | // Fluent workspace handle |
| 581 | // --------------------------------------------------------------------------- |
| 582 |
| 583 | describe("ColineWorkspace fluent API", () => { |
| 584 | it("delegates Notes CRUD through workspace handle", async () => { |
| 585 | const fetchMock = vi |
| 586 | .fn() |
| 587 | .mockResolvedValueOnce(jsonResponse({ data: { notes: [], cursor: null } })) |
| 588 | .mockResolvedValueOnce(jsonResponse({ data: { note: { id: "n_1" } } })) |
| 589 | .mockResolvedValueOnce(jsonResponse({ data: { note: { id: "n_1" } } })) |
| 590 | .mockResolvedValueOnce(jsonResponse({ data: { note: { id: "n_1" } } })) |
| 591 | .mockResolvedValueOnce(jsonResponse({ data: { ok: true } })); |
| 592 |
| 593 | const ws = mockClient(fetchMock).workspace("ws_123"); |
| 594 |
| 595 | await ws.listNotes(); |
| 596 | await ws.createNote({ title: "Test" }); |
| 597 | await ws.getNote("n_1"); |
| 598 | await ws.updateNote("n_1", { title: "Updated" }); |
| 599 | await ws.deleteNote("n_1"); |
| 600 |
| 601 | expect(fetchMock).toHaveBeenCalledTimes(5); |
| 602 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/notes"); |
| 603 | }); |
| 604 |
| 605 | it("delegates Docs CRUD through workspace handle", async () => { |
| 606 | const fetchMock = vi |
| 607 | .fn() |
| 608 | .mockResolvedValueOnce(jsonResponse({ data: { docs: [] } })) |
| 609 | .mockResolvedValueOnce(jsonResponse({ data: { doc: { id: "d_1" } } })); |
| 610 |
| 611 | const ws = mockClient(fetchMock).workspace("ws_123"); |
| 612 |
| 613 | await ws.listDocs(); |
| 614 | await ws.createDoc({ title: "Design" }); |
| 615 |
| 616 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/docs"); |
| 617 | expectUrl(fetchMock, 1, "https://api.coline.app/api/v1/workspaces/ws_123/docs"); |
| 618 | }); |
| 619 |
| 620 | it("delegates Calendar CRUD through workspace handle", async () => { |
| 621 | const fetchMock = vi |
| 622 | .fn() |
| 623 | .mockResolvedValueOnce(jsonResponse({ data: { events: [] } })) |
| 624 | .mockResolvedValueOnce(jsonResponse({ data: { event: { id: "e_1" } } })); |
| 625 |
| 626 | const ws = mockClient(fetchMock).workspace("ws_123"); |
| 627 |
| 628 | await ws.listCalendarEvents({ start: "2026-04-01", end: "2026-04-30" }); |
| 629 | await ws.createCalendarEvent({ |
| 630 | title: "Meet", |
| 631 | startsAt: "2026-04-05T09:00:00Z", |
| 632 | endsAt: "2026-04-05T10:00:00Z", |
| 633 | timeZone: "UTC", |
| 634 | }); |
| 635 |
| 636 | expect(fetchMock).toHaveBeenCalledTimes(2); |
| 637 | }); |
| 638 |
| 639 | it("delegates Task CRUD through workspace handle", async () => { |
| 640 | const fetchMock = vi |
| 641 | .fn() |
| 642 | .mockResolvedValueOnce(jsonResponse({ data: { taskboards: [] } })) |
| 643 | .mockResolvedValueOnce(jsonResponse({ data: { tasks: [] } })) |
| 644 | .mockResolvedValueOnce(jsonResponse({ data: { task: { id: "t_1" } } })); |
| 645 |
| 646 | const ws = mockClient(fetchMock).workspace("ws_123"); |
| 647 |
| 648 | await ws.listTaskboards(); |
| 649 | await ws.listTasks("board_1"); |
| 650 | await ws.createTask("board_1", { title: "Ship it" }); |
| 651 |
| 652 | expect(fetchMock).toHaveBeenCalledTimes(3); |
| 653 | }); |
| 654 |
| 655 | it("delegates search through workspace handle", async () => { |
| 656 | const fetchMock = vi.fn().mockResolvedValue( |
| 657 | jsonResponse({ data: { results: [], total: 0 } }), |
| 658 | ); |
| 659 | const ws = mockClient(fetchMock).workspace("ws_123"); |
| 660 |
| 661 | await ws.search({ query: "sdk" }); |
| 662 | expectUrl(fetchMock, 0, "https://api.coline.app/api/v1/workspaces/ws_123/search"); |
| 663 | }); |
| 664 | }); |
| 665 |
| 666 | // --------------------------------------------------------------------------- |
| 667 | // Retries |
| 668 | // --------------------------------------------------------------------------- |
| 669 |
| 670 | describe("Retry logic", () => { |
| 671 | it("retries on 429 and 5xx then succeeds", async () => { |
| 672 | const fetchMock = vi |
| 673 | .fn() |
| 674 | .mockResolvedValueOnce( |
| 675 | jsonResponse({ error: { code: "RATE_LIMIT", message: "Too fast" } }, 429), |
| 676 | ) |
| 677 | .mockResolvedValueOnce( |
| 678 | jsonResponse({ error: { code: "INTERNAL", message: "Oops" } }, 500), |
| 679 | ) |
| 680 | .mockResolvedValueOnce( |
| 681 | jsonResponse({ data: { notes: [] } }), |
| 682 | ); |
| 683 |
| 684 | const client = new ColineApiClient({ |
| 685 | baseUrl: "https://api.coline.app", |
| 686 | apiKey: "test-key", |
| 687 | fetch: fetchMock, |
| 688 | maxRetries: 2, |
| 689 | }); |
| 690 |
| 691 | const result = await client.listWorkspaceNotes("ws_123"); |
| 692 | expect(result.notes).toEqual([]); |
| 693 | expect(fetchMock).toHaveBeenCalledTimes(3); |
| 694 | }); |
| 695 |
| 696 | it("throws after exhausting retries", async () => { |
| 697 | const fetchMock = vi.fn().mockResolvedValue( |
| 698 | jsonResponse({ error: { code: "INTERNAL", message: "Oops" } }, 500), |
| 699 | ); |
| 700 |
| 701 | const client = new ColineApiClient({ |
| 702 | baseUrl: "https://api.coline.app", |
| 703 | apiKey: "test-key", |
| 704 | fetch: fetchMock, |
| 705 | maxRetries: 1, |
| 706 | }); |
| 707 |
| 708 | await expect(client.listWorkspaceNotes("ws_123")).rejects.toBeInstanceOf(ColineApiError); |
| 709 | expect(fetchMock).toHaveBeenCalledTimes(2); |
| 710 | }); |
| 711 |
| 712 | it("does not retry on 4xx (non-429)", async () => { |
| 713 | const fetchMock = vi.fn().mockResolvedValue( |
| 714 | jsonResponse({ error: { code: "FORBIDDEN", message: "Denied" } }, 403), |
| 715 | ); |
| 716 |
| 717 | const client = new ColineApiClient({ |
| 718 | baseUrl: "https://api.coline.app", |
| 719 | apiKey: "test-key", |
| 720 | fetch: fetchMock, |
| 721 | maxRetries: 3, |
| 722 | }); |
| 723 |
| 724 | await expect(client.listWorkspaceNotes("ws_123")).rejects.toBeInstanceOf(ColineApiError); |
| 725 | expect(fetchMock).toHaveBeenCalledTimes(1); |
| 726 | }); |
| 727 | }); |
| 728 |
| 729 | // --------------------------------------------------------------------------- |
| 730 | // Streaming |
| 731 | // --------------------------------------------------------------------------- |
| 732 |
| 733 | describe("Tab streaming", () => { |
| 734 | it("streams Tab text chunks from SSE", async () => { |
| 735 | const sseBody = [ |
| 736 | 'data: {"id":"c_1","object":"chat.completion.chunk","created":1,"model":"tab-v1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}\n\n', |
| 737 | 'data: {"id":"c_1","object":"chat.completion.chunk","created":1,"model":"tab-v1","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}\n\n', |
| 738 | 'data: {"id":"c_1","object":"chat.completion.chunk","created":1,"model":"tab-v1","choices":[{"index":0,"delta":{"content":" world"},"finish_reason":null}]}\n\n', |
| 739 | 'data: {"id":"c_1","object":"chat.completion.chunk","created":1,"model":"tab-v1","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}\n\n', |
| 740 | "data: [DONE]\n\n", |
| 741 | ].join(""); |
| 742 |
| 743 | const fetchMock = vi.fn().mockResolvedValue( |
| 744 | new Response(sseBody, { |
| 745 | status: 200, |
| 746 | headers: { "Content-Type": "text/event-stream" }, |
| 747 | }), |
| 748 | ); |
| 749 |
| 750 | const client = mockClient(fetchMock); |
| 751 | const chunks: string[] = []; |
| 752 |
| 753 | for await (const text of client.streamTabText({ |
| 754 | tab_context: { |
| 755 | surface: "notes", |
| 756 | workspace_slug: "acme", |
| 757 | entity_id: "note_1", |
| 758 | active_text_before_cursor: "Hi", |
| 759 | }, |
| 760 | })) { |
| 761 | chunks.push(text); |
| 762 | } |
| 763 |
| 764 | expect(chunks).toEqual(["Hello", " world"]); |
| 765 | }); |
| 766 |
| 767 | it("throws on non-200 streaming response", async () => { |
| 768 | const fetchMock = vi.fn().mockResolvedValue( |
| 769 | new Response(JSON.stringify({ error: { code: "FORBIDDEN", message: "No" } }), { |
| 770 | status: 403, |
| 771 | headers: { "Content-Type": "application/json" }, |
| 772 | }), |
| 773 | ); |
| 774 |
| 775 | const client = mockClient(fetchMock); |
| 776 |
| 777 | const gen = client.streamTabText({ |
| 778 | tab_context: { surface: "notes", workspace_slug: "acme", entity_id: "n_1", active_text_before_cursor: "test" }, |
| 779 | }); |
| 780 |
| 781 | await expect(gen.next()).rejects.toBeInstanceOf(ColineApiError); |
| 782 | }); |
| 783 | }); |
| 784 |
| 785 | // --------------------------------------------------------------------------- |
| 786 | // Uploads |
| 787 | // --------------------------------------------------------------------------- |
| 788 |
| 789 | describe("Uploads API", () => { |
| 790 | it("initiates and completes a multi-part upload", async () => { |
| 791 | const fetchMock = vi |
| 792 | .fn() |
| 793 | .mockResolvedValueOnce( |
| 794 | jsonResponse({ data: { uploadId: "up_1", partCount: 2 } }), |
| 795 | ) |
| 796 | .mockResolvedValueOnce( |
| 797 | jsonResponse({ data: { partNumber: 1, etag: "etag_1" } }), |
| 798 | ) |
| 799 | .mockResolvedValueOnce( |
| 800 | jsonResponse({ data: { partNumber: 2, etag: "etag_2" } }), |
| 801 | ) |
| 802 | .mockResolvedValueOnce( |
| 803 | jsonResponse({ data: { file: { id: "file_1" } } }), |
| 804 | ); |
| 805 |
| 806 | const client = mockClient(fetchMock); |
| 807 |
| 808 | await client.initiateUpload("ws_123", { |
| 809 | fileName: "report.pdf", |
| 810 | mimeType: "application/pdf", |
| 811 | sizeBytes: 2048, |
| 812 | driveId: "drive_1", |
| 813 | }); |
| 814 |
| 815 | await client.uploadPart("ws_123", "up_1", 1, new Uint8Array(1024)); |
| 816 | await client.uploadPart("ws_123", "up_1", 2, new Uint8Array(1024)); |
| 817 |
| 818 | const result = await client.completeUpload("ws_123", "up_1", [ |
| 819 | { partNumber: 1, etag: "etag_1" }, |
| 820 | { partNumber: 2, etag: "etag_2" }, |
| 821 | ]); |
| 822 |
| 823 | expect(result.file.id).toBe("file_1"); |
| 824 | expect(fetchMock).toHaveBeenCalledTimes(4); |
| 825 | }); |
| 826 |
| 827 | it("uploads a file in one call via uploadFile helper", async () => { |
| 828 | const fetchMock = vi |
| 829 | .fn() |
| 830 | .mockResolvedValueOnce( |
| 831 | jsonResponse({ data: { uploadId: "up_1", partCount: 1 } }), |
| 832 | ) |
| 833 | .mockResolvedValueOnce( |
| 834 | jsonResponse({ data: { partNumber: 1, etag: "etag_1" } }), |
| 835 | ) |
| 836 | .mockResolvedValueOnce( |
| 837 | jsonResponse({ data: { file: { id: "file_1", name: "photo.jpg" } } }), |
| 838 | ); |
| 839 |
| 840 | const client = mockClient(fetchMock); |
| 841 |
| 842 | const result = await client.uploadFile("ws_123", { |
| 843 | data: new Uint8Array(512), |
| 844 | fileName: "photo.jpg", |
| 845 | mimeType: "image/jpeg", |
| 846 | driveId: "drive_1", |
| 847 | }); |
| 848 |
| 849 | expect(result.file.id).toBe("file_1"); |
| 850 | expect(fetchMock).toHaveBeenCalledTimes(3); |
| 851 | }); |
| 852 | }); |
| 853 |
| 854 | // --------------------------------------------------------------------------- |
| 855 | // Error handling |
| 856 | // --------------------------------------------------------------------------- |
| 857 |
| 858 | describe("Error handling", () => { |
| 859 | it("ColineApiError has correct properties", async () => { |
| 860 | const fetchMock = vi.fn().mockResolvedValue( |
| 861 | jsonResponse({ error: { code: "NOT_FOUND", message: "Note not found." } }, 404), |
| 862 | ); |
| 863 |
| 864 | const client = mockClient(fetchMock); |
| 865 |
| 866 | try { |
| 867 | await client.getWorkspaceNote("ws_123", "note_999"); |
| 868 | expect.unreachable("Should have thrown"); |
| 869 | } catch (error) { |
| 870 | expect(error).toBeInstanceOf(ColineApiError); |
| 871 | const apiError = error as ColineApiError; |
| 872 | expect(apiError.status).toBe(404); |
| 873 | expect(apiError.code).toBe("NOT_FOUND"); |
| 874 | expect(apiError.message).toBe("Note not found."); |
| 875 | expect(apiError.isRetryable).toBe(false); |
| 876 | } |
| 877 | }); |
| 878 |
| 879 | it("429 errors are marked retryable", async () => { |
| 880 | const fetchMock = vi.fn().mockResolvedValue( |
| 881 | jsonResponse({ error: { code: "RATE_LIMIT_EXCEEDED", message: "Slow down." } }, 429), |
| 882 | ); |
| 883 |
| 884 | const client = mockClient(fetchMock); |
| 885 |
| 886 | try { |
| 887 | await client.listWorkspaceNotes("ws_123"); |
| 888 | expect.unreachable("Should have thrown"); |
| 889 | } catch (error) { |
| 890 | const apiError = error as ColineApiError; |
| 891 | expect(apiError.isRetryable).toBe(true); |
| 892 | } |
| 893 | }); |
| 894 |
| 895 | it("500 errors are marked retryable", async () => { |
| 896 | const fetchMock = vi.fn().mockResolvedValue( |
| 897 | jsonResponse({ error: { code: "INTERNAL", message: "Oops." } }, 500), |
| 898 | ); |
| 899 |
| 900 | const client = mockClient(fetchMock); |
| 901 |
| 902 | try { |
| 903 | await client.listWorkspaceNotes("ws_123"); |
| 904 | expect.unreachable("Should have thrown"); |
| 905 | } catch (error) { |
| 906 | const apiError = error as ColineApiError; |
| 907 | expect(apiError.isRetryable).toBe(true); |
| 908 | } |
| 909 | }); |
| 910 | }); |
| 911 |
| 912 | // --------------------------------------------------------------------------- |
| 913 | // Auth header injection |
| 914 | // --------------------------------------------------------------------------- |
| 915 |
| 916 | describe("Auth headers", () => { |
| 917 | it("sends Bearer token on core API requests", async () => { |
| 918 | const fetchMock = vi.fn().mockResolvedValue( |
| 919 | jsonResponse({ data: { notes: [] } }), |
| 920 | ); |
| 921 |
| 922 | const client = new ColineApiClient({ |
| 923 | baseUrl: "https://api.coline.app", |
| 924 | apiKey: "col_ws_abc_secret123", |
| 925 | fetch: fetchMock, |
| 926 | }); |
| 927 |
| 928 | await client.listWorkspaceNotes("ws_123"); |
| 929 |
| 930 | const headers = getRequestHeaders(fetchMock, 0); |
| 931 | expect(headers.get("Authorization")).toBe("Bearer col_ws_abc_secret123"); |
| 932 | }); |
| 933 |
| 934 | it("sends custom headers alongside auth", async () => { |
| 935 | const fetchMock = vi.fn().mockResolvedValue( |
| 936 | jsonResponse({ data: { notes: [] } }), |
| 937 | ); |
| 938 |
| 939 | const client = new ColineApiClient({ |
| 940 | baseUrl: "https://api.coline.app", |
| 941 | apiKey: "key", |
| 942 | fetch: fetchMock, |
| 943 | headers: { "X-Custom": "value" }, |
| 944 | }); |
| 945 |
| 946 | await client.listWorkspaceNotes("ws_123"); |
| 947 |
| 948 | const headers = getRequestHeaders(fetchMock, 0); |
| 949 | expect(headers.get("Authorization")).toBe("Bearer key"); |
| 950 | expect(headers.get("X-Custom")).toBe("value"); |
| 951 | }); |
| 952 | }); |
| 953 |
| 954 | // --------------------------------------------------------------------------- |
| 955 | // App runtime (notifications, index, ambient) |
| 956 | // --------------------------------------------------------------------------- |
| 957 |
| 958 | describe("App Runtime API", () => { |
| 959 | it("sends app notifications", async () => { |
| 960 | const fetchMock = vi.fn().mockResolvedValue( |
| 961 | jsonResponse({ data: { delivered: 1 } }), |
| 962 | ); |
| 963 | const client = mockClient(fetchMock); |
| 964 |
| 965 | await client.createAppNotification("ws_123", "acme-crm", { |
| 966 | channelKey: "alerts", |
| 967 | typeKey: "new_lead", |
| 968 | title: "New lead", |
| 969 | body: "Acme Corp signed up", |
| 970 | recipients: [{ userId: "user_1" }], |
| 971 | }); |
| 972 |
| 973 | expectMethod(fetchMock, 0, "POST"); |
| 974 | expectUrl( |
| 975 | fetchMock, |
| 976 | 0, |
| 977 | "https://api.coline.app/api/v1/workspaces/ws_123/apps/acme-crm/notifications", |
| 978 | ); |
| 979 | }); |
| 980 |
| 981 | it("upserts and deletes index documents", async () => { |
| 982 | const fetchMock = vi |
| 983 | .fn() |
| 984 | .mockResolvedValueOnce(jsonResponse({ data: { upserted: 2 } })) |
| 985 | .mockResolvedValueOnce(jsonResponse({ data: { deleted: 1 } })); |
| 986 |
| 987 | const client = mockClient(fetchMock); |
| 988 |
| 989 | await client.upsertAppIndexDocuments("ws_123", "acme-crm", { |
| 990 | documents: [ |
| 991 | { documentKey: "doc_1", documentType: "help", title: "Help", body: "How to use" }, |
| 992 | { documentKey: "doc_2", documentType: "help", title: "FAQ", body: "Common questions" }, |
| 993 | ], |
| 994 | }); |
| 995 |
| 996 | await client.deleteAppIndexDocuments("ws_123", "acme-crm", { |
| 997 | documentKeys: ["doc_1"], |
| 998 | }); |
| 999 |
| 1000 | expectMethod(fetchMock, 0, "POST"); |
| 1001 | expectMethod(fetchMock, 1, "DELETE"); |
| 1002 | }); |
| 1003 |
| 1004 | it("emits ambient events", async () => { |
| 1005 | const fetchMock = vi.fn().mockResolvedValue( |
| 1006 | jsonResponse({ data: { accepted: 1 } }), |
| 1007 | ); |
| 1008 | const client = mockClient(fetchMock); |
| 1009 |
| 1010 | await client.emitAppAmbientEvents("ws_123", "acme-crm", { |
| 1011 | events: [ |
| 1012 | { |
| 1013 | action: "created", |
| 1014 | entityType: "app_document", |
| 1015 | entityId: "lead_1", |
| 1016 | containerType: "channel", |
| 1017 | containerId: "ch_1", |
| 1018 | dedupeKey: "lead_scored_lead_1", |
| 1019 | }, |
| 1020 | ], |
| 1021 | }); |
| 1022 |
| 1023 | expectUrl( |
| 1024 | fetchMock, |
| 1025 | 0, |
| 1026 | "https://api.coline.app/api/v1/workspaces/ws_123/apps/acme-crm/ambient/events", |
| 1027 | ); |
| 1028 | }); |
| 1029 | }); |
| 1030 |
| 1031 | // --------------------------------------------------------------------------- |
| 1032 | // URL encoding |
| 1033 | // --------------------------------------------------------------------------- |
| 1034 |
| 1035 | describe("URL encoding", () => { |
| 1036 | it("encodes special characters in path segments", async () => { |
| 1037 | const fetchMock = vi.fn().mockResolvedValue( |
| 1038 | jsonResponse({ data: { notes: [] } }), |
| 1039 | ); |
| 1040 | const client = mockClient(fetchMock); |
| 1041 |
| 1042 | await client.listWorkspaceNotes("ws/with/slashes"); |
| 1043 | expectUrl( |
| 1044 | fetchMock, |
| 1045 | 0, |
| 1046 | "https://api.coline.app/api/v1/workspaces/ws%2Fwith%2Fslashes/notes", |
| 1047 | ); |
| 1048 | }); |
| 1049 | }); |
| 1050 |