import { createKubernetesApplyManifestAction } from './createKubernetesApplyManifestAction';
import { KubeConfig, KubernetesObjectApi } from '@kubernetes/client-node';
import * as yaml from 'js-yaml';

jest.mock('@kubernetes/client-node', () => {
	const originalModule = jest.requireActual('@kubernetes/client-node');
	return {
		...originalModule,
		KubeConfig: jest.fn(),
		KubernetesObjectApi: {
			makeApiClient: jest.fn().mockReturnValue({
				create: jest.fn().mockResolvedValue('Mocked API Call Success'),
			}),
		},
	};
});

describe('createKubernetesApplyManifestAction', () => {
	it('successfully reads a Kubernetes manifest from a file and processes it', async () => {
		const action = createKubernetesApplyManifestAction();
		const mockContext = {
			input: {
				manifestPath: './manifests/pod.yaml',
			},
			logger: {
				info: jest.fn(),
				error: jest.fn(),
			},
		};

		// Assuming the environment variables are set in the test environment
		expect(process.env.TOKEN).not.toBeUndefined();
		expect(process.env.CLUSTER_URL).not.toBeUndefined();

		await action.handler(mockContext);

		// Verify that the Kubernetes client's create method was called
		expect(KubernetesObjectApi.makeApiClient().create).toHaveBeenCalled();
		// You might want to check for specific log messages if your function logs outcomes
		expect(mockContext.logger.info).toHaveBeenCalled();
	});

	// Additional tests for error handling and other scenarios can be added here
});
