Skip to content

Commit

Permalink
test(qb): add tests for new methods and remove pins
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Nov 7, 2022
1 parent b0b959e commit f27a5b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
21 changes: 13 additions & 8 deletions tests/Unit/Drivers/MySqlDriverTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 }) => {
Expand All @@ -435,6 +440,6 @@ test.group('MySqlDriverTest', group => {
.orHavingNotExists(Database.table('users').where('id', 2))
.findMany()

assert.lengthOf(groupByUsers, 10)
assert.lengthOf(groupByUsers, 2)
})
})
29 changes: 17 additions & 12 deletions tests/Unit/Drivers/PostgresDriverTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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 }) => {
Expand All @@ -430,6 +435,6 @@ test.group('PostgresDriverTest', group => {
.orHavingNotExists(Database.table('products').where('id', 2))
.findMany()

assert.lengthOf(groupByUsers, 10)
assert.lengthOf(groupByUsers, 2)
})
})

0 comments on commit f27a5b9

Please sign in to comment.