@@ -2,7 +2,11 @@ import _ from 'lodash';
22import { ObjectId } from 'mongodb' ;
33import request from 'supertest' ;
44
5- import { getLoggedInAgent , getServer } from '../../../fixtures' ;
5+ import {
6+ getLoggedInAgent ,
7+ getServer ,
8+ RAW_SQL_ALERT_TEMPLATE ,
9+ } from '../../../fixtures' ;
610import { AlertSource , AlertThresholdType } from '../../../models/alert' ;
711import Alert from '../../../models/alert' ;
812import Dashboard from '../../../models/dashboard' ;
@@ -83,8 +87,13 @@ describe('External API Alerts', () => {
8387 } ;
8488
8589 // Helper to create a dashboard with a raw SQL tile for testing
90+ // Uses Number display type by default (not alertable) for rejection tests
8691 const createTestDashboardWithRawSqlTile = async (
87- options : { teamId ?: any } = { } ,
92+ options : {
93+ teamId ?: any ;
94+ displayType ?: string ;
95+ sqlTemplate ?: string ;
96+ } = { } ,
8897 ) => {
8998 const tileId = new ObjectId ( ) . toString ( ) ;
9099 const tiles = [
@@ -97,8 +106,8 @@ describe('External API Alerts', () => {
97106 h : 3 ,
98107 config : {
99108 configType : 'sql' ,
100- displayType : 'line ',
101- sqlTemplate : 'SELECT 1' ,
109+ displayType : options . displayType ?? 'number ',
110+ sqlTemplate : options . sqlTemplate ?? 'SELECT 1' ,
102111 connection : 'test-connection' ,
103112 } ,
104113 } ,
@@ -716,7 +725,34 @@ describe('External API Alerts', () => {
716725 . expect ( 400 ) ;
717726 } ) ;
718727
719- it ( 'should reject creating an alert on a raw SQL tile' , async ( ) => {
728+ it ( 'should allow creating an alert on a raw SQL line tile' , async ( ) => {
729+ const webhook = await createTestWebhook ( ) ;
730+ const { dashboard, tileId } = await createTestDashboardWithRawSqlTile ( {
731+ displayType : 'line' ,
732+ sqlTemplate : RAW_SQL_ALERT_TEMPLATE ,
733+ } ) ;
734+
735+ const alertInput = {
736+ dashboardId : dashboard . _id . toString ( ) ,
737+ tileId,
738+ threshold : 100 ,
739+ interval : '1h' ,
740+ source : AlertSource . TILE ,
741+ thresholdType : AlertThresholdType . ABOVE ,
742+ channel : {
743+ type : 'webhook' ,
744+ webhookId : webhook . _id . toString ( ) ,
745+ } ,
746+ } ;
747+
748+ const res = await authRequest ( 'post' , ALERTS_BASE_URL )
749+ . send ( alertInput )
750+ . expect ( 200 ) ;
751+ expect ( res . body . data . dashboardId ) . toBe ( dashboard . _id . toString ( ) ) ;
752+ expect ( res . body . data . tileId ) . toBe ( tileId ) ;
753+ } ) ;
754+
755+ it ( 'should reject creating an alert on a raw SQL number tile' , async ( ) => {
720756 const webhook = await createTestWebhook ( ) ;
721757 const { dashboard, tileId } = await createTestDashboardWithRawSqlTile ( ) ;
722758
@@ -736,7 +772,30 @@ describe('External API Alerts', () => {
736772 await authRequest ( 'post' , ALERTS_BASE_URL ) . send ( alertInput ) . expect ( 400 ) ;
737773 } ) ;
738774
739- it ( 'should reject updating an alert to reference a raw SQL tile' , async ( ) => {
775+ it ( 'should reject creating an alert on a raw SQL tile without interval params' , async ( ) => {
776+ const webhook = await createTestWebhook ( ) ;
777+ const { dashboard, tileId } = await createTestDashboardWithRawSqlTile ( {
778+ displayType : 'line' ,
779+ sqlTemplate : 'SELECT count() FROM otel_logs' ,
780+ } ) ;
781+
782+ const alertInput = {
783+ dashboardId : dashboard . _id . toString ( ) ,
784+ tileId,
785+ threshold : 100 ,
786+ interval : '1h' ,
787+ source : AlertSource . TILE ,
788+ thresholdType : AlertThresholdType . ABOVE ,
789+ channel : {
790+ type : 'webhook' ,
791+ webhookId : webhook . _id . toString ( ) ,
792+ } ,
793+ } ;
794+
795+ await authRequest ( 'post' , ALERTS_BASE_URL ) . send ( alertInput ) . expect ( 400 ) ;
796+ } ) ;
797+
798+ it ( 'should reject updating an alert to reference a raw SQL number tile' , async ( ) => {
740799 const { alert, webhook } = await createTestAlert ( ) ;
741800 const { dashboard : rawSqlDashboard , tileId : rawSqlTileId } =
742801 await createTestDashboardWithRawSqlTile ( ) ;
0 commit comments