fix(support-cases): prevent crash when auto-triage encounters undefined tags
- supportCase.tags is optional in SupportCaseDoc schema - Spreading undefined throws TypeError at runtime - Fixed both [...supportCase.tags] and .includes() call with ?? [] fallback - Added regression test for undefined tags case - 9 support-cases tests passing
This commit is contained in:
parent
63322a2d07
commit
f3a4d915f5
@ -225,6 +225,30 @@ describe('supportCaseRoutes', () => {
|
|||||||
expect(body.tagsAdded).toContain('category:billing');
|
expect(body.tagsAdded).toContain('category:billing');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('POST /support/cases/:id/auto-triage handles undefined tags gracefully', async () => {
|
||||||
|
repoMock.getCase.mockResolvedValue({
|
||||||
|
id: 'sup_3',
|
||||||
|
productId: 'lysnrai',
|
||||||
|
title: 'Slow dashboard loading',
|
||||||
|
description: 'Pages take 10s to load',
|
||||||
|
priority: 'low',
|
||||||
|
// tags intentionally omitted — undefined
|
||||||
|
});
|
||||||
|
repoMock.updateCase.mockImplementation(
|
||||||
|
async (_id: string, _pid: string, updates: Record<string, unknown>) => ({
|
||||||
|
...updates,
|
||||||
|
id: 'sup_3',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const app = await buildApp({ sub: 'admin_1', productId: 'lysnrai', role: 'admin' });
|
||||||
|
|
||||||
|
const res = await app.inject({ method: 'POST', url: '/api/support/cases/sup_3/auto-triage' });
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
const body = res.json();
|
||||||
|
expect(body.newPriority).toBe('medium');
|
||||||
|
expect(body.tagsAdded).toContain('auto-triaged:medium');
|
||||||
|
});
|
||||||
|
|
||||||
// ── Case Metrics ───────────────────────────────────────
|
// ── Case Metrics ───────────────────────────────────────
|
||||||
|
|
||||||
it('GET /support/metrics returns case metrics with SLA compliance', async () => {
|
it('GET /support/metrics returns case metrics with SLA compliance', async () => {
|
||||||
|
|||||||
@ -254,7 +254,7 @@ export async function supportCaseRoutes(app: FastifyInstance) {
|
|||||||
const text = `${supportCase.title} ${supportCase.description ?? ''}`.toLowerCase();
|
const text = `${supportCase.title} ${supportCase.description ?? ''}`.toLowerCase();
|
||||||
|
|
||||||
let suggestedPriority: string = supportCase.priority;
|
let suggestedPriority: string = supportCase.priority;
|
||||||
const tags = [...supportCase.tags];
|
const tags = [...(supportCase.tags ?? [])];
|
||||||
|
|
||||||
// Priority heuristics
|
// Priority heuristics
|
||||||
if (text.includes('outage') || text.includes('production down') || text.includes('data loss')) {
|
if (text.includes('outage') || text.includes('production down') || text.includes('data loss')) {
|
||||||
@ -293,7 +293,7 @@ export async function supportCaseRoutes(app: FastifyInstance) {
|
|||||||
triaged: true,
|
triaged: true,
|
||||||
previousPriority: supportCase.priority,
|
previousPriority: supportCase.priority,
|
||||||
newPriority: suggestedPriority,
|
newPriority: suggestedPriority,
|
||||||
tagsAdded: dedupedTags.filter(t => !supportCase.tags.includes(t)),
|
tagsAdded: dedupedTags.filter(t => !(supportCase.tags ?? []).includes(t)),
|
||||||
case: updated,
|
case: updated,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user