import { OrderBy } from '../../types';
import { orderByOptionMapping } from './order-by-option.mapping';
import * as schemaModule from '../schemas/order-by-option.schema';

describe('orderByOptionMapping', () => {
  const mockSchemaParser = jest.fn().mockImplementation((input) => input);

  beforeEach(() => {
    jest.clearAllMocks();

    // Mock the schema parse method to avoid validation errors in tests
    jest.spyOn(schemaModule.OrderByOptionSchema, 'parse').mockImplementation(mockSchemaParser);
  });

  it('should map ascending order by option correctly', () => {
    // Arrange
    const orderBy: OrderBy = {
      label: 'Sort by Name',
      by: 'name',
      desc: false,
    };

    // Act
    const result = orderByOptionMapping(orderBy);

    // Assert
    expect(mockSchemaParser).toHaveBeenCalledWith({
      label: 'Sort by Name',
      by: 'name',
      dir: 'asc',
      selected: false,
    });

    expect(result).toEqual({
      label: 'Sort by Name',
      by: 'name',
      dir: 'asc',
      selected: false,
    });
  });

  it('should map descending order by option correctly', () => {
    // Arrange
    const orderBy: OrderBy = {
      label: 'Sort by Date',
      by: 'date',
      desc: true,
    };

    // Act
    const result = orderByOptionMapping(orderBy);

    // Assert
    expect(mockSchemaParser).toHaveBeenCalledWith({
      label: 'Sort by Date',
      by: 'date',
      dir: 'desc',
      selected: false,
    });

    expect(result).toEqual({
      label: 'Sort by Date',
      by: 'date',
      dir: 'desc',
      selected: false,
    });
  });
});
