Skip to content

Commit

Permalink
improve tests for OrFail
Browse files Browse the repository at this point in the history
  • Loading branch information
snlamm committed Aug 31, 2017
1 parent 2ac0560 commit 1eb2d7c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions test/index.js
Expand Up @@ -87,22 +87,25 @@ test('Find or fail. Stub Objection version < 0.8.1', t => {
Person.QueryBuilder.prototype.throwIfNotFound = null

const personsQuery = Person.query().finder.firstNameOrFail('Jim')
const personQuery = Person.query().finder.firstNameOrFail('Jim').first()
const updatePersonQuery = Person.query().finder.firstNameOrFail('Jim').update({ email: 'jim@abc.com' })
const successfulPersonsQuery = Person.query().finder.firstNameOrFail('John')

return personsQuery.then(() => {
Person.QueryBuilder.prototype.throwIfNotFound = throwIfNotFound
t.fail()
}).catch(err => {
t.is(err.message, 'No models found')
}).then(() => {
return personQuery.then(() => {
return successfulPersonsQuery.then(() => {
return personsQuery.then(() => {
Person.QueryBuilder.prototype.throwIfNotFound = throwIfNotFound
t.fail()
}).catch(err => {
Person.QueryBuilder.prototype.throwIfNotFound = throwIfNotFound
t.is(err.message, 'No models found')
}).then(() => {
return updatePersonQuery.then(() => {
Person.QueryBuilder.prototype.throwIfNotFound = throwIfNotFound
t.fail()
}).catch(err => {
Person.QueryBuilder.prototype.throwIfNotFound = throwIfNotFound
t.is(err.message, 'No models found')
})
})
})
}).catch(() => t.fail())
})

test('Querying on a non-existing field fails', t => {
Expand Down

0 comments on commit 1eb2d7c

Please sign in to comment.