Closed Getz85 closed 8 years ago
@Getz85 What version of knex / bookshelf are you using?
@Getz85 Does the test work once you remove the transaction? I might be seeing a similar issue.
@jbrumwell knex version 0.11.10 bookshelf version 0.10.0
@dustinmartin Indeed, the test work fine if I remove the transaction!
@Getz85 Awesome...so we might have the culprit. Checkout my comment in issue #40. Perhaps it details some similarities in your setup. I'm curious to know when you mock Knex and what DB you are using or if there is anything else that sticks out. Thanks!
@dustinmartin I use MySQL, so we've got another use case here ;) I mock knex before passing it to bookshelf, like in the tests apparently.
before(function(done) {
db = knex({
client: 'mysql',
useNullAsDefault: true
});
mockKnex.mock(db);
bookshelf = require('bookshelf')(db);
bookshelf.plugin('registry');
var Customer = require('../../models/customer')(bookshelf);
done();
});
I have added a branch here with a transaction test inside of bookshelf, https://github.com/colonyamerican/mock-knex/tree/bug/bookshelf-transactions, which passes but this could be client specific. If I get time today I'll try and update the code to run through a mysql / postgres client and see if we can track it down
@jbrumwell Thanks so much for looking into this. Let me know if I can provide any information or test something for you.
@jbrumwell Any luck reproducing the bug with mysql or postgres?
Took a little longer then expected, can you guys give this branch a test?
https://github.com/colonyamerican/mock-knex/tree/feature/test-databases
Released version 0.3.4, let me know if it resolves the issues
@jbrumwell That worked perfectly! Thanks! What ended up being the problem?
There were a few issues
This resolved the issue with transactions
stream
method https://github.com/colonyamerican/mock-knex/commit/da037a0920abbdbd6cb598b729c22783c6c6d3da#diff-afb57afee1821745f7d0c2b15087aec2R49response
in their query object. To avoid these issues we nest our properties now, https://github.com/colonyamerican/mock-knex/commit/da037a0920abbdbd6cb598b729c22783c6c6d3da#diff-d8494ca7e744216ae18ca4aa7d9eab7cR18Thanks for your help :)
Fantastic! Thanks again for resolve this. Happy to help!
My unit tests worked fine with Mock-knex 0.3.2. With the last version, I've got this error when I want to test some insert or update operations inside a transaction:
On insert:
On update:
This is an exemple of code which failed:
And this is my tracker code: