import { buildPaginatedResponse } from './pagination.util';

describe('pagination util', () => {
  it('builds offset pagination metadata', () => {
    const result = buildPaginatedResponse(['a', 'b'], {
      page: 2,
      limit: 2,
      total: 5,
      offset: 2,
    });

    expect(result.count).toBe(2);
    expect(result.totalPages).toBe(3);
    expect(result.pagination.hasNextPage).toBe(true);
    expect(result.pagination.hasPreviousPage).toBe(true);
    expect(result.pagination.nextPage).toBe(3);
    expect(result.pagination.previousPage).toBe(1);
    expect(result.pagination.mode).toBe('offset');
  });

  it('builds cursor pagination metadata', () => {
    const result = buildPaginatedResponse(['a'], {
      page: 1,
      limit: 2,
      total: 3,
      offset: 0,
      currentCursor: 'cursor-a',
      nextCursor: 'cursor-b',
      mode: 'cursor',
    });

    expect(result.nextCursor).toBe('cursor-b');
    expect(result.pagination.currentCursor).toBe('cursor-a');
    expect(result.pagination.nextCursor).toBe('cursor-b');
    expect(result.pagination.mode).toBe('cursor');
  });
});
