Skip to content

Commit

Permalink
test(errors): update testing suite to match new error
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Oct 6, 2023
1 parent aec69f7 commit ba1adf9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/orm/decorators/date_time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function prepareDateTimeColumn(value: any, attributeName: string, modelInstance:
*/
throw new errors.E_INVALID_DATE_COLUMN_VALUE([
`${modelName}.${attributeName}`,
'It must be an instance of "luxon.DateTime',
'It must be an instance of "luxon.DateTime"',
])
}

Expand Down
6 changes: 4 additions & 2 deletions test/migrations/migrator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getMigrator,
cleanup as cleanupTables,
} from '../../test-helpers/index.js'
import * as errors from '../../src/errors.js'

test.group('Migrator', (group) => {
group.each.setup(async () => {
Expand Down Expand Up @@ -834,7 +835,7 @@ test.group('Migrator', (group) => {
const db = getDb()
cleanup(() => db.manager.closeAll())

assert.plan(4)
assert.plan(5)

await fs.create(
'database/migrations/users_v11.ts',
Expand Down Expand Up @@ -892,9 +893,10 @@ test.group('Migrator', (group) => {
assert.lengthOf(migrated, 2)
assert.isTrue(hasUsersTable)
assert.isTrue(hasAccountsTable)
assert.instanceOf(migrator1.error, errors.E_MISSING_SCHEMA_FILES)
assert.equal(
migrator1.error!.message,
'Cannot perform rollback. Schema file {database/migrations/accounts_v11} is missing'
'Cannot perform rollback. Schema file "database/migrations/accounts_v11" is missing'
)
})

Expand Down
21 changes: 15 additions & 6 deletions test/orm/base_model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { LucidRow } from '../../src/types/model.js'
import { ModelPaginator } from '../../src/orm/paginator/index.js'
import { SimplePaginator } from '../../src/database/paginator/simple_paginator.js'
import { SnakeCaseNamingStrategy } from '../../src/orm/naming_strategies/snake_case.js'
import * as errors from '../../src/errors.js'

test.group('Base model | boot', (group) => {
group.setup(async () => {
Expand Down Expand Up @@ -6018,7 +6019,7 @@ test.group('Base Model | date', (group) => {
})

test('raise error when date column value is unprocessable', async ({ fs, assert }) => {
assert.plan(1)
assert.plan(2)

const app = new AppFactory().create(fs.baseUrl, () => {})
await app.init()
Expand All @@ -6044,8 +6045,12 @@ test.group('Base Model | date', (group) => {
user.dob = 10 as any
try {
await user.save()
} catch ({ message }) {
assert.equal(message, 'The value for "User.dob" must be an instance of "luxon.DateTime"')
} catch (error) {
assert.instanceOf(error, errors.E_INVALID_DATE_COLUMN_VALUE)
assert.equal(
error.message,
'Invalid value for "User.dob". The value must be an instance of "luxon.DateTime"'
)
}
})

Expand Down Expand Up @@ -6414,7 +6419,7 @@ test.group('Base Model | datetime', (group) => {
})

test('raise error when datetime column value is unprocessable', async ({ fs, assert }) => {
assert.plan(1)
assert.plan(2)

const app = new AppFactory().create(fs.baseUrl, () => {})
await app.init()
Expand All @@ -6440,8 +6445,12 @@ test.group('Base Model | datetime', (group) => {
user.dob = 10 as any
try {
await user.save()
} catch ({ message }) {
assert.equal(message, 'The value for "User.dob" must be an instance of "luxon.DateTime"')
} catch (error) {
assert.instanceOf(error, errors.E_INVALID_DATE_COLUMN_VALUE)
assert.equal(
error.message,
'Invalid value for "User.dob". It must be an instance of "luxon.DateTime"'
)
}
})

Expand Down

0 comments on commit ba1adf9

Please sign in to comment.