rochejul / sequelize-mocking

Sequelize extension to deal with data-mocking for testing
MIT License
63 stars 26 forks source link

Unable to mock sequelize transactions #24

Closed ricardobotto closed 6 years ago

ricardobotto commented 6 years ago

Hi,

I'm unable to mock tests that uses sequelize transactions.

Mocks currently generating START TRANSACTION queries which corresponds to the MySQL syntax.

I already tested using SQLITE as project default database and it correctly generates a query: BEGIN DEFERRED TRANSACTION

Using following transaction templates: sql.transaction().then(function (t) { return t.commit(); });

sql.transaction(function (t) { });

Both return the following errors:

Unhandled rejection SequelizeDatabaseError: SQLITE_ERROR: near "START": syntax error at Query.formatError (./node_modules/sequelize/lib/dialects/sqlite/query.js:424:16) at afterExecute (./node_modules/sequelize/lib/dialects/sqlite/query.js:120:32) at replacement (./node_modules/sqlite3/lib/trace.js:19:31) at Statement.errBack (./node_modules/sqlite3/lib/sqlite3.js:16:21)

Am I doing somthing wrong regarding mocks configuration? Here is my Database Instance const sql = new Sequelize(config.db.database, config.db.username, config.db.password, { host: config.db.host, dialect: config.db.driver, logging: false, operatorsAliases: Sequelize.Op });

rochejul commented 6 years ago

Hi @ricardobotto

Could you provide an attachment with a concrete example of your issue please ?

Many thanks

Regards

ricardobotto commented 6 years ago

Hi @rochejul

I'm attaching a more complete example, hope it helps. Transactions structures can be found in controller.txt.

controller.txt index.txt test-spec.txt userModel.txt

Thanks for helping :)

rochejul commented 6 years ago

Many thanks !

I try to take some times on the next days to look on it

Thanks

djfabrix commented 6 years ago

I have the same problem. Any news about resolution? Thanks in advance

rochejul commented 6 years ago

Analysis in progress. It seems we could have not the expected QueryGenerator instance, and we use the "abstract" one instead the sqlite dedicated.

Look to find a fix

Regards

rochejul commented 6 years ago

Ok, it seems the "queryInterface" property is not updated (new creation since Sequelize 4.X ?) --> https://github.com/sequelize/sequelize/blob/master/lib/sequelize.js#L243

so like the dialect, we have to override it.

rochejul commented 6 years ago

Will be deployed soon

ekrotenko commented 4 years ago

Any updates? Still tests fail on calls of transaction.commit()/transaction.rollback()

rochejul commented 4 years ago

Hi @ekrotenko Could you please them to give a full example please ? A tiny project to illustrate the issue

Regards