/**
 * @jest-environment @dynatrace/runtime-simulator/lib/test-environment
 */

import actionName from './action-name.action';
import { buildMockedFetchResponse } from './test-utils';

describe('action-name', () => {
  let fetchMock;

  beforeEach(() => {
    fetchMock = jest.fn();
    globalThis.fetch = fetchMock;
  });

  afterEach(() => {
    // Clean up the mock to prevent interference with other tests
    fetchMock.mockClear();
  });

    it('should produce expected results', async () => {
      fetchMock.mockImplementation(() =>
        buildMockedFetchResponse({
          schemaId: 'action-name-connection',
          value: {
            name: 'My Connection',
            token: 'abc123',
            url: 'https://foo.bar',
          },
          summary: 'My Connection',
        }),
      );

      const result = await actionName({ name: 'Mark', connectionId: 'action-name-connection-object-id' });
      expect(result).toEqual({ message: 'Hello Mark!' });
      expect.assertions(1);
  });
});
