import { describe, expect, it } from 'vitest';
import { ErrorType } from '../../../components';
import { ApolloErrorMapper } from './ApolloErrorMapper';

describe('ApolloErrorMapper', () => {
  const mockError: ErrorType = {
    name: 'ApolloError',
    networkError: { message: 'Network connection lost' },
  };

  it('should map an Apollo error with a network error', () => {
    const mappedError = ApolloErrorMapper(mockError);
    expect(mappedError).toEqual({
      title: 'A network error occurred',
      body: expect.any(Object), // You can modify the expectation here based on your needs
    });
  });

  it('should not map an error if already mapped by a previous error mapper', () => {
    const previousMappedError: ErrorType = {
      title: 'Previous Error',
      body: 'Previous error message',
    };
    const mappedError = ApolloErrorMapper(mockError, previousMappedError);
    expect(mappedError).toBeUndefined();
  });

  it('should return undefined if it does not match the conditions', () => {
    const error: ErrorType = new Error('Some other error');
    const mappedError = ApolloErrorMapper(error);
    expect(mappedError).toBeUndefined();
  });
});
