diff --git a/packages/api/src/routers/external-api/__tests__/dashboards.test.ts b/packages/api/src/routers/external-api/__tests__/dashboards.test.ts index 4d8cbb7d44..3f9c075b23 100644 --- a/packages/api/src/routers/external-api/__tests__/dashboards.test.ts +++ b/packages/api/src/routers/external-api/__tests__/dashboards.test.ts @@ -2573,6 +2573,66 @@ describe('External API v2 Dashboards - new format', () => { ); }); + it('persists where as empty string when omitted from heatmap tile', async () => { + const heatmapNoWhere = { + name: 'Heatmap Without Where', + x: 0, + y: 0, + w: 6, + h: 3, + config: { + displayType: 'heatmap', + sourceId: traceSource._id.toString(), + select: [{ valueExpression: 'Duration' }], + }, + }; + + const response = await authRequest('post', BASE_URL) + .send({ + name: 'Dashboard Heatmap No Where', + tiles: [heatmapNoWhere], + tags: [], + }) + .expect(200); + + const dashboardInDb = await Dashboard.findById( + response.body.data.id, + ).lean(); + + expect((dashboardInDb!.tiles[0].config as any).where).toBe(''); + }); + + it('persists select-item where as empty string when omitted', async () => { + const lineChartNoWhere = { + name: 'Line Chart Without Where', + x: 0, + y: 0, + w: 6, + h: 3, + config: { + displayType: 'line', + sourceId: traceSource._id.toString(), + select: [{ aggFn: 'count' }], + }, + }; + + const response = await authRequest('post', BASE_URL) + .send({ + name: 'Dashboard Line No Where', + tiles: [lineChartNoWhere], + tags: [], + }) + .expect(200); + + const dashboardInDb = await Dashboard.findById( + response.body.data.id, + ).lean(); + + expect( + (dashboardInDb!.tiles[0].config as any).select[0].aggCondition, + ).toBe(''); + }); + it('does not silently downgrade a corrupted heatmap to line on GET', async () => { // Seed a Dashboard directly via Mongo with a heatmap tile whose // select[0] lacks a non-empty valueExpression. The current API diff --git a/packages/api/src/routers/external-api/v2/dashboards.ts b/packages/api/src/routers/external-api/v2/dashboards.ts index 5b83bcc41d..9dd32fbead 100644 --- a/packages/api/src/routers/external-api/v2/dashboards.ts +++ b/packages/api/src/routers/external-api/v2/dashboards.ts @@ -4,7 +4,7 @@ import { z } from 'zod'; import { deleteDashboard } from '@/controllers/dashboard'; import Dashboard, { IDashboard } from '@/models/dashboard'; -import { validateRequestWithEnhancedErrors as validateRequest } from '@/utils/enhancedErrors'; +import { processRequestWithEnhancedErrors as validateRequest } from '@/utils/enhancedErrors'; import { ExternalDashboardTileWithId, objectIdSchema } from '@/utils/zod'; import {