fix(ui): authenticate pipeline status api call (#21257)

* fix(ui): authenticate pipeline status api call

* fix tests
This commit is contained in:
Chirag Madlani 2025-05-18 19:54:58 +05:30 committed by GitHub
parent 764b1702b4
commit 7a73598a93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -24,6 +24,16 @@ jest.mock('../../rest/ingestionPipelineAPI', () => ({
getAirflowStatus: jest.fn(),
}));
jest.mock('../../hooks/useApplicationStore', () => {
return {
useApplicationStore: jest.fn().mockImplementation(() => ({
currentUser: {
id: '123',
},
})),
};
});
// Mock component to test the context
const TestComponent = () => {
const {

View File

@ -21,6 +21,7 @@ import React, {
useState,
} from 'react';
import { PipelineServiceClientResponse } from '../../generated/entity/services/ingestionPipelines/pipelineServiceClientResponse';
import { useApplicationStore } from '../../hooks/useApplicationStore';
import { getAirflowStatus } from '../../rest/ingestionPipelineAPI';
import { AirflowStatusContextType } from './AirflowStatusProvider.interface';
@ -40,8 +41,12 @@ const AirflowStatusProvider = ({ children }: Props) => {
useState<PipelineServiceClientResponse['reason']>();
const [platform, setPlatform] =
useState<PipelineServiceClientResponse['platform']>('unknown');
const { currentUser } = useApplicationStore();
const fetchAirflowStatus = useCallback(async () => {
if (!currentUser?.id) {
return;
}
setIsLoading(true);
try {
const response = await getAirflowStatus();
@ -54,11 +59,11 @@ const AirflowStatusProvider = ({ children }: Props) => {
} finally {
setIsLoading(false);
}
}, []);
}, [currentUser?.id]);
useEffect(() => {
fetchAirflowStatus();
}, []);
}, [fetchAirflowStatus]);
const value: AirflowStatusContextType = useMemo(
() => ({