@@ -31,6 +31,7 @@ import {
3131 createLightweightMonitors ,
3232 diffMonitors ,
3333 parseAlertConfig ,
34+ parseFields ,
3435 parseSchedule ,
3536} from '../../src/push/monitor' ;
3637import { Server } from '../utils/server' ;
@@ -621,4 +622,59 @@ heartbeat.monitors:
621622 expect ( config ) . toEqual ( { } ) ;
622623 } ) ;
623624 } ) ;
625+
626+ describe ( 'parseFields' , ( ) => {
627+ it ( 'extracts fields from config and removes them' , ( ) => {
628+ const config = {
629+ 'fields.label1' : 'value1' ,
630+ 'fields.label2' : 'value2' ,
631+ otherKey : 'otherValue' ,
632+ } ;
633+
634+ const result = parseFields ( config as any ) ;
635+
636+ expect ( result ) . toEqual ( { label1 : 'value1' , label2 : 'value2' } ) ;
637+ expect ( config ) . toEqual ( { otherKey : 'otherValue' } ) ; // Ensure fields were deleted
638+ } ) ;
639+
640+ it ( 'merges global fields into parsed fields' , ( ) => {
641+ const config = {
642+ 'fields.label1' : 'value1' ,
643+ } ;
644+ const gFields = {
645+ label2 : 'globalValue' ,
646+ label3 : 'anotherGlobalValue' ,
647+ } ;
648+
649+ const result = parseFields ( config as any , gFields ) ;
650+
651+ expect ( result ) . toEqual ( {
652+ label1 : 'value1' ,
653+ label2 : 'globalValue' ,
654+ label3 : 'anotherGlobalValue' ,
655+ } ) ;
656+ } ) ;
657+
658+ it ( 'returns only global fields if no config fields exist' , ( ) => {
659+ const config = {
660+ otherKey : 'otherValue' ,
661+ } ;
662+ const gFields = {
663+ label1 : 'globalValue' ,
664+ } ;
665+
666+ const result = parseFields ( config as any , gFields ) ;
667+
668+ expect ( result ) . toEqual ( { label1 : 'globalValue' } ) ;
669+ } ) ;
670+
671+ it ( 'returns undefined if no fields exist' , ( ) => {
672+ const config = {
673+ otherKey : 'otherValue' ,
674+ } ;
675+ const result = parseFields ( config as any ) ;
676+
677+ expect ( result ) . toBeUndefined ( ) ;
678+ } ) ;
679+ } ) ;
624680} ) ;
0 commit comments