⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
import { describe, it, expect, beforeEach } from 'bun:test';
import { authedApi, type Api, createProject } from '#tests/helpers/app';
import { signUpTestUser } from '#tests/helpers/auth';
import { resetDb } from '#tests/helpers/db';
import { createAgent } from '#tests/helpers/agents';
// Issues live under a project. Create is /projects/:projectKey/issues (permission
// guard on :projectKey); the other routes address the issue by its own id
// (/issues/:issueId) and resolve access through the workItem guard. An issue is
// read back through GET /issues/:issueId (with its custom field values) or through
// the project view (GET /projects/:projectKey → `issues`, which carries labelIds
// and set field values). createProject seeds five default columns.
interface Setup {
asOwner: Api;
ownerUserId: string;
columnId: number;
columnIds: number[];
}
// A fresh project plus the ids of its seeded columns. columnIds[0] is used as the
// default target column for created issues.
async function setupProject(): Promise<Setup> {
const owner = await signUpTestUser();
const asOwner = authedApi(owner.cookie);
await createProject(asOwner, { key: 'MKT', name: 'Marketing' });
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const columnIds = view.data!.columns.map((c) => c.id);
return { asOwner, ownerUserId: owner.userId, columnId: columnIds[0], columnIds };
}
function createIssue(client: Api, columnId: number, patch: Record<string, unknown> = {}) {
return client.projects({ projectKey: 'MKT' }).issues.post({ columnId, title: 'Task', ...patch });
}
// A label of a second project, which no issue of the first one may carry.
async function foreignLabel(client: Api) {
await createProject(client, { key: 'OPS', name: 'Operations' });
const res = await client.projects({ projectKey: 'OPS' }).labels.post({ name: 'ops-secret' });
return res.data!;
}
// A column and an issue type of a second project, which no issue of the first one
// may point at.
async function foreignProject(client: Api) {
await createProject(client, { key: 'OPS', name: 'Operations' });
const view = await client.projects({ projectKey: 'OPS' }).get();
const type = await client
.projects({ projectKey: 'OPS' })
['issue-types'].post({ name: 'Incident' });
return { columnId: view.data!.columns[0].id, typeId: type.data!.id };
}
// The board's issue list (carries labelIds and set custom field values).
async function issuesOf(client: Api, projectKey = 'MKT') {
const board = await client.projects({ projectKey }).issues.board.get();
return board.data!.issues;
}
describe('issues', () => {
beforeEach(async () => {
await resetDb();
});
describe('create', () => {
it('creates an issue and returns it with an identifier and position', async () => {
const { asOwner, columnId } = await setupProject();
const created = await createIssue(asOwner, columnId, { title: 'Ship the docs' });
expect(created.status).toBe(201);
expect(created.data).toMatchObject({
title: 'Ship the docs',
columnId,
description: '',
labelIds: [],
});
expect(created.data?.identifier).toMatch(/^MKT-\d+$/);
expect(typeof created.data?.id).toBe('number');
expect(typeof created.data?.position).toBe('number');
const list = await issuesOf(asOwner);
expect(list.map((i) => i.id)).toContain(created.data!.id);
});
it('returns the linked initiative expanded to id, title and status', async () => {
const { asOwner, columnId } = await setupProject();
const initiative = (
await asOwner
.projects({ projectKey: 'MKT' })
.initiatives.post({ title: 'Q3 Launch', status: 'active' })
).data!;
const created = await createIssue(asOwner, columnId, { initiativeId: initiative.id });
expect(created.status).toBe(201);
expect(created.data?.initiative).toEqual({
id: initiative.id,
title: 'Q3 Launch',
status: 'active',
});
// The board payload carries the same expanded shape.
const onBoard = (await issuesOf(asOwner)).find((i) => i.id === created.data!.id);
expect(onBoard?.initiative).toEqual({
id: initiative.id,
title: 'Q3 Launch',
status: 'active',
});
});
it('stores the optional fields when provided', async () => {
const { asOwner, columnId } = await setupProject();
const created = await createIssue(asOwner, columnId, {
title: 'With details',
description: 'the body',
priority: 'high',
startDate: '2026-01-01',
dueDate: '2026-02-01',
});
expect(created.status).toBe(201);
expect(created.data).toMatchObject({ description: 'the body', priority: 'high' });
// `date` columns come back as 'YYYY-MM-DD', which Eden Treaty revives into a Date.
expect(new Date(created.data!.startDate!).getTime()).toBe(new Date('2026-01-01').getTime());
expect(new Date(created.data!.dueDate!).getTime()).toBe(new Date('2026-02-01').getTime());
});
it('accepts a description of 50000 characters and rejects a longer one', async () => {
const { asOwner, columnId } = await setupProject();
const fits = await createIssue(asOwner, columnId, { description: 'x'.repeat(50_000) });
expect(fits.status).toBe(201);
const over = await createIssue(asOwner, columnId, { description: 'x'.repeat(50_001) });
expect(over.status).toBe(400);
});
it('hands out an increasing per-project sequence number', async () => {
const { asOwner, columnId } = await setupProject();
const first = (await createIssue(asOwner, columnId)).data!;
const second = (await createIssue(asOwner, columnId)).data!;
const seq = (id: string) => Number(id.split('-')[1]);
expect(seq(second.identifier)).toBe(seq(first.identifier) + 1);
});
it('gives a later issue in the same column a higher position', async () => {
const { asOwner, columnId } = await setupProject();
const first = (await createIssue(asOwner, columnId)).data!;
const second = (await createIssue(asOwner, columnId)).data!;
expect(second.position).toBeGreaterThan(first.position);
});
it('attaches labels passed as labelIds', async () => {
const { asOwner, columnId } = await setupProject();
const label = (await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'bug' }))
.data!;
const created = await createIssue(asOwner, columnId, { labelIds: [label.id] });
expect(created.status).toBe(201);
expect(created.data?.labelIds).toEqual([label.id]);
// The project view also reports the label on the issue.
const list = await issuesOf(asOwner);
expect(list.find((i) => i.id === created.data!.id)?.labelIds).toEqual([label.id]);
});
it('rejects a label of another project and creates no issue', async () => {
const { asOwner, columnId } = await setupProject();
const foreign = await foreignLabel(asOwner);
const created = await createIssue(asOwner, columnId, { labelIds: [foreign.id] });
expect(created.status).toBe(400);
expect(await issuesOf(asOwner)).toHaveLength(0);
});
it('rejects a column of another project and creates no issue', async () => {
const { asOwner } = await setupProject();
const foreign = await foreignProject(asOwner);
const created = await createIssue(asOwner, foreign.columnId);
expect(created.status).toBe(400);
expect(await issuesOf(asOwner)).toHaveLength(0);
});
it('rejects an issue type of another project and creates no issue', async () => {
const { asOwner, columnId } = await setupProject();
const foreign = await foreignProject(asOwner);
const created = await createIssue(asOwner, columnId, { typeId: foreign.typeId });
expect(created.status).toBe(400);
expect(await issuesOf(asOwner)).toHaveLength(0);
});
it('rejects an empty title', async () => {
const { asOwner, columnId } = await setupProject();
const res = await createIssue(asOwner, columnId, { title: '' });
expect(res.status).toBe(400);
});
it('rejects a missing columnId', async () => {
const { asOwner } = await setupProject();
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.post({ title: 'No column' } as unknown as { columnId: number; title: string });
expect(res.status).toBe(400);
});
it('returns 404 for an unknown project', async () => {
const { asOwner, columnId } = await setupProject();
const res = await asOwner
.projects({ projectKey: 'NOPE' })
.issues.post({ columnId, title: 'X' });
expect(res.status).toBe(404);
});
});
describe('get', () => {
it('returns the issue with its custom field values', async () => {
const { asOwner, columnId } = await setupProject();
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Severity', fieldType: 'text' });
const issue = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner.issues({ issueId: issue.id }).get();
expect(res.status).toBe(200);
expect(res.data).toMatchObject({ id: issue.id, title: 'Task' });
// The project-wide field is listed (unset → value null).
expect(res.data?.fields.map((f) => f.name)).toContain('Severity');
expect(res.data?.fields.find((f) => f.name === 'Severity')?.value).toBeNull();
});
it('returns 404 for a missing issue', async () => {
const { asOwner } = await setupProject();
const res = await asOwner.issues({ issueId: 999999 }).get();
expect(res.status).toBe(404);
});
it('rejects a non-numeric issue id', async () => {
const { asOwner } = await setupProject();
const res = await asOwner.issues({ issueId: 'abc' as unknown as number }).get();
expect(res.status).toBe(400);
});
});
// GET /projects/:projectKey/issues/:sequenceNumber resolves an issue by its
// human number (the identifier-based URL), including archived ones.
describe('get by number', () => {
it('returns the issue matching the project-scoped number', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues({ sequenceNumber: issue.sequenceNumber })
.get();
expect(res.status).toBe(200);
expect(res.data).toMatchObject({ id: issue.id, identifier: issue.identifier });
});
it('resolves an archived issue too', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
await asOwner.issues({ issueId: issue.id }).archive.post();
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues({ sequenceNumber: issue.sequenceNumber })
.get();
expect(res.status).toBe(200);
expect(res.data?.archivedAt).toBeTruthy();
});
it('returns 404 for an unknown number', async () => {
const { asOwner } = await setupProject();
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues({ sequenceNumber: 999999 })
.get();
expect(res.status).toBe(404);
});
});
describe('dates', () => {
// The value goes into a `date` column, so an unvalidated one reaches Postgres
// and answers 500 with the driver's message instead of 400.
it('rejects a due date that is not YYYY-MM-DD', async () => {
const { asOwner, columnId } = await setupProject();
const res = await asOwner.projects({ projectKey: 'MKT' }).issues.post({
columnId,
title: 'Dated',
dueDate: '01.02.2026',
});
expect(res.status).toBe(400);
});
it('rejects a due date an update sends in another notation', async () => {
const { asOwner, columnId } = await setupProject();
const created = await asOwner
.projects({ projectKey: 'MKT' })
.issues.post({ columnId, title: 'Dated' });
const res = await asOwner
.issues({ issueId: created.data!.id })
.patch({ dueDate: '01.02.2026' });
expect(res.status).toBe(400);
});
it('rejects a date whose month does not exist', async () => {
const { asOwner, columnId } = await setupProject();
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.post({ columnId, title: 'Dated', dueDate: '2026-13-45' });
expect(res.status).toBe(400);
});
it('rejects a due date before the start date on create', async () => {
const { asOwner, columnId } = await setupProject();
const res = await createIssue(asOwner, columnId, {
startDate: '2026-09-08',
dueDate: '2026-08-30',
});
expect(res.status).toBe(400);
});
it('allows a due date equal to the start date', async () => {
const { asOwner, columnId } = await setupProject();
const res = await createIssue(asOwner, columnId, {
startDate: '2026-09-08',
dueDate: '2026-09-08',
});
expect(res.status).toBe(201);
});
it('rejects a due date patched before the stored start date', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId, { startDate: '2026-09-08' })).data!;
const res = await asOwner.issues({ issueId: issue.id }).patch({ dueDate: '2026-08-30' });
expect(res.status).toBe(400);
});
it('rejects a start date patched after the stored due date', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId, { dueDate: '2026-08-30' })).data!;
const res = await asOwner.issues({ issueId: issue.id }).patch({ startDate: '2026-09-08' });
expect(res.status).toBe(400);
});
});
describe('update', () => {
it('updates the title', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const patched = await asOwner.issues({ issueId: issue.id }).patch({ title: 'Renamed' });
expect(patched.status).toBe(200);
expect(patched.data).toMatchObject({ title: 'Renamed' });
const read = await asOwner.issues({ issueId: issue.id }).get();
expect(read.data?.title).toBe('Renamed');
});
it('bounds the description the way a new issue is bounded', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const edit = asOwner.issues({ issueId: issue.id });
expect((await edit.patch({ description: 'x'.repeat(50_000) })).status).toBe(200);
expect((await edit.patch({ description: 'x'.repeat(50_001) })).status).toBe(400);
});
it('moves the issue to another column', async () => {
const { asOwner, columnId, columnIds } = await setupProject();
const target = columnIds[1];
const issue = (await createIssue(asOwner, columnId)).data!;
const patched = await asOwner.issues({ issueId: issue.id }).patch({ columnId: target });
expect(patched.status).toBe(200);
expect(patched.data?.columnId).toBe(target);
});
it('reorders the issue within a column', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const patched = await asOwner.issues({ issueId: issue.id }).patch({ position: 5 });
expect(patched.status).toBe(200);
expect(patched.data?.position).toBe(5);
});
it('replaces the label set', async () => {
const { asOwner, columnId } = await setupProject();
const a = (await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'a' })).data!;
const b = (await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'b' })).data!;
const issue = (await createIssue(asOwner, columnId, { labelIds: [a.id] })).data!;
const patched = await asOwner.issues({ issueId: issue.id }).patch({ labelIds: [b.id] });
expect(patched.status).toBe(200);
expect(patched.data?.labelIds).toEqual([b.id]);
const list = await issuesOf(asOwner);
expect(list.find((i) => i.id === issue.id)?.labelIds).toEqual([b.id]);
});
it('rejects a label of another project and keeps the current set', async () => {
const { asOwner, columnId } = await setupProject();
const own = (await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'a' })).data!;
const foreign = await foreignLabel(asOwner);
const issue = (await createIssue(asOwner, columnId, { labelIds: [own.id] })).data!;
const patched = await asOwner.issues({ issueId: issue.id }).patch({ labelIds: [foreign.id] });
expect(patched.status).toBe(400);
const list = await issuesOf(asOwner);
expect(list.find((i) => i.id === issue.id)?.labelIds).toEqual([own.id]);
});
it('rejects a column of another project and keeps the current one', async () => {
const { asOwner, columnId } = await setupProject();
const foreign = await foreignProject(asOwner);
const issue = (await createIssue(asOwner, columnId)).data!;
const patched = await asOwner.issues({ issueId: issue.id }).patch({
columnId: foreign.columnId,
});
expect(patched.status).toBe(400);
const read = await asOwner.issues({ issueId: issue.id }).get();
expect(read.data?.columnId).toBe(columnId);
});
it('rejects an issue type of another project and keeps the current one', async () => {
const { asOwner, columnId } = await setupProject();
const own = (
await asOwner.projects({ projectKey: 'MKT' })['issue-types'].post({ name: 'Bug' })
).data!;
const foreign = await foreignProject(asOwner);
const issue = (await createIssue(asOwner, columnId, { typeId: own.id })).data!;
const patched = await asOwner.issues({ issueId: issue.id }).patch({ typeId: foreign.typeId });
expect(patched.status).toBe(400);
const read = await asOwner.issues({ issueId: issue.id }).get();
expect(read.data?.typeId).toBe(own.id);
});
it('changes only the given fields', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId, { title: 'Keep', priority: 'low' }))
.data!;
const patched = await asOwner.issues({ issueId: issue.id }).patch({ priority: 'high' });
expect(patched.data).toMatchObject({ title: 'Keep', priority: 'high' });
});
it('returns 404 for a missing issue', async () => {
const { asOwner } = await setupProject();
const res = await asOwner.issues({ issueId: 999999 }).patch({ title: 'Nope' });
expect(res.status).toBe(404);
});
it('rejects an empty title', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner.issues({ issueId: issue.id }).patch({ title: '' });
expect(res.status).toBe(400);
});
it('rejects a non-numeric issue id', async () => {
const { asOwner } = await setupProject();
const res = await asOwner
.issues({ issueId: 'abc' as unknown as number })
.patch({ title: 'X' });
expect(res.status).toBe(400);
});
});
describe('estimates', () => {
it('stores both estimates on create and reads them back', async () => {
const { asOwner, columnId } = await setupProject();
const created = await createIssue(asOwner, columnId, {
title: 'Sized',
estimatePoints: 3,
estimateMinutes: 90,
});
expect(created.status).toBe(201);
expect(created.data).toMatchObject({ estimatePoints: 3, estimateMinutes: 90 });
const read = await asOwner.issues({ issueId: created.data!.id }).get();
expect(read.data).toMatchObject({ estimatePoints: 3, estimateMinutes: 90 });
});
it('leaves both estimates unset on an issue created without them', async () => {
const { asOwner, columnId } = await setupProject();
const created = await createIssue(asOwner, columnId);
expect(created.data).toMatchObject({ estimatePoints: null, estimateMinutes: null });
});
it('clears an estimate set back to null', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId, { estimateMinutes: 90 })).data!;
const patched = await asOwner.issues({ issueId: issue.id }).patch({ estimateMinutes: null });
expect(patched.status).toBe(200);
expect(patched.data).toMatchObject({ estimateMinutes: null });
});
it('keeps a fractional points estimate', async () => {
const { asOwner, columnId } = await setupProject();
const created = await createIssue(asOwner, columnId, { estimatePoints: 0.5 });
expect(created.data).toMatchObject({ estimatePoints: 0.5 });
});
it('rejects a negative estimate', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
expect((await createIssue(asOwner, columnId, { estimatePoints: -1 })).status).toBe(400);
expect(
(await asOwner.issues({ issueId: issue.id }).patch({ estimateMinutes: -30 })).status,
).toBe(400);
});
it('rejects a time estimate that is not a whole number of minutes', async () => {
const { asOwner, columnId } = await setupProject();
const res = await createIssue(asOwner, columnId, { estimateMinutes: 1.5 });
expect(res.status).toBe(400);
});
it('sets an estimate on many issues at once', async () => {
const { asOwner, columnId } = await setupProject();
const first = (await createIssue(asOwner, columnId)).data!;
const second = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.patch({ ids: [first.id, second.id], patch: { estimatePoints: 2 } });
expect(res.status).toBe(200);
expect((await asOwner.issues({ issueId: second.id }).get()).data).toMatchObject({
estimatePoints: 2,
});
});
});
describe('delete', () => {
it('deletes the issue', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const del = await asOwner.issues({ issueId: issue.id }).delete();
expect(del.status).toBe(204);
const gone = await asOwner.issues({ issueId: issue.id }).get();
expect(gone.status).toBe(404);
const list = await issuesOf(asOwner);
expect(list.map((i) => i.id)).not.toContain(issue.id);
});
it('returns 404 for a missing issue', async () => {
const { asOwner } = await setupProject();
const res = await asOwner.issues({ issueId: 999999 }).delete();
expect(res.status).toBe(404);
});
});
// POST /issues/:issueId/archive hides the issue from the board (kept, restorable);
// POST /issues/:issueId/restore brings it back. Archived issues are excluded from
// the project view's `issues` and listed by GET /projects/:projectKey/issues/archived.
describe('archive', () => {
async function archivedOf(client: Api, projectKey = 'MKT') {
const res = await client.projects({ projectKey }).issues.archived.get();
return res.data!;
}
it('archives an issue: off the board, on the archived list, archivedAt set', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner.issues({ issueId: issue.id }).archive.post();
expect(res.status).toBe(200);
expect(res.data?.archivedAt).toBeTruthy();
expect((await issuesOf(asOwner)).map((i) => i.id)).not.toContain(issue.id);
expect((await archivedOf(asOwner)).map((i) => i.id)).toContain(issue.id);
});
it('restores an archived issue back onto the board', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
await asOwner.issues({ issueId: issue.id }).archive.post();
const res = await asOwner.issues({ issueId: issue.id }).restore.post();
expect(res.status).toBe(200);
expect(res.data?.archivedAt).toBeNull();
expect((await issuesOf(asOwner)).map((i) => i.id)).toContain(issue.id);
expect((await archivedOf(asOwner)).map((i) => i.id)).not.toContain(issue.id);
});
it('records an archived entry in the feed', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
await asOwner.issues({ issueId: issue.id }).archive.post();
const res = await asOwner.issues({ issueId: issue.id }).feed.get({ query: {} });
expect(res.data?.items.some((i) => i.action === 'archived')).toBe(true);
});
it('returns 404 archiving a missing issue', async () => {
const { asOwner } = await setupProject();
const res = await asOwner.issues({ issueId: 999999 }).archive.post();
expect(res.status).toBe(404);
});
it('denies archive to a non-member with 403', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const outsider = authedApi((await signUpTestUser()).cookie);
const res = await outsider.issues({ issueId: issue.id }).archive.post();
expect(res.status).toBe(403);
});
});
// PUT /issues/:issueId/fields/:fieldId sets one custom field's value. Read back
// through GET /issues/:issueId (the `fields` array).
describe('custom field values', () => {
async function fieldValue(client: Api, issueId: number, fieldId: number) {
const res = await client.issues({ issueId }).get();
return res.data?.fields.find((f) => f.fieldId === fieldId);
}
// A project-wide field (no issueTypeId) of a second project, which must stay
// invisible to the issues of the first one.
async function foreignField(client: Api) {
await createProject(client, { key: 'OPS', name: 'Operations' });
const res = await client
.projects({ projectKey: 'OPS' })
['custom-fields'].post({ name: 'Source URL', fieldType: 'text' });
return res.data!;
}
it('sets a text field value', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Notes', fieldType: 'text' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: 'hello' });
expect(put.status).toBe(200);
expect(put.data).toMatchObject({ ok: true });
expect((await fieldValue(asOwner, issue.id, field.id))?.value).toBe('hello');
});
it('accepts a text value of 50000 characters and rejects a longer one', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Steps', fieldType: 'markdown' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const value = asOwner.issues({ issueId: issue.id }).fields({ fieldId: field.id });
expect((await value.put({ value: 'x'.repeat(50_000) })).status).toBe(200);
expect((await value.put({ value: 'x'.repeat(50_001) })).status).toBe(400);
});
// A member field holds a user id. Which users it offers is its scope: everyone
// the project has, the people only, or the agents only.
async function memberField(
client: Api,
name: string,
memberScope: 'all' | 'humans' | 'agents',
) {
const res = await client
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name, fieldType: 'member', memberScope });
return res.data!;
}
async function createAgentUserId(client: Api) {
const res = await createAgent(client, 'MKT', {
name: 'Bot',
username: 'bot',
kind: 'external',
});
return res.data!.agent.userId;
}
it('sets a member field to a project member', async () => {
const { asOwner, ownerUserId, columnId } = await setupProject();
const field = await memberField(asOwner, 'Reviewer', 'all');
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: ownerUserId });
expect(put.status).toBe(200);
expect((await fieldValue(asOwner, issue.id, field.id))?.value).toBe(ownerUserId);
});
it('clears a member field with a null value', async () => {
const { asOwner, ownerUserId, columnId } = await setupProject();
const field = await memberField(asOwner, 'Reviewer', 'all');
const issue = (await createIssue(asOwner, columnId)).data!;
const fields = asOwner.issues({ issueId: issue.id }).fields({ fieldId: field.id });
await fields.put({ value: ownerUserId });
expect((await fields.put({ value: null })).status).toBe(200);
expect((await fieldValue(asOwner, issue.id, field.id))?.value).toBeNull();
});
it('rejects a member field value that is not a member of the project', async () => {
const { asOwner, columnId } = await setupProject();
const outsider = await signUpTestUser();
const field = await memberField(asOwner, 'Reviewer', 'all');
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: outsider.userId });
expect(put.status).toBe(400);
});
it('rejects an agent in a field scoped to the people', async () => {
const { asOwner, columnId } = await setupProject();
const agentUserId = await createAgentUserId(asOwner);
const field = await memberField(asOwner, 'Reviewer', 'humans');
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: agentUserId });
expect(put.status).toBe(400);
});
it('rejects a member in a field scoped to the agents', async () => {
const { asOwner, ownerUserId, columnId } = await setupProject();
const field = await memberField(asOwner, 'Runner', 'agents');
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: ownerUserId });
expect(put.status).toBe(400);
});
it('accepts an agent in a field scoped to the agents', async () => {
const { asOwner, columnId } = await setupProject();
const agentUserId = await createAgentUserId(asOwner);
const field = await memberField(asOwner, 'Runner', 'agents');
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: agentUserId });
expect(put.status).toBe(200);
expect((await fieldValue(asOwner, issue.id, field.id))?.value).toBe(agentUserId);
});
it("sets a select field's option ids", async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner.projects({ projectKey: 'MKT' })['custom-fields'].post({
name: 'Priority',
fieldType: 'select',
options: ['Low', 'High'],
})
).data!;
const optionId = field.options[1].id;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ optionIds: [optionId] });
expect(put.status).toBe(200);
expect((await fieldValue(asOwner, issue.id, field.id))?.optionIds).toEqual([optionId]);
});
it('stores and reads back a number field value', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Points', fieldType: 'number' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: 8 });
expect(put.status).toBe(200);
// The number column stores a string. The service coerces it back to a number.
expect((await fieldValue(asOwner, issue.id, field.id))?.value).toBe(8);
});
it('stores and reads back a boolean field value', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Done', fieldType: 'boolean' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: true });
expect(put.status).toBe(200);
expect((await fieldValue(asOwner, issue.id, field.id))?.value).toBe(true);
});
// Treaty revives an ISO datetime into a Date, so the moment is compared, not
// the shape it arrives in.
function asIso(value: unknown): string {
return new Date(value as string).toISOString();
}
it('stores and reads back a datetime field value', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Kickoff', fieldType: 'datetime' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: '2026-09-16T07:30:00.000Z' });
expect(put.status).toBe(200);
const stored = await fieldValue(asOwner, issue.id, field.id);
expect(asIso(stored?.value)).toBe('2026-09-16T07:30:00.000Z');
expect(stored?.valueEnd).toBeNull();
});
it('stores and reads back both ends of a datetime range', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Slot', fieldType: 'datetime_range' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: '2026-09-16T07:30:00.000Z', valueEnd: '2026-09-16T09:30:00.000Z' });
expect(put.status).toBe(200);
const stored = await fieldValue(asOwner, issue.id, field.id);
expect(asIso(stored?.value)).toBe('2026-09-16T07:30:00.000Z');
expect(asIso(stored?.valueEnd)).toBe('2026-09-16T09:30:00.000Z');
});
it('rejects an unparseable datetime', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Kickoff', fieldType: 'datetime' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: 'not-a-datetime' });
expect(put.status).toBe(400);
});
it('rejects a datetime without a time of day', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Kickoff', fieldType: 'datetime' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: '2026-09-16' });
expect(put.status).toBe(400);
});
it('rejects a range whose end is not after its start', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Slot', fieldType: 'datetime_range' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const fields = asOwner.issues({ issueId: issue.id }).fields({ fieldId: field.id });
const equal = await fields.put({
value: '2026-09-16T07:30:00.000Z',
valueEnd: '2026-09-16T07:30:00.000Z',
});
expect(equal.status).toBe(400);
const before = await fields.put({
value: '2026-09-16T07:30:00.000Z',
valueEnd: '2026-09-16T06:30:00.000Z',
});
expect(before.status).toBe(400);
});
it('rejects a range end without a start', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Slot', fieldType: 'datetime_range' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: null, valueEnd: '2026-09-16T09:30:00.000Z' });
expect(put.status).toBe(400);
});
it('clears both ends of a datetime range when set to null', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Slot', fieldType: 'datetime_range' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const fields = asOwner.issues({ issueId: issue.id }).fields({ fieldId: field.id });
await fields.put({
value: '2026-09-16T07:30:00.000Z',
valueEnd: '2026-09-16T09:30:00.000Z',
});
const cleared = await fields.put({ value: null });
expect(cleared.status).toBe(200);
const stored = await fieldValue(asOwner, issue.id, field.id);
expect(stored?.value).toBeNull();
expect(stored?.valueEnd).toBeNull();
});
it('clears a field value when set to null', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Notes', fieldType: 'text' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const fields = asOwner.issues({ issueId: issue.id }).fields({ fieldId: field.id });
await fields.put({ value: 'set' });
expect((await fieldValue(asOwner, issue.id, field.id))?.value).toBe('set');
const cleared = await fields.put({ value: null });
expect(cleared.status).toBe(200);
expect((await fieldValue(asOwner, issue.id, field.id))?.value).toBeNull();
});
it('rejects an invalid number for a number field', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Points', fieldType: 'number' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: 'not-a-number' });
expect(put.status).toBe(400);
});
it('rejects a non-http url for a url field', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner
.projects({ projectKey: 'MKT' })
['custom-fields'].post({ name: 'Link', fieldType: 'url' })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: 'javascript:alert(1)' });
expect(put.status).toBe(400);
});
it('rejects an option id of another field and keeps the current selection', async () => {
const { asOwner, columnId } = await setupProject();
const customFields = asOwner.projects({ projectKey: 'MKT' })['custom-fields'];
const target = (
await customFields.post({
name: 'Priority',
fieldType: 'select',
options: ['Low', 'High'],
})
).data!;
const other = (
await customFields.post({ name: 'Stage', fieldType: 'select', options: ['Draft'] })
).data!;
const issue = (await createIssue(asOwner, columnId)).data!;
await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: target.id })
.put({ optionIds: [target.options[0].id] });
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: target.id })
.put({ optionIds: [other.options[0].id] });
expect(put.status).toBe(400);
expect((await fieldValue(asOwner, issue.id, target.id))?.optionIds).toEqual([
target.options[0].id,
]);
});
it("omits another project's field from the issue", async () => {
const { asOwner, columnId } = await setupProject();
const foreign = await foreignField(asOwner);
const issue = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner.issues({ issueId: issue.id }).get();
expect(res.status).toBe(200);
expect(res.data?.fields.map((f) => f.fieldId)).not.toContain(foreign.id);
});
it("returns 404 setting another project's field", async () => {
const { asOwner, columnId } = await setupProject();
const foreign = await foreignField(asOwner);
const issue = (await createIssue(asOwner, columnId)).data!;
const put = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: foreign.id })
.put({ value: 'hello' });
expect(put.status).toBe(404);
});
it('rejects a non-numeric field id', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: 'abc' as unknown as number })
.put({ value: 'x' });
expect(res.status).toBe(400);
});
});
describe('board', () => {
it('returns the active issues for a member', async () => {
const { asOwner, columnId } = await setupProject();
await createIssue(asOwner, columnId, { title: 'Task' });
const res = await asOwner.projects({ projectKey: 'MKT' }).issues.board.get();
expect(res.status).toBe(200);
expect(res.data?.issues).toHaveLength(1);
expect(res.data?.issues[0]).toMatchObject({ title: 'Task' });
});
it('denies a non-member with 403', async () => {
await setupProject();
const outsider = authedApi((await signUpTestUser()).cookie);
const res = await outsider.projects({ projectKey: 'MKT' }).issues.board.get();
expect(res.status).toBe(403);
});
});
describe('search', () => {
// GET /projects/:projectKey/issues/search — the light search behind the command
// palette. Returns IssueSearchHit rows (no description/field values).
function search(client: Api, query: Record<string, string | number>, projectKey = 'MKT') {
return client.projects({ projectKey }).issues.search.get({ query });
}
it('returns the estimate in points', async () => {
const { asOwner, columnId } = await setupProject();
await createIssue(asOwner, columnId, { title: 'Zephyr rollout', estimatePoints: 3 });
const res = await search(asOwner, { q: 'zephyr' });
expect(res.data![0]).toMatchObject({ title: 'Zephyr rollout', estimatePoints: 3 });
});
it('matches by title and excludes non-matching issues', async () => {
const { asOwner, columnId } = await setupProject();
const hit = (await createIssue(asOwner, columnId, { title: 'Zephyr rollout' })).data!;
await createIssue(asOwner, columnId, { title: 'Unrelated task' });
const res = await search(asOwner, { q: 'zephyr' });
expect(res.status).toBe(200);
expect(res.data!.map((i) => i.id)).toEqual([hit.id]);
expect(res.data![0]).toMatchObject({ identifier: hit.identifier, archived: false });
});
it('matches by description', async () => {
const { asOwner, columnId } = await setupProject();
const hit = (
await createIssue(asOwner, columnId, {
title: 'Plain',
description: 'contains quokka word',
})
).data!;
await createIssue(asOwner, columnId, { title: 'Other' });
const res = await search(asOwner, { q: 'quokka' });
expect(res.data!.map((i) => i.id)).toEqual([hit.id]);
});
it('always includes archived issues, flagged as archived', async () => {
const { asOwner, columnId } = await setupProject();
const hit = (await createIssue(asOwner, columnId, { title: 'Zephyr rollout' })).data!;
await asOwner.issues({ issueId: hit.id }).archive.post();
const res = await search(asOwner, { q: 'zephyr' });
expect(res.status).toBe(200);
expect(res.data!.map((i) => i.id)).toEqual([hit.id]);
expect(res.data![0]).toMatchObject({ archived: true });
});
it('matches by issue number, plainly and as KEY-42, but not another key', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId, { title: 'Numbered' })).data!;
const seq = issue.sequenceNumber;
expect((await search(asOwner, { q: String(seq) })).data!.map((i) => i.id)).toContain(
issue.id,
);
expect((await search(asOwner, { q: `MKT-${seq}` })).data!.map((i) => i.id)).toContain(
issue.id,
);
// A different project key does not match the number.
expect((await search(asOwner, { q: `OTHER-${seq}` })).data!.map((i) => i.id)).not.toContain(
issue.id,
);
});
it('matches by a scalar custom field text value', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner.projects({ projectKey: 'MKT' })['custom-fields'].post({
name: 'Notes',
fieldType: 'text',
})
).data!;
const issue = (await createIssue(asOwner, columnId, { title: 'Plain title' })).data!;
await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ value: 'narwhal note' });
const res = await search(asOwner, { q: 'narwhal' });
expect(res.data!.map((i) => i.id)).toEqual([issue.id]);
});
it('matches by a select option label', async () => {
const { asOwner, columnId } = await setupProject();
const field = (
await asOwner.projects({ projectKey: 'MKT' })['custom-fields'].post({
name: 'Severity',
fieldType: 'select',
options: ['Trivial', 'Critical'],
})
).data!;
const issue = (await createIssue(asOwner, columnId, { title: 'Plain title' })).data!;
await asOwner
.issues({ issueId: issue.id })
.fields({ fieldId: field.id })
.put({ optionIds: [field.options[1].id] });
const res = await search(asOwner, { q: 'critical' });
expect(res.data!.map((i) => i.id)).toEqual([issue.id]);
});
it('caps the result count at limit', async () => {
const { asOwner, columnId } = await setupProject();
for (let i = 0; i < 3; i++) await createIssue(asOwner, columnId, { title: `Item ${i}` });
const res = await search(asOwner, { q: 'item', limit: 2 });
expect(res.data!.length).toBe(2);
});
it('matches LIKE metacharacters literally', async () => {
const { asOwner, columnId } = await setupProject();
const hit = (await createIssue(asOwner, columnId, { title: '50% off deal' })).data!;
await createIssue(asOwner, columnId, { title: 'no discount' });
const res = await search(asOwner, { q: '50%' });
expect(res.data!.map((i) => i.id)).toEqual([hit.id]);
});
it('does not find issues from another project', async () => {
const { asOwner, columnId } = await setupProject();
await createIssue(asOwner, columnId, { title: 'Kestrel here' });
await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const opsCols = (await asOwner.projects({ projectKey: 'OPS' }).get()).data!.columns;
await asOwner
.projects({ projectKey: 'OPS' })
.issues.post({ columnId: opsCols[0].id, title: 'Kestrel there' });
const res = await search(asOwner, { q: 'kestrel' });
expect(res.data!.every((i) => i.identifier.startsWith('MKT-'))).toBe(true);
expect(res.data!.length).toBe(1);
});
it('denies a non-member', async () => {
const { asOwner, columnId } = await setupProject();
await createIssue(asOwner, columnId, { title: 'Secret' });
const outsider = authedApi((await signUpTestUser()).cookie);
expect((await search(outsider, { q: 'secret' })).status).toBe(403);
});
});
describe('list (filters)', () => {
// GET /projects/:projectKey/issues — the filtered list (no text query). Same
// IssueSearchHit rows as search.
function list(client: Api, query: Record<string, string | number> = {}, projectKey = 'MKT') {
return client.projects({ projectKey }).issues.get({ query });
}
it('lists active issues by default and excludes archived', async () => {
const { asOwner, columnId } = await setupProject();
const active = (await createIssue(asOwner, columnId, { title: 'Active' })).data!;
const gone = (await createIssue(asOwner, columnId, { title: 'Archived one' })).data!;
await asOwner.issues({ issueId: gone.id }).archive.post();
const res = await list(asOwner);
expect(res.status).toBe(200);
const ids = res.data!.map((i) => i.id);
expect(ids).toContain(active.id);
expect(ids).not.toContain(gone.id);
});
it('includes archived when includeArchived is set', async () => {
const { asOwner, columnId } = await setupProject();
const gone = (await createIssue(asOwner, columnId, { title: 'Archived one' })).data!;
await asOwner.issues({ issueId: gone.id }).archive.post();
const res = await list(asOwner, { includeArchived: 'true' });
expect(res.data!.map((i) => i.id)).toContain(gone.id);
expect(res.data!.find((i) => i.id === gone.id)?.archived).toBe(true);
});
it('filters by column id', async () => {
const { asOwner, columnId, columnIds } = await setupProject();
const here = (await createIssue(asOwner, columnId, { title: 'Here' })).data!;
await createIssue(asOwner, columnIds[1], { title: 'Elsewhere' });
const res = await list(asOwner, { columnId });
expect(res.data!.map((i) => i.id)).toContain(here.id);
expect(res.data!.every((i) => i.columnId === columnId)).toBe(true);
});
it('applies the labelIds filter with AND semantics', async () => {
const { asOwner, columnId } = await setupProject();
const a = (await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'a' })).data!;
const b = (await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'b' })).data!;
const both = (await createIssue(asOwner, columnId, { title: 'Both', labelIds: [a.id, b.id] }))
.data!;
const onlyA = (await createIssue(asOwner, columnId, { title: 'OnlyA', labelIds: [a.id] }))
.data!;
const res = await list(asOwner, { labelIds: `${a.id},${b.id}` });
const ids = res.data!.map((i) => i.id);
expect(ids).toContain(both.id);
expect(ids).not.toContain(onlyA.id);
});
// A block is a relation between two issues, which no text search reaches.
describe('blocked', () => {
async function blockedSetup() {
const { asOwner } = await setupProject();
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const column = (stateType: string) =>
view.data!.columns.find((c) => c.stateType === stateType)!.id;
const make = async (title: string, stateType = 'backlog', patch = {}) =>
(await createIssue(asOwner, column(stateType), { title, ...patch })).data!.id;
const block = (blocker: number, held: number) =>
asOwner.issues({ issueId: blocker }).links.post({ targetIssueId: held, kind: 'blocks' });
const blockedTitles = async (query: Record<string, string> = { blocked: 'true' }) =>
(await list(asOwner, query)).data!.map((i) => i.title);
return { asOwner, make, block, blockedTitles };
}
it('lists the issues an open issue blocks, not the blocker or an unlinked issue', async () => {
const { make, block, blockedTitles } = await blockedSetup();
const blocker = await make('Blocker', 'started');
await block(blocker, await make('Held up'));
await make('Free');
expect(await blockedTitles()).toEqual(['Held up']);
});
it('reads the relation from either side', async () => {
const { asOwner, make, blockedTitles } = await blockedSetup();
const blocker = await make('Blocker');
const held = await make('Held up');
await asOwner
.issues({ issueId: held })
.links.post({ targetIssueId: blocker, kind: 'blocked_by' });
expect(await blockedTitles()).toEqual(['Held up']);
});
it('leaves out an issue whose blocker is completed, canceled or archived', async () => {
const { asOwner, make, block, blockedTitles } = await blockedSetup();
await block(await make('Done', 'completed'), await make('After done'));
await block(await make('Dropped', 'canceled'), await make('After dropped'));
const archived = await make('Archived');
await block(archived, await make('After archived'));
await asOwner.issues({ issueId: archived }).archive.post();
expect(await blockedTitles()).toEqual([]);
});
it('keeps an issue that one of its blockers still holds up', async () => {
const { make, block, blockedTitles } = await blockedSetup();
const held = await make('Held up');
await block(await make('Done', 'completed'), held);
await block(await make('Open'), held);
expect(await blockedTitles()).toEqual(['Held up']);
});
it('combines with the other filters', async () => {
const { make, block, blockedTitles } = await blockedSetup();
const blocker = await make('Blocker');
await block(blocker, await make('Held up'));
const urgent = await make('Held up, urgent', 'backlog', { priority: 'urgent' });
await block(blocker, urgent);
expect(await blockedTitles({ blocked: 'true', priority: 'urgent' })).toEqual([
'Held up, urgent',
]);
});
it('does not filter for any other value', async () => {
const { make, block, blockedTitles } = await blockedSetup();
await block(await make('Blocker'), await make('Held up'));
expect((await blockedTitles({ blocked: 'false' })).sort()).toEqual(['Blocker', 'Held up']);
expect((await blockedTitles({ blocked: '' })).sort()).toEqual(['Blocker', 'Held up']);
});
});
it('ignores placeholder 0 ids and empty strings (LLM-filled defaults)', async () => {
const { asOwner, columnId } = await setupProject();
const one = (await createIssue(asOwner, columnId, { title: 'Real one' })).data!;
// A tool-calling model tends to fill every optional field: 0 for numeric ids,
// "" for strings. These must mean "any", not a filter on id 0 / empty priority.
const res = await list(asOwner, {
columnId: 0,
typeId: 0,
initiativeId: 0,
priority: '',
});
expect(res.status).toBe(200);
expect(res.data!.map((i) => i.id)).toContain(one.id);
});
it('returns the dates, with completedAt set once the issue is completed', async () => {
const { asOwner, columnId } = await setupProject();
const one = (await createIssue(asOwner, columnId, { title: 'Dated' })).data!;
const before = (await list(asOwner)).data!.find((i) => i.id === one.id)!;
expect(before.createdAt).toBeInstanceOf(Date);
expect(before.updatedAt).toBeInstanceOf(Date);
expect(before.completedAt).toBeNull();
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
const done = view.data!.columns.find((c) => c.stateType === 'completed')!.id;
await asOwner.issues({ issueId: one.id }).patch({ columnId: done });
const after = (await list(asOwner)).data!.find((i) => i.id === one.id)!;
expect(after.completedAt).toBeInstanceOf(Date);
});
it('returns the time, the status time and the parent', async () => {
const { asOwner, columnId, columnIds } = await setupProject();
const parent = (await createIssue(asOwner, columnId, { title: 'Parent' })).data!;
const child = (
await createIssue(asOwner, columnId, {
title: 'Child',
parentId: parent.id,
estimateMinutes: 120,
})
).data!;
const spentOn = new Date().toISOString().slice(0, 10);
await asOwner.issues({ issueId: child.id }).worklogs.post({ minutes: 30, spentOn });
await asOwner.issues({ issueId: child.id }).worklogs.post({ minutes: 15, spentOn });
const before = (await list(asOwner)).data!;
expect(before.find((i) => i.id === parent.id)).toMatchObject({
parent: null,
estimateMinutes: null,
loggedMinutes: 0,
});
const fresh = before.find((i) => i.id === child.id)!;
expect(fresh).toMatchObject({
parent: { id: parent.id, identifier: parent.identifier, title: 'Parent' },
estimateMinutes: 120,
loggedMinutes: 45,
});
const full = async () => (await asOwner.issues({ issueId: child.id }).get()).data!;
expect(fresh.statusSince).toEqual((await full()).statusSince);
await asOwner.issues({ issueId: child.id }).patch({ columnId: columnIds[1] });
const moved = (await list(asOwner)).data!.find((i) => i.id === child.id)!;
expect(moved.statusSince).toEqual((await full()).statusSince);
expect(moved.statusSince).not.toEqual(fresh.statusSince);
});
it('returns the estimate in points, a fraction too', async () => {
const { asOwner, columnId } = await setupProject();
const sized = (await createIssue(asOwner, columnId, { title: 'Sized', estimatePoints: 0.5 }))
.data!;
const bare = (await createIssue(asOwner, columnId, { title: 'Bare' })).data!;
const rows = (await list(asOwner)).data!;
expect(rows.find((i) => i.id === sized.id)).toMatchObject({ estimatePoints: 0.5 });
expect(rows.find((i) => i.id === bare.id)).toMatchObject({ estimatePoints: null });
});
it('filters by created and updated time', async () => {
const { asOwner, columnId } = await setupProject();
const one = (await createIssue(asOwner, columnId, { title: 'Timed' })).data!;
const past = new Date(Date.now() - 60_000).toISOString();
const future = new Date(Date.now() + 60_000).toISOString();
const ids = async (query: Record<string, string>) =>
(await list(asOwner, query)).data!.map((i) => i.id);
expect(await ids({ createdFrom: past, createdTo: future })).toContain(one.id);
expect(await ids({ createdFrom: future })).not.toContain(one.id);
expect(await ids({ updatedFrom: past })).toContain(one.id);
expect(await ids({ updatedTo: past })).not.toContain(one.id);
expect(await ids({ updatedFrom: '' })).toContain(one.id);
});
it('rejects a time filter that does not parse', async () => {
const { asOwner } = await setupProject();
expect((await list(asOwner, { updatedFrom: 'last week' })).status).toBe(400);
});
it('denies a non-member', async () => {
const { asOwner, columnId } = await setupProject();
await createIssue(asOwner, columnId, { title: 'Secret' });
const outsider = authedApi((await signUpTestUser()).cookie);
expect((await list(outsider)).status).toBe(403);
});
});
describe('bulk actions', () => {
it('applies one patch to every listed issue', async () => {
const { asOwner, columnId, columnIds } = await setupProject();
const a = (await createIssue(asOwner, columnId)).data!;
const b = (await createIssue(asOwner, columnId)).data!;
const target = columnIds[2];
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.patch({ ids: [a.id, b.id], patch: { columnId: target } });
expect(res.status).toBe(200);
expect(res.data).toMatchObject({ updated: 2 });
const list = await issuesOf(asOwner);
expect(list.find((i) => i.id === a.id)?.columnId).toBe(target);
expect(list.find((i) => i.id === b.id)?.columnId).toBe(target);
});
it('adds labels to every listed issue, keeping existing ones', async () => {
const { asOwner, columnId } = await setupProject();
const a = (await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'a' })).data!;
const b = (await asOwner.projects({ projectKey: 'MKT' }).labels.post({ name: 'b' })).data!;
const one = (await createIssue(asOwner, columnId, { labelIds: [a.id] })).data!;
const two = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.labels.post({ ids: [one.id, two.id], add: [b.id] });
expect(res.status).toBe(200);
expect(res.data).toMatchObject({ updated: 2 });
const list = await issuesOf(asOwner);
expect(list.find((i) => i.id === one.id)?.labelIds.sort()).toEqual([a.id, b.id].sort());
expect(list.find((i) => i.id === two.id)?.labelIds).toEqual([b.id]);
});
it("rejects a bulk move to another project's column", async () => {
const { asOwner, columnId } = await setupProject();
const foreign = await foreignProject(asOwner);
const issue = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.patch({ ids: [issue.id], patch: { columnId: foreign.columnId } });
expect(res.status).toBe(400);
const list = await issuesOf(asOwner);
expect(list.find((i) => i.id === issue.id)?.columnId).toBe(columnId);
});
it("does not reveal another project's full column through the WIP check", async () => {
const { asOwner, columnId } = await setupProject();
const foreign = await foreignProject(asOwner);
await asOwner
.projects({ projectKey: 'OPS' })
.issues.post({ columnId: foreign.columnId, title: 'Occupant' });
await asOwner
.projects({ projectKey: 'OPS' })
.columns({ columnId: foreign.columnId })
.patch({ name: 'Ops Secret Lane', wipLimit: 1, wipMode: 'hard' });
const issue = (await createIssue(asOwner, columnId)).data!;
// The column check runs before the WIP check, so a full foreign column is
// refused as a foreign column, not as a full one.
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.patch({ ids: [issue.id], patch: { columnId: foreign.columnId } });
expect(res.status).toBe(400);
expect(JSON.stringify(res.error?.value)).not.toContain('Ops Secret Lane');
});
it("rejects a bulk add of another project's label", async () => {
const { asOwner, columnId } = await setupProject();
const foreign = await foreignLabel(asOwner);
const issue = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.labels.post({ ids: [issue.id], add: [foreign.id] });
expect(res.status).toBe(400);
const list = await issuesOf(asOwner);
expect(list.find((i) => i.id === issue.id)?.labelIds).toEqual([]);
});
it('archives every listed issue', async () => {
const { asOwner, columnId } = await setupProject();
const a = (await createIssue(asOwner, columnId)).data!;
const b = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.archive.post({ ids: [a.id, b.id] });
expect(res.status).toBe(200);
expect(res.data).toMatchObject({ archived: 2 });
const list = await issuesOf(asOwner);
expect(list.map((i) => i.id)).not.toContain(a.id);
expect(list.map((i) => i.id)).not.toContain(b.id);
});
it('deletes every listed issue', async () => {
const { asOwner, columnId } = await setupProject();
const a = (await createIssue(asOwner, columnId)).data!;
const b = (await createIssue(asOwner, columnId)).data!;
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.delete.post({ ids: [a.id, b.id] });
expect(res.status).toBe(200);
expect(res.data).toMatchObject({ deleted: 2 });
expect((await asOwner.issues({ issueId: a.id }).get()).status).toBe(404);
expect((await asOwner.issues({ issueId: b.id }).get()).status).toBe(404);
});
it('ignores ids that belong to another project', async () => {
const { asOwner, columnId } = await setupProject();
const mine = (await createIssue(asOwner, columnId)).data!;
// A second project owned by the same user; its issue must not be touched by a
// bulk action scoped to the first project.
await createProject(asOwner, { key: 'OPS', name: 'Ops' });
const opsColumn = (await asOwner.projects({ projectKey: 'OPS' }).get()).data!.columns[0].id;
const foreign = (
await asOwner
.projects({ projectKey: 'OPS' })
.issues.post({ columnId: opsColumn, title: 'X' })
).data!;
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.archive.post({ ids: [mine.id, foreign.id] });
expect(res.data).toMatchObject({ archived: 1 });
// The foreign issue is still on its own board.
expect((await issuesOf(asOwner, 'OPS')).map((i) => i.id)).toContain(foreign.id);
});
it('rejects an empty id list', async () => {
const { asOwner } = await setupProject();
const res = await asOwner
.projects({ projectKey: 'MKT' })
.issues.bulk.patch({ ids: [], patch: { priority: 'high' } });
expect(res.status).toBe(400);
});
it('denies a non-member', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const outsider = authedApi((await signUpTestUser()).cookie);
expect(
(
await outsider
.projects({ projectKey: 'MKT' })
.issues.bulk.patch({ ids: [issue.id], patch: { priority: 'high' } })
).status,
).toBe(403);
expect(
(
await outsider
.projects({ projectKey: 'MKT' })
.issues.bulk.delete.post({ ids: [issue.id] })
).status,
).toBe(403);
});
});
describe('access', () => {
it('denies a non-member on every issue route', async () => {
const { asOwner, columnId } = await setupProject();
const issue = (await createIssue(asOwner, columnId)).data!;
const outsider = authedApi((await signUpTestUser()).cookie);
// Guard-thrown 403 is not in Treaty's inferred error-status union, so assert
// the top-level HTTP status rather than error.status.
expect(
(await outsider.projects({ projectKey: 'MKT' }).issues.post({ columnId, title: 'X' }))
.status,
).toBe(403);
expect((await outsider.issues({ issueId: issue.id }).get()).status).toBe(403);
expect((await outsider.issues({ issueId: issue.id }).patch({ title: 'X' })).status).toBe(403);
expect((await outsider.issues({ issueId: issue.id }).delete()).status).toBe(403);
});
});
});