Skip to content

Commit

Permalink
Merge pull request #1 from DiogoBatista/test/ruifernando7-solution-test
Browse files Browse the repository at this point in the history
added test for ruifernando7 fix
  • Loading branch information
ruifernando7 authored Nov 29, 2022
2 parents d00151e + a205e0f commit f32473b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion test/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { createConnection, getConnection } from 'typeorm';

import { createQueryBuilder } from './utils/createQueryBuilder';
import { prepareData } from './utils/prepareData';
import { prepareData, setTimestamp } from './utils/prepareData';
import { User } from './entities/User';
import { Photo } from './entities/Photo';
import { buildPaginator } from '../src/index';
Expand Down Expand Up @@ -118,6 +118,39 @@ describe('TypeORM cursor-based pagination test', () => {
expect(result.cursor.afterCursor).to.eq(null);
});

describe('when the query has an addOrderBy defined', () => {
it('should return entities with the correct order', async () => {
const data = [
{
name: 'z-user',
camelCaseColumn: setTimestamp(1),
},
{
name: 'a-user',
camelCaseColumn: setTimestamp(2),
},
];

await getConnection().getRepository(User).save(data);

const queryBuilder = createQueryBuilder(User, 'user').addOrderBy(
'UPPER(user.name)',
'ASC',
);
const paginator = buildPaginator({
entity: User,
query: {
limit: 1,
},
});

const result = await paginator.paginate(queryBuilder);

expect(result.data[0].name).to.eq(data[1].name);
expect(result.data[0].name).to.eq(data[0].name);
});
});

after(async () => {
await getConnection().query('TRUNCATE TABLE users RESTART IDENTITY CASCADE;');
await getConnection().close();
Expand Down
2 changes: 1 addition & 1 deletion test/utils/prepareData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getConnection } from 'typeorm';
import { User } from '../entities/User';
import { Snake } from '../entities/Snake';

function setTimestamp(i: number): Date {
export function setTimestamp(i: number): Date {
const now = new Date();
now.setMinutes(now.getMinutes() + i);

Expand Down

0 comments on commit f32473b

Please sign in to comment.