Add bd exec bridge and mutation API routes with tests
This commit is contained in:
parent
0e3815ac3c
commit
2c80265258
15 changed files with 904 additions and 5 deletions
55
tests/api/mutations-routes.test.ts
Normal file
55
tests/api/mutations-routes.test.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { POST as createPost } from '../../src/app/api/beads/create/route';
|
||||
import { POST as reopenPost } from '../../src/app/api/beads/reopen/route';
|
||||
import { POST as commentPost } from '../../src/app/api/beads/comment/route';
|
||||
|
||||
async function readJson(response: Response): Promise<any> {
|
||||
const text = await response.text();
|
||||
return text ? JSON.parse(text) : {};
|
||||
}
|
||||
|
||||
test('create route returns 400 for invalid payload', async () => {
|
||||
const response = await createPost(
|
||||
new Request('http://localhost/api/beads/create', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ projectRoot: '', title: '' }),
|
||||
headers: { 'content-type': 'application/json' },
|
||||
}),
|
||||
);
|
||||
|
||||
assert.equal(response.status, 400);
|
||||
const data = await readJson(response);
|
||||
assert.equal(data.ok, false);
|
||||
assert.equal(data.error.classification, 'bad_args');
|
||||
});
|
||||
|
||||
test('reopen route returns 400 for missing id', async () => {
|
||||
const response = await reopenPost(
|
||||
new Request('http://localhost/api/beads/reopen', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ projectRoot: 'C:/repo' }),
|
||||
headers: { 'content-type': 'application/json' },
|
||||
}),
|
||||
);
|
||||
|
||||
assert.equal(response.status, 400);
|
||||
const data = await readJson(response);
|
||||
assert.equal(data.ok, false);
|
||||
});
|
||||
|
||||
test('comment route returns 400 for missing comment text', async () => {
|
||||
const response = await commentPost(
|
||||
new Request('http://localhost/api/beads/comment', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ projectRoot: 'C:/repo', id: 'bb-1' }),
|
||||
headers: { 'content-type': 'application/json' },
|
||||
}),
|
||||
);
|
||||
|
||||
assert.equal(response.status, 400);
|
||||
const data = await readJson(response);
|
||||
assert.equal(data.ok, false);
|
||||
assert.equal(typeof data.error.message, 'string');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue