Skip to content

Commit

Permalink
test: add more assertions to cover edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 13, 2019
1 parent 0b8f13d commit b6e455e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
10 changes: 8 additions & 2 deletions test/orm/model-belongs-to.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ test.group('Model | BelongsTo | persist', (group) => {
})

test('use parent model transaction when defined', async (assert) => {
assert.plan(4)
assert.plan(5)

class User extends BaseModel {
@column({ primary: true })
Expand Down Expand Up @@ -1169,6 +1169,12 @@ test.group('Model | BelongsTo | persist', (group) => {
profile.displayName = 'virk'

await profile.related<'belongsTo', 'user'>('user').associate(user)

/**
* Ensure that related save has not committed the transaction
*/
assert.deepEqual(profile.$trx, trx)

await trx.rollback()

const totalUsers = await db.query().from('users').count('*', 'total')
Expand All @@ -1180,7 +1186,7 @@ test.group('Model | BelongsTo | persist', (group) => {
assert.isUndefined(profile.$trx)
})

test('create save point when parent is already in transaction', async (assert) => {
test('create save point when parent is in transaction and not persisted', async (assert) => {
assert.plan(5)

class User extends BaseModel {
Expand Down
20 changes: 16 additions & 4 deletions test/orm/model-has-many.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ test.group('Model | HasMany | persist', (group) => {
})

test('use parent model transaction when defined', async (assert) => {
assert.plan(4)
assert.plan(5)

class Post extends BaseModel {
@column({ primary: true })
Expand Down Expand Up @@ -1466,6 +1466,12 @@ test.group('Model | HasMany | persist', (group) => {
post.title = 'Adonis 101'

await user.related('posts').save(post)

/**
* Ensure that related save has not committed the transaction
*/
assert.deepEqual(user.$trx, trx)

await trx.rollback()

const totalUsers = await db.query().from('users').count('*', 'total')
Expand All @@ -1478,7 +1484,7 @@ test.group('Model | HasMany | persist', (group) => {
})

test('use parent model transaction with save many when defined', async (assert) => {
assert.plan(5)
assert.plan(6)

class Post extends BaseModel {
@column({ primary: true })
Expand Down Expand Up @@ -1516,6 +1522,12 @@ test.group('Model | HasMany | persist', (group) => {
post1.title = 'Lucid 101'

await user.related('posts').saveMany([post, post1])

/**
* Ensure that related save has not committed the transaction
*/
assert.deepEqual(user.$trx, trx)

await trx.rollback()

const totalUsers = await db.query().from('users').count('*', 'total')
Expand All @@ -1528,7 +1540,7 @@ test.group('Model | HasMany | persist', (group) => {
assert.isUndefined(post1.$trx)
})

test('create save point when parent is already in transaction', async (assert) => {
test('create save point when parent is in transaction and not persisted', async (assert) => {
assert.plan(5)

class Post extends BaseModel {
Expand Down Expand Up @@ -1577,7 +1589,7 @@ test.group('Model | HasMany | persist', (group) => {
assert.isUndefined(post.$trx)
})

test('create save point with saveMany when parent is already in transaction', async (assert) => {
test('create save point with saveMany when parent is in transaction and not persisted', async (assert) => {
assert.plan(5)

class Post extends BaseModel {
Expand Down
10 changes: 8 additions & 2 deletions test/orm/model-has-one.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ test.group('Model | HasOne | persist', (group) => {
})

test('use parent model transaction when defined', async (assert) => {
assert.plan(4)
assert.plan(5)

class Profile extends BaseModel {
@column({ primary: true })
Expand Down Expand Up @@ -1159,6 +1159,12 @@ test.group('Model | HasOne | persist', (group) => {
profile.displayName = 'virk'

await user.related<'hasOne', 'profile'>('profile').save(profile)

/**
* Ensure that related save has not committed the transaction
*/
assert.deepEqual(user.$trx, trx)

await trx.rollback()

const totalUsers = await db.query().from('users').count('*', 'total')
Expand All @@ -1170,7 +1176,7 @@ test.group('Model | HasOne | persist', (group) => {
assert.isUndefined(profile.$trx)
})

test('create save point when parent is already in transaction', async (assert) => {
test('create save point when parent is already in transaction and not persisted', async (assert) => {
assert.plan(5)

class Profile extends BaseModel {
Expand Down
28 changes: 26 additions & 2 deletions test/orm/model-many-to-many.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,12 @@ test.group('Model | ManyToMany | persist', (group) => {
skill.name = 'Programming'

await user.related('skills').save(skill)

/**
* Ensure that related save has not committed the transaction
*/
assert.deepEqual(user.$trx, trx)

await trx.rollback()

const totalUsers = await db.query().from('users').count('*', 'total')
Expand Down Expand Up @@ -2524,6 +2530,12 @@ test.group('Model | ManyToMany | persist', (group) => {
skill.name = 'Programming'

await user.related('skills').save(skill, false)

/**
* Ensure that related save has not committed the transaction
*/
assert.deepEqual(user.$trx, trx)

await trx.rollback()

const totalUsers = await db.query().from('users').count('*', 'total')
Expand Down Expand Up @@ -2568,6 +2580,12 @@ test.group('Model | ManyToMany | persist', (group) => {
skill1.name = 'Dancy'

await user.related('skills').saveMany([skill, skill1])

/**
* Ensure that related save has not committed the transaction
*/
assert.deepEqual(user.$trx, trx)

await trx.rollback()

const totalUsers = await db.query().from('users').count('*', 'total')
Expand Down Expand Up @@ -2612,6 +2630,12 @@ test.group('Model | ManyToMany | persist', (group) => {
skill1.name = 'Dancing'

await user.related('skills').saveMany([skill, skill1], false)

/**
* Ensure that related save has not committed the transaction
*/
assert.deepEqual(user.$trx, trx)

await trx.rollback()

const totalUsers = await db.query().from('users').count('*', 'total')
Expand All @@ -2623,7 +2647,7 @@ test.group('Model | ManyToMany | persist', (group) => {
assert.lengthOf(skillUsers, 0)
})

test('create save point when parent is already in transaction', async (assert) => {
test('create save point when parent is in transaction and not persisted', async (assert) => {
class Skill extends BaseModel {
@column({ primary: true })
public id: number
Expand Down Expand Up @@ -2668,7 +2692,7 @@ test.group('Model | ManyToMany | persist', (group) => {
assert.lengthOf(skillUsers, 0)
})

test('create save point with save many when parent is already in transaction', async (assert) => {
test('create save point with save many when parent is in transaction and not persisted', async (assert) => {
class Skill extends BaseModel {
@column({ primary: true })
public id: number
Expand Down

0 comments on commit b6e455e

Please sign in to comment.