diff --git a/assets/js/state/selectors/lastExecutions.js b/assets/js/state/selectors/lastExecutions.js index 281b73fe56..c4c14df336 100644 --- a/assets/js/state/selectors/lastExecutions.js +++ b/assets/js/state/selectors/lastExecutions.js @@ -21,7 +21,7 @@ const addHostnameToAgentsCheckResults = ( ...executionData, data: { ...data, - check_results: check_results.map((checkResult) => ({ + check_results: check_results?.map((checkResult) => ({ ...checkResult, agents_check_results: checkResult?.agents_check_results.map( (target) => ({ diff --git a/assets/js/state/selectors/lastExecutions.test.js b/assets/js/state/selectors/lastExecutions.test.js index 62c5a94848..303b5194bd 100644 --- a/assets/js/state/selectors/lastExecutions.test.js +++ b/assets/js/state/selectors/lastExecutions.test.js @@ -3,6 +3,7 @@ import { clusterFactory, catalogCheckFactory, checksExecutionCompletedForTargetsFactory, + checksExecutionRunningFactory, } from '@lib/test-utils/factories'; import { getLastExecution, getLastExecutionData } from './lastExecutions'; @@ -100,4 +101,34 @@ describe('lastExecutions selector', () => { lastExecution.data.check_results[0].agents_check_results[1].hostname ).toEqual(hostname2); }); + + it('should properly handle running executions', () => { + const { id: clusterID } = clusterFactory.build(); + const runningExecution = checksExecutionRunningFactory.build({ + group_id: clusterID, + }); + + const state = { + clustersList: { + clusters: [], + }, + hostsList: { + hosts: [], + }, + catalog: {}, + lastExecutions: { + [clusterID]: { + loading: false, + data: runningExecution, + error: null, + }, + }, + }; + + const { lastExecution } = getLastExecutionData(clusterID)(state); + + expect(lastExecution.data.result).toBeNull(); + expect(lastExecution.data.check_results).toBeUndefined(); + expect(lastExecution.data.status).toEqual('running'); + }); });