-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid column name errors #358
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ module.exports = Nodal => { | |
|
||
const async = require('async'); | ||
|
||
let expect = require('chai').expect; | ||
const { assert, expect } = require('chai'); | ||
|
||
describe('Nodal.Composer', function() { | ||
|
||
|
@@ -1225,23 +1225,23 @@ module.exports = Nodal => { | |
children__is_favorite: true, | ||
children__license: null, | ||
pets__name: 'Oliver', | ||
pets__alive: true, | ||
pets__is_alive: true, | ||
name: 'Zoolander', | ||
pets__animal__in: ['Cat'] | ||
}, | ||
{ | ||
children__is_favorite: true, | ||
children__license__not_null: true, | ||
pets__name: 'Oliver', | ||
pets__alive: true, | ||
pets__is_alive: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test for comparators too ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I could add those if you like but this change was just to fix the bad column name used in the original test. |
||
name: 'Zoolander', | ||
pets__animal__in: ['Cat'] | ||
}, | ||
{ | ||
careers__title: 'Freelancer', | ||
careers__is_active: true, | ||
pets__name: 'Oliver', | ||
pets__alive: true, | ||
pets__is_alive: true, | ||
name: 'Zoolander', | ||
pets__animal__in: ['Cat'] | ||
}, | ||
|
@@ -1709,6 +1709,50 @@ module.exports = Nodal => { | |
|
||
}); | ||
|
||
it('Should throw errors when querying with a bad column name', done => { | ||
|
||
try { | ||
|
||
Parent.query() | ||
.join('pets') | ||
.where({ active: true }) | ||
.end(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the style consistent with other tests (use the callback and catch the error) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way I wrote the code is such that it throws an error outside of the Would you prefer me to have it throw the error inside the |
||
|
||
assert.fail("Expected query to throw an error"); | ||
|
||
} catch (error) { | ||
|
||
expect(error.message).to.contain("Column 'active'"); | ||
expect(error.message).to.contain("'Parent'"); | ||
|
||
} | ||
|
||
done(); | ||
|
||
}); | ||
|
||
it('Should throw errors when querying joins with a bad column name', done => { | ||
|
||
try { | ||
|
||
Parent.query() | ||
.join('pets') | ||
.where({ pets__active: true }) | ||
.end(); | ||
|
||
assert.fail("Expected query to throw an error"); | ||
|
||
} catch (error) { | ||
|
||
expect(error.message).to.contain("Column 'active'"); | ||
expect(error.message).to.contain("'Pet'"); | ||
|
||
} | ||
|
||
done(); | ||
|
||
}); | ||
|
||
// IMPORTANT: Do npt place any tests after the `Should do a destroy cascade` | ||
// test since all models will be gone | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write a new test case here instead of adapting an old one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually an issue with the existing tests since the column
active
doesn't exist (it'sis_active
). I had to update them because my new changes would break the tests otherwise. This column doesn't seem to affect the result of the test anyway since they still pass like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha. Makes sense then