import { describe, expect, it } from 'vitest';
import { SortData } from '../../List';
import { sortToPostGraphileOrderBy } from './SortTransformer';

interface TestData {
  title: string;
}

enum mockEnum {
  TitleAsc = 'TITLE_ASC',
  TitleDesc = 'TITLE_DESC',
}

describe('sortToPostGraphileOrderBy', () => {
  it('returns a value from an enum using the ascending direction', () => {
    const sort: SortData<TestData> = {
      column: 'title',
      direction: 'asc',
    };

    const orderBy = sortToPostGraphileOrderBy(sort, mockEnum);

    expect(orderBy).toEqual([mockEnum.TitleAsc]);
  });

  it('returns a value from an enum using the descending direction', () => {
    const sort: SortData<TestData> = { column: 'title', direction: 'desc' };

    const orderBy = sortToPostGraphileOrderBy(sort, mockEnum);

    expect(orderBy).toEqual([mockEnum.TitleDesc]);
  });

  it('returns undefined if no sorting data is given', () => {
    const sort = undefined;

    const orderBy = sortToPostGraphileOrderBy(sort!, mockEnum);

    expect(orderBy).toBeUndefined();
  });
});
