From f27a5b9c4b275373827c012f6c7427615f75dc5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 7 Nov 2022 00:14:13 -0300 Subject: [PATCH] test(qb): add tests for new methods and remove pins --- tests/Unit/Drivers/MySqlDriverTest.js | 21 ++++++++++------- tests/Unit/Drivers/PostgresDriverTest.js | 29 ++++++++++++++---------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/tests/Unit/Drivers/MySqlDriverTest.js b/tests/Unit/Drivers/MySqlDriverTest.js index 65158ed..8a082ed 100644 --- a/tests/Unit/Drivers/MySqlDriverTest.js +++ b/tests/Unit/Drivers/MySqlDriverTest.js @@ -37,14 +37,22 @@ test.group('MySqlDriverTest', group => { await DB.runMigrations() - const { id } = await DB.table('users').create({ name: 'João Lenon', email: 'lenon@athenna.io' }) + const { id } = await DB.table('users').create({ + name: 'João Lenon', + email: 'lenon@athenna.io', + }) await DB.table('products').createMany([ { userId: id, name: 'iPhone 13', price: 1000 }, { userId: id, name: 'iPhone 14', price: 2000 }, ]) - await DB.table('users').create({ name: 'Victor Tesoura', email: 'txsoura@athenna.io' }) + await DB.table('users').create({ + name: 'Victor Tesoura', + email: 'txsoura@athenna.io', + createdAt: new Date(Date.now() + 100000), + updatedAt: new Date(Date.now() + 100000), + }) }) group.each.teardown(async () => { @@ -360,11 +368,8 @@ test.group('MySqlDriverTest', group => { const oldestCreatedAt = await DB.table('users').oldest().find() const latestCreatedAt = await DB.table('users').latest().find() - console.log(oldestCreatedAt) - console.log(latestCreatedAt) - assert.isTrue(oldestCreatedAt.createdAt < latestCreatedAt.createdAt) - }).pin() + }) test('should be able to find users ordering by latest and oldest with different columns', async ({ assert }) => { const oldestUpdatedAt = await DB.table('users').oldest('updatedAt').find() @@ -411,7 +416,7 @@ test.group('MySqlDriverTest', group => { .orWhereNotExists(Database.table('users').where('id', 2)) .findMany() - assert.lengthOf(whereUsers, 10) + assert.lengthOf(whereUsers, 2) }) test('should be able to get users using GROUP BY and HAVING queries', async ({ assert }) => { @@ -435,6 +440,6 @@ test.group('MySqlDriverTest', group => { .orHavingNotExists(Database.table('users').where('id', 2)) .findMany() - assert.lengthOf(groupByUsers, 10) + assert.lengthOf(groupByUsers, 2) }) }) diff --git a/tests/Unit/Drivers/PostgresDriverTest.js b/tests/Unit/Drivers/PostgresDriverTest.js index 5ff54eb..4d5f14a 100644 --- a/tests/Unit/Drivers/PostgresDriverTest.js +++ b/tests/Unit/Drivers/PostgresDriverTest.js @@ -37,14 +37,19 @@ test.group('PostgresDriverTest', group => { await DB.runMigrations() - const [{ id }] = await DB.table('users').createMany([ - { name: 'João Lenon', email: 'lenon@athenna.io' }, - { name: 'Victor Tesoura', email: 'txsoura@athenna.io' }, - ]) + const { id } = await DB.table('users').create({ name: 'João Lenon', email: 'lenon@athenna.io' }) + await DB.table('products').createMany([ { userId: id, name: 'iPhone 13', price: 1000 }, { userId: id, name: 'iPhone 14', price: 2000 }, ]) + + await DB.table('users').create({ + name: 'Victor Tesoura', + email: 'txsoura@athenna.io', + createdAt: new Date(Date.now() + 100000), + updatedAt: new Date(Date.now() + 100000), + }) }) group.each.teardown(async () => { @@ -354,16 +359,16 @@ test.group('PostgresDriverTest', group => { await otherDB.close() }) - test('should be able to find products ordering by latest and oldest', async ({ assert }) => { - const oldestCreatedAt = await DB.table('products').oldest().find() - const latestCreatedAt = await DB.table('products').latest().find() + test('should be able to find users ordering by latest and oldest', async ({ assert }) => { + const oldestCreatedAt = await DB.table('users').oldest().find() + const latestCreatedAt = await DB.table('users').latest().find() assert.isTrue(oldestCreatedAt.createdAt < latestCreatedAt.createdAt) }) - test('should be able to find products ordering by latest and oldest with different columns', async ({ assert }) => { - const oldestUpdatedAt = await DB.table('products').oldest('updatedAt').find() - const latestUpdatedAt = await DB.table('products').latest('updatedAt').find() + test('should be able to find users ordering by latest and oldest with different columns', async ({ assert }) => { + const oldestUpdatedAt = await DB.table('users').oldest('updatedAt').find() + const latestUpdatedAt = await DB.table('users').latest('updatedAt').find() assert.isTrue(oldestUpdatedAt.updatedAt < latestUpdatedAt.updatedAt) }) @@ -406,7 +411,7 @@ test.group('PostgresDriverTest', group => { .orWhereNotExists(Database.table('products').where('id', 2)) .findMany() - assert.lengthOf(whereUsers, 10) + assert.lengthOf(whereUsers, 2) }) test('should be able to get products using GROUP BY and HAVING queries', async ({ assert }) => { @@ -430,6 +435,6 @@ test.group('PostgresDriverTest', group => { .orHavingNotExists(Database.table('products').where('id', 2)) .findMany() - assert.lengthOf(groupByUsers, 10) + assert.lengthOf(groupByUsers, 2) }) })