Skip to content

Commit

Permalink
tests(errors): improve message for missing attribute error
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Nov 28, 2024
1 parent 4e8f232 commit 0ff68f2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
7 changes: 5 additions & 2 deletions test/orm/model_belongs_to.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ test.group('Model | BelongsTo | Options', (group) => {
Profile.boot()
Profile.$getRelation('user')!.boot()
} catch ({ message }) {
assert.equal(message, '"Profile.user" expects "id" to exist on "User" model, but is missing')
assert.equal(
message,
'Relation "Profile.user" expects "id" to exist on "User" model, but is missing. Did you forget to define the column?'
)
}
})

Expand Down Expand Up @@ -84,7 +87,7 @@ test.group('Model | BelongsTo | Options', (group) => {
} catch ({ message }) {
assert.equal(
message,
'"Profile.user" expects "userId" to exist on "Profile" model, but is missing'
'Relation "Profile.user" expects "userId" to exist on "Profile" model, but is missing. Did you forget to define the column?'
)
}
})
Expand Down
7 changes: 5 additions & 2 deletions test/orm/model_has_many.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ test.group('Model | HasMany | Options', (group) => {
User.boot()
User.$getRelation('posts')!.boot()
} catch ({ message }) {
assert.equal(message, '"User.posts" expects "id" to exist on "User" model, but is missing')
assert.equal(
message,
'Relation "User.posts" expects "id" to exist on "User" model, but is missing. Did you forget to define the column?'
)
}
})

Expand Down Expand Up @@ -85,7 +88,7 @@ test.group('Model | HasMany | Options', (group) => {
} catch ({ message }) {
assert.equal(
message,
'"User.posts" expects "userId" to exist on "Post" model, but is missing'
'Relation "User.posts" expects "userId" to exist on "Post" model, but is missing. Did you forget to define the column?'
)
}
})
Expand Down
11 changes: 7 additions & 4 deletions test/orm/model_has_many_through.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test.group('Model | Has Many Through | Options', (group) => {
} catch ({ message }) {
assert.equal(
message,
'"Country.posts" expects "id" to exist on "Country" model, but is missing'
'Relation "Country.posts" expects "id" to exist on "Country" model, but is missing. Did you forget to define the column?'
)
}
})
Expand Down Expand Up @@ -92,7 +92,7 @@ test.group('Model | Has Many Through | Options', (group) => {
} catch ({ message }) {
assert.equal(
message,
'"Country.posts" expects "countryId" to exist on "User" model, but is missing'
'Relation "Country.posts" expects "countryId" to exist on "User" model, but is missing. Did you forget to define the column?'
)
}
})
Expand Down Expand Up @@ -127,7 +127,10 @@ test.group('Model | Has Many Through | Options', (group) => {
Country.boot()
Country.$getRelation('posts')!.boot()
} catch ({ message }) {
assert.equal(message, '"Country.posts" expects "id" to exist on "User" model, but is missing')
assert.equal(
message,
'Relation "Country.posts" expects "id" to exist on "User" model, but is missing. Did you forget to define the column?'
)
}
})

Expand Down Expand Up @@ -166,7 +169,7 @@ test.group('Model | Has Many Through | Options', (group) => {
} catch ({ message }) {
assert.equal(
message,
'"Country.posts" expects "userId" to exist on "Post" model, but is missing'
'Relation "Country.posts" expects "userId" to exist on "Post" model, but is missing. Did you forget to define the column?'
)
}
})
Expand Down
7 changes: 5 additions & 2 deletions test/orm/model_has_one.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ test.group('Model | HasOne | Options', (group) => {
User.boot()
User.$getRelation('profile')!.boot()
} catch ({ message }) {
assert.equal(message, '"User.profile" expects "id" to exist on "User" model, but is missing')
assert.equal(
message,
'Relation "User.profile" expects "id" to exist on "User" model, but is missing. Did you forget to define the column?'
)
}
})

Expand Down Expand Up @@ -83,7 +86,7 @@ test.group('Model | HasOne | Options', (group) => {
} catch ({ message }) {
assert.equal(
message,
'"User.profile" expects "userId" to exist on "Profile" model, but is missing'
'Relation "User.profile" expects "userId" to exist on "Profile" model, but is missing. Did you forget to define the column?'
)
}
})
Expand Down
10 changes: 8 additions & 2 deletions test/orm/model_many_to_many.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ test.group('Model | ManyToMany | Options', (group) => {
User.boot()
User.$getRelation('skills')!.boot()
} catch ({ message }) {
assert.equal(message, '"User.skills" expects "id" to exist on "User" model, but is missing')
assert.equal(
message,
'Relation "User.skills" expects "id" to exist on "User" model, but is missing. Did you forget to define the column?'
)
}
})

Expand Down Expand Up @@ -141,7 +144,10 @@ test.group('Model | ManyToMany | Options', (group) => {
User.boot()
User.$getRelation('skills')!.boot()
} catch ({ message }) {
assert.equal(message, '"User.skills" expects "id" to exist on "Skill" model, but is missing')
assert.equal(
message,
'Relation "User.skills" expects "id" to exist on "Skill" model, but is missing. Did you forget to define the column?'
)
}
})

Expand Down

0 comments on commit 0ff68f2

Please sign in to comment.