@@ -16,6 +16,7 @@ import {
1616 ensureYamlExtension ,
1717 getMetadataFilePaths ,
1818 getPluginsAndFunctions ,
19+ createCustomEvaluation ,
1920} from '../../../../src/commands/agent/generate/test-spec.js' ;
2021
2122describe ( 'AgentGenerateTestSpec Helper Methods' , ( ) => {
@@ -378,4 +379,80 @@ describe('AgentGenerateTestSpec Helper Methods', () => {
378379 expect ( result ) . to . not . have . property ( '*' ) ;
379380 } ) ;
380381 } ) ;
382+
383+ describe ( 'createCustomEvaluation' , ( ) => {
384+ it ( 'should create correct structure for string comparison' , ( ) => {
385+ const evaluation = createCustomEvaluation ( 'Test Label' , '$.response.message' , 'equals' , 'expected text' ) ;
386+
387+ expect ( evaluation ) . to . deep . equal ( {
388+ label : 'Test Label' ,
389+ name : 'string_comparison' ,
390+ parameters : [
391+ { name : 'operator' , value : 'equals' , isReference : false } ,
392+ { name : 'actual' , value : '$.response.message' , isReference : true } ,
393+ { name : 'expected' , value : 'expected text' , isReference : false } ,
394+ ] ,
395+ } ) ;
396+ } ) ;
397+
398+ it ( 'should create correct structure for numeric comparison' , ( ) => {
399+ const evaluation = createCustomEvaluation ( 'Numeric Test' , '$.metrics.score' , 'greater_than_or_equal' , '85' ) ;
400+
401+ expect ( evaluation ) . to . deep . equal ( {
402+ label : 'Numeric Test' ,
403+ name : 'numeric_comparison' ,
404+ parameters : [
405+ { name : 'operator' , value : 'greater_than_or_equal' , isReference : false } ,
406+ { name : 'actual' , value : '$.metrics.score' , isReference : true } ,
407+ { name : 'expected' , value : '85' , isReference : false } ,
408+ ] ,
409+ } ) ;
410+ } ) ;
411+
412+ it ( 'should handle all supported operators' , ( ) => {
413+ const operators = [ 'equals' , 'greater_than_or_equal' , 'greater_than' , 'less_than' , 'less_than_or_equal' ] ;
414+
415+ operators . forEach ( ( operator ) => {
416+ const evaluation = createCustomEvaluation ( `Test ${ operator } ` , '$.test.value' , operator , '100' ) ;
417+
418+ expect ( evaluation . parameters [ 0 ] ) . to . deep . equal ( {
419+ name : 'operator' ,
420+ value : operator ,
421+ isReference : false ,
422+ } ) ;
423+ } ) ;
424+ } ) ;
425+
426+ it ( 'should always set correct isReference flags' , ( ) => {
427+ const evaluation = createCustomEvaluation ( 'Reference Test' , '$.actual.path' , 'equals' , 'expected' ) ;
428+
429+ const [ operatorParam , actualParam , expectedParam ] = evaluation . parameters ;
430+
431+ expect ( operatorParam . isReference ) . to . be . false ;
432+ expect ( actualParam . isReference ) . to . be . true ; // actual is always a reference (JSONPath)
433+ expect ( expectedParam . isReference ) . to . be . false ; // expected is always a literal value
434+ } ) ;
435+
436+ it ( 'should correctly determine comparison type based on expected value' , ( ) => {
437+ const numericEvaluation = createCustomEvaluation ( 'Test' , '$.path' , 'equals' , '42' ) ;
438+ expect ( numericEvaluation . name ) . to . equal ( 'numeric_comparison' ) ;
439+
440+ const stringEvaluation = createCustomEvaluation ( 'Test' , '$.path' , 'equals' , 'text' ) ;
441+ expect ( stringEvaluation . name ) . to . equal ( 'string_comparison' ) ;
442+ } ) ;
443+
444+ it ( 'should handle complex JSONPaths and values' , ( ) => {
445+ const evaluation = createCustomEvaluation (
446+ 'Complex Test' ,
447+ '$.response.data[0].nested["special-key"].value' ,
448+ 'less_than' ,
449+ '3.14159'
450+ ) ;
451+
452+ expect ( evaluation . label ) . to . equal ( 'Complex Test' ) ;
453+ expect ( evaluation . name ) . to . equal ( 'numeric_comparison' ) ;
454+ expect ( evaluation . parameters [ 1 ] . value ) . to . equal ( '$.response.data[0].nested["special-key"].value' ) ;
455+ expect ( evaluation . parameters [ 2 ] . value ) . to . equal ( '3.14159' ) ;
456+ } ) ;
457+ } ) ;
381458} ) ;
0 commit comments