Skip to content

Commit a021235

Browse files
Samuel Roybenjamin658
Samuel Roy
authored andcommitted
fix(tests): make float column test deterministic
Sometimes the test case would fail due to the random balances chosen for each user in prepareData. The test is now deterministic by using an ordered fixed list of balances.
1 parent 1f4bcb4 commit a021235

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

test/pagination.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ describe('TypeORM cursor-based pagination test', () => {
9191

9292
expect(firstPageResult.data[1].id).to.not.eq(nextPageResult.data[0].id);
9393
expect(firstPageResult.data[1].balance).to.be.above(nextPageResult.data[0].balance);
94+
expect(firstPageResult.data[0].id).to.eq(10);
95+
expect(nextPageResult.data[0].id).to.eq(8);
9496
});
9597

9698
it('should return entities with given order', async () => {

test/utils/prepareData.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@ function setTimestamp(i: number): Date {
99
return now;
1010
}
1111

12-
function getRandomFloat(min: number, max: number): number {
13-
const str = (Math.random() * (max - min) + min).toFixed(2);
14-
15-
return parseFloat(str);
16-
}
12+
const balances = [1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2];
1713

1814
export async function prepareData(): Promise<void> {
1915
const data = [...Array(10).keys()].map((i) => ({
2016
name: `user${i}`,
21-
balance: getRandomFloat(1, 2),
17+
balance: balances[i],
2218
camelCaseColumn: setTimestamp(i),
2319
photos: [
2420
{

0 commit comments

Comments
 (0)