fix(support-cases): prevent auto-triage from regressing case status
- Auto-triage previously always set status to 'triaged', even for cases already in in_progress, escalated, or other later states - Now only transitions to 'triaged' if case is still in 'open' state - Cases in later states keep their current status (only priority + tags update) - Added regression test for in_progress case - 10 support-cases tests passing
This commit is contained in:
parent
78cb958a6d
commit
10c288857d
@ -225,6 +225,36 @@ describe('supportCaseRoutes', () => {
|
|||||||
expect(body.tagsAdded).toContain('category:billing');
|
expect(body.tagsAdded).toContain('category:billing');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('POST /support/cases/:id/auto-triage does not regress status of in-progress cases', async () => {
|
||||||
|
repoMock.getCase.mockResolvedValue({
|
||||||
|
id: 'sup_4',
|
||||||
|
productId: 'lysnrai',
|
||||||
|
title: 'Error on login page',
|
||||||
|
description: 'Users see 500',
|
||||||
|
priority: 'medium',
|
||||||
|
status: 'in_progress',
|
||||||
|
tags: [],
|
||||||
|
});
|
||||||
|
repoMock.updateCase.mockImplementation(
|
||||||
|
async (_id: string, _pid: string, updates: Record<string, unknown>) => ({
|
||||||
|
...updates,
|
||||||
|
id: 'sup_4',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const app = await buildApp({ sub: 'admin_1', productId: 'lysnrai', role: 'admin' });
|
||||||
|
|
||||||
|
const res = await app.inject({ method: 'POST', url: '/api/support/cases/sup_4/auto-triage' });
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
const body = res.json();
|
||||||
|
expect(body.newPriority).toBe('high');
|
||||||
|
// Status should remain in_progress, not regress to triaged
|
||||||
|
expect(repoMock.updateCase).toHaveBeenCalledWith(
|
||||||
|
'sup_4',
|
||||||
|
'lysnrai',
|
||||||
|
expect.objectContaining({ status: 'in_progress' })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('POST /support/cases/:id/auto-triage handles undefined tags gracefully', async () => {
|
it('POST /support/cases/:id/auto-triage handles undefined tags gracefully', async () => {
|
||||||
repoMock.getCase.mockResolvedValue({
|
repoMock.getCase.mockResolvedValue({
|
||||||
id: 'sup_3',
|
id: 'sup_3',
|
||||||
|
|||||||
@ -283,9 +283,14 @@ export async function supportCaseRoutes(app: FastifyInstance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dedupedTags = [...new Set(tags)];
|
const dedupedTags = [...new Set(tags)];
|
||||||
|
// Only advance to 'triaged' if still in 'open' state — don't regress later statuses
|
||||||
|
const triageableStatuses = ['open'];
|
||||||
|
const statusUpdate = triageableStatuses.includes(supportCase.status)
|
||||||
|
? 'triaged'
|
||||||
|
: supportCase.status;
|
||||||
const updated = await repo.updateCase(id, access.productId, {
|
const updated = await repo.updateCase(id, access.productId, {
|
||||||
priority: suggestedPriority as SupportCaseDoc['priority'],
|
priority: suggestedPriority as SupportCaseDoc['priority'],
|
||||||
status: 'triaged',
|
status: statusUpdate,
|
||||||
tags: dedupedTags,
|
tags: dedupedTags,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user