|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { app } from './index.js'; |
| 3 | +describe('Server API', () => { |
| 4 | + it('GET /api/info returns bot info', async () => { |
| 5 | + // Note: This relies on actual file system unless mocked. |
| 6 | + // Ideally we mock fs, but for integration test on CI it's fine. |
| 7 | + const res = await app.request('/api/info'); |
| 8 | + expect(res.status).toBe(200); |
| 9 | + const data = await res.json(); |
| 10 | + expect(data).toHaveProperty('version'); |
| 11 | + }); |
| 12 | + it('GET /api/agent/status returns structure', async () => { |
| 13 | + const res = await app.request('/api/agent/status'); |
| 14 | + expect(res.status).toBe(200); |
| 15 | + const data = await res.json(); |
| 16 | + expect(data).toHaveProperty('config'); |
| 17 | + expect(data).toHaveProperty('gateway'); |
| 18 | + }); |
| 19 | +}); |
| 20 | +describe('Backlinks API', () => { |
| 21 | + // These tests rely on the actual WORKSPACE directory (~/clawd by default) |
| 22 | + // They test the API structure and basic behavior |
| 23 | + it('GET /api/resolve-wikilink returns 400 without link', async () => { |
| 24 | + const res = await app.request('/api/resolve-wikilink'); |
| 25 | + expect(res.status).toBe(400); |
| 26 | + }); |
| 27 | + it('GET /api/resolve-wikilink resolves existing file', async () => { |
| 28 | + // MEMORY.md should exist in the workspace |
| 29 | + const res = await app.request('/api/resolve-wikilink?link=MEMORY'); |
| 30 | + expect(res.status).toBe(200); |
| 31 | + const data = await res.json(); |
| 32 | + expect(data).toHaveProperty('found'); |
| 33 | + expect(data).toHaveProperty('path'); |
| 34 | + }); |
| 35 | + it('GET /api/resolve-wikilink returns not found for nonexistent', async () => { |
| 36 | + const res = await app.request('/api/resolve-wikilink?link=nonexistent-file-that-does-not-exist-12345'); |
| 37 | + expect(res.status).toBe(200); |
| 38 | + const data = await res.json(); |
| 39 | + expect(data.found).toBe(false); |
| 40 | + }); |
| 41 | +}); |
0 commit comments