diff --git a/services/platform-service/src/modules/support-cases/routes.test.ts b/services/platform-service/src/modules/support-cases/routes.test.ts index ddba2d94..f3ccc5c3 100644 --- a/services/platform-service/src/modules/support-cases/routes.test.ts +++ b/services/platform-service/src/modules/support-cases/routes.test.ts @@ -225,6 +225,30 @@ describe('supportCaseRoutes', () => { 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) => ({ + ...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 ─────────────────────────────────────── it('GET /support/metrics returns case metrics with SLA compliance', async () => { diff --git a/services/platform-service/src/modules/support-cases/routes.ts b/services/platform-service/src/modules/support-cases/routes.ts index 4aae81f0..a7f9e647 100644 --- a/services/platform-service/src/modules/support-cases/routes.ts +++ b/services/platform-service/src/modules/support-cases/routes.ts @@ -254,7 +254,7 @@ export async function supportCaseRoutes(app: FastifyInstance) { const text = `${supportCase.title} ${supportCase.description ?? ''}`.toLowerCase(); let suggestedPriority: string = supportCase.priority; - const tags = [...supportCase.tags]; + const tags = [...(supportCase.tags ?? [])]; // Priority heuristics if (text.includes('outage') || text.includes('production down') || text.includes('data loss')) { @@ -293,7 +293,7 @@ export async function supportCaseRoutes(app: FastifyInstance) { triaged: true, previousPriority: supportCase.priority, newPriority: suggestedPriority, - tagsAdded: dedupedTags.filter(t => !supportCase.tags.includes(t)), + tagsAdded: dedupedTags.filter(t => !(supportCase.tags ?? []).includes(t)), case: updated, }; });