77
88import { config } from 'dotenv' ;
99import { createDtHttpClient } from '../src/authentication/dynatrace-clients' ;
10- import { findMonitoredEntityByName } from '../src/capabilities/find-monitored-entity-by-name' ;
10+ import { findMonitoredEntitiesByName } from '../src/capabilities/find-monitored-entity-by-name' ;
1111import { getDynatraceEnv , DynatraceEnv } from '../src/getDynatraceEnv' ;
12+ import { getEntityTypeFromId } from '../src/utils/dynatrace-entity-types' ;
1213
1314// Load environment variables
1415config ( ) ;
@@ -60,27 +61,25 @@ describe('Find Monitored Entity by Name Integration Tests', () => {
6061
6162 // Search for an entity name that is very unlikely to exist
6263 const searchTerm = 'this-entity-definitely-does-not-exist-12345' ;
64+ const extendedSearch = false ;
6365
64- const response = await findMonitoredEntityByName ( dtClient , searchTerm ) ;
66+ const response = await findMonitoredEntitiesByName ( dtClient , [ searchTerm ] , extendedSearch ) ;
6567
6668 expect ( response ) . toBeDefined ( ) ;
67- expect ( typeof response ) . toBe ( 'string' ) ;
68- expect ( response ) . toBe ( 'No monitored entity found with the specified name.' ) ;
69+ expect ( response ?. records ) . toBeDefined ( ) ;
70+ expect ( response ?. records ?. length ) . toEqual ( 0 ) ;
6971 } , 30_000 ) ; // Increased timeout for API calls
7072
71- test ( 'should handle search with empty string ' , async ( ) => {
73+ test ( 'should handle search with empty list ' , async ( ) => {
7274 const dtClient = await createHttpClient ( ) ;
7375
7476 // Test with empty string
75- const searchTerm = '' ;
77+ const searchTerms = [ ] as string [ ] ;
78+ const extendedSearch = false ;
7679
77- const response = await findMonitoredEntityByName ( dtClient , searchTerm ) ;
78-
79- expect ( response ) . toBeDefined ( ) ;
80- expect ( typeof response ) . toBe ( 'string' ) ;
81-
82- // Should handle gracefully - likely will return many results or handle empty search
83- expect ( response ) . toContain ( 'You need to provide an entity name to search for' ) ;
80+ await expect ( findMonitoredEntitiesByName ( dtClient , searchTerms , extendedSearch ) ) . rejects . toThrow (
81+ / N o e n t i t y n a m e s s u p p l i e d t o s e a r c h f o r / ,
82+ ) ;
8483 } ) ;
8584
8685 test ( 'should return properly formatted response when entities are found' , async ( ) => {
@@ -89,20 +88,19 @@ describe('Find Monitored Entity by Name Integration Tests', () => {
8988 // Search for a pattern that is likely to find at least one entity
9089 // "host" is common in most Dynatrace environments
9190 const searchTerm = 'host' ;
91+ const extendedSearch = false ;
9292
93- const response = await findMonitoredEntityByName ( dtClient , searchTerm ) ;
93+ const response = await findMonitoredEntitiesByName ( dtClient , [ searchTerm ] , extendedSearch ) ;
9494
95+ // Assert, based on the DqlExecutionResult
9596 expect ( response ) . toBeDefined ( ) ;
96- expect ( typeof response ) . toBe ( 'string' ) ;
97-
98- // If entities are found, check the format
99- if ( response . includes ( 'The following monitored entities were found:' ) ) {
100- // Each line should follow the expected format
101- const lines = response . split ( '\n' ) . filter ( ( line ) => line . startsWith ( '- Entity' ) ) ;
102-
103- lines . forEach ( ( line ) => {
104- expect ( line ) . toMatch ( / ^ - E n t i t y ' .* ' o f t y p e ' .* h a s e n t i t y i d ' .* ' $ / ) ;
97+ if ( response ?. records && response . records . length > 0 ) {
98+ response . records . forEach ( ( entity ) => {
99+ expect ( entity ?. id ) . toBeDefined ( ) ;
100+ expect ( getEntityTypeFromId ( String ( entity ?. id ) ) ) . toBeDefined ( ) ;
105101 } ) ;
102+ } else {
103+ // Nothing to assert; environment for testing has no entities found.
106104 }
107105 } ) ;
108106} ) ;
0 commit comments