diff --git a/changelog.md b/changelog.md index b917dbd..cbf9cd4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,6 @@ # Changelog -v0.10.2 - 8ed75d2 - Dec 4th 2017 +v0.10.2 - Dec 4th 2017 * Fix for DataTypes not being exposed during `sequelize.import` calls * *DEV* Added .editorconfig file to normalize editors and minimize whitespace changes diff --git a/docs/api/model.md b/docs/api/model.md index 421aaba..8d97cd5 100644 --- a/docs/api/model.md +++ b/docs/api/model.md @@ -80,7 +80,7 @@ UserMock.findOne().then(function (result) { UserMock.$queueResult(UserMock.build(), { wasCreated: false }); UserMock.findOrCreate({ // ... -}).spread(function (user, created) { +}).then(function ([user, created]) { // created == false }); ``` @@ -306,8 +306,8 @@ Name | Type | Description - -## findById(id) -> Promise.<Instance> + +## findBfindByPkyId(id) -> Promise.<Instance> Executes a mock query to find an instance with the given ID value. Without any other configuration, the default behavior when no queueud query result is present is to diff --git a/docs/api/sequelize.md b/docs/api/sequelize.md index 9f934c4..b6a4eae 100644 --- a/docs/api/sequelize.md +++ b/docs/api/sequelize.md @@ -71,7 +71,7 @@ Reference to the Util functions ## Promise -Reference to the bluebird promise library +Reference to the Promise library diff --git a/docs/docs/mock-queries.md b/docs/docs/mock-queries.md index f6aa926..4878fe1 100644 --- a/docs/docs/mock-queries.md +++ b/docs/docs/mock-queries.md @@ -98,7 +98,7 @@ User.$useHandler(function(query, queryOptions, done) { if (query === "findOne") return User.build({id: 1}); }); User.$useHandler(function(query, queryOptions, done) { - if (query === "findById") return User.build({id: queryOptions[0]}); + if (query === "findByPk") return User.build({id: queryOptions[0]}); }); User.$useHandler(function(query, queryOptions, done) { if (query === "findOrCreate") return User.build({id:1000}); @@ -107,7 +107,7 @@ User.$useHandler(function(query, queryOptions, done) { User.findOne().then(function (user) { user.get('id'); // === 1 }); -User.findById(123).then(function (user) { +User.findByPk(123).then(function (user) { user.get('id'); // === 123 }); User.findOrCreate().then(function (user) { @@ -158,7 +158,7 @@ Some functions require additional parameters or configuration. You can specify b ```javascript User.$queueResult( User.build(), { wasCreated: true } ); -User.findOrCreate().spread(function (user, wasCreated) { +User.findOrCreate().then(function ([user, wasCreated]) { wasCreated; // === true }); ``` diff --git a/package.json b/package.json index a2974c8..7369cb3 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ }, "homepage": "https://github.com/BlinkUX/sequelize-mock#readme", "dependencies": { - "bluebird": "^3.4.6", "inflection": "^1.10.0", "lodash": "^4.16.4" }, diff --git a/src/instance.js b/src/instance.js index a2cb256..823e15d 100644 --- a/src/instance.js +++ b/src/instance.js @@ -24,8 +24,7 @@ * @fileOverview Instances of Models created by Model function calls. */ -var bluebird = require('bluebird'), - _ = require('lodash'), +var _ = require('lodash'), Errors = require('./errors'); var id = 0; @@ -205,24 +204,6 @@ fakeModelInstance.prototype.get = function (key) { } }; -/** - * Get plain value - * @param {String} key Key yo get the value for - * @return {Any} - */ -fakeModelInstance.prototype.getDataValue = function (key) { - return this._values[key]; -}; - -/** - * Set plain value - * @param {String} key Key yo get the value for - * @param {Any} value - */ -fakeModelInstance.prototype.setDataValue = function (key, value) { - this._values[key] = value; -}; - /** * Triggers validation. If there are errors added through `$addValidationError` they will * be returned and the queue of validation errors will be cleared. @@ -250,7 +231,7 @@ fakeModelInstance.prototype.validate = function () { this.$clearValidationErrors(); } - return bluebird.resolve(validationError); + return Promise.resolve(validationError); }; /** @@ -279,7 +260,7 @@ fakeModelInstance.prototype.save = function () { **/ fakeModelInstance.prototype.destroy = function () { this._values.deletedAt = new Date(); - return bluebird.resolve(); + return Promise.resolve(); }; /** @@ -289,7 +270,7 @@ fakeModelInstance.prototype.destroy = function () { * @return {Promise} will always resolve with the current instance **/ fakeModelInstance.prototype.reload = function () { - return bluebird.resolve(this); + return Promise.resolve(this); }; /** diff --git a/src/model.js b/src/model.js index 313f447..e7c099a 100644 --- a/src/model.js +++ b/src/model.js @@ -10,8 +10,7 @@ * @fileOverview The base mock Model object for use in tests */ -var Promise = require('bluebird'), - _ = require('lodash'), +var _ = require('lodash'), nodeutil = require('util'), Utils = require('./utils'), Instance = require('./instance'), @@ -127,7 +126,7 @@ function fakeModel (name, defaults, opts) { * UserMock.$queueResult(UserMock.build(), { wasCreated: false }); * UserMock.findOrCreate({ * // ... - * }).spread(function (user, created) { + * }).then(function ([user, created]) { * // created == false * }); * @@ -239,14 +238,6 @@ fakeModel.prototype.scope = function () { return this; }; -/** - * No-op that returns a void. - * - * @instance - * @return {undefined} - **/ -fakeModel.prototype.addScope = function () {}; - /** * Executes a mock query to find all of the instances with any provided options. Without * any other configuration, the default behavior when no queueud query result is present @@ -346,11 +337,11 @@ fakeModel.prototype.findAndCountAll = function (options) { * @param {Integer} id ID of the instance * @return {Promise} Promise that resolves with an instance with the given ID **/ -fakeModel.prototype.findById = function (id) { +fakeModel.prototype.findByPk = function (id) { var self = this; return this.$query({ - query: "findById", + query: "findByPk", queryOptions: arguments, fallbackFn: !this.options.autoQueryFallback ? null : function () { return Promise.resolve( self.build({ id: id }) ); @@ -395,6 +386,53 @@ fakeModel.prototype.findOne = function (obj) { }); }; + +/** + * Executes a mock query to count all of the instances with any provided options. + * Without any other configuration, the default behavior when no queueud query result + * is present is to create result with the value 1 wrapped in promise. + * + * To turn off this behavior, the `$autoQueryFallback` option on the model should be set + * to `false`. + * + * @example + * // This is an example of the default behavior with no queued results + * // If there is a queued result or failure, that will be returned instead + * User.count({ + * where: { + * email: 'myEmail@example.com', + * }, + * }).then(function (count) { + * // count returns the actual value + * count == 1; // true + * }); + * + * @instance + * @method count + * @param {Object} [options] Options for the count query + * @param {Object} [options.where] Values that any automatically created Instances should have + * @return {Promise} result returned by the mock query + **/ +fakeModel.prototype.count = function(options) { + var self = this; + + return this.$query({ + query: "count", + queryOptions: arguments, + fallbackFn: !this.options.autoQueryFallback + ? null + : function() { + return Promise.resolve([ + self.build(options ? options.where : {}) + ]).then(function(result) { + return Promise.resolve(result.length); + }); + } + }); +}; + + + /** * Executes a mock query to find the max value of a field. Without any other * configuration, the default behavior when no queueud query result is present @@ -525,7 +563,7 @@ fakeModel.prototype.upsert = function (values) { query: "upsert", queryOptions: arguments, fallbackFn: !this.options.autoQueryFallback ? null : function () { - return self.build(values).save().return(self.options.createdDefault); + return self.build(values).save().then((()=>self.options.createdDefault)) }, }); } diff --git a/src/queryinterface.js b/src/queryinterface.js index d86d0ff..4b9f366 100644 --- a/src/queryinterface.js +++ b/src/queryinterface.js @@ -20,8 +20,7 @@ * @fileOverview The mock QueryInterface base that is used for returning results from queries for tests **/ -var bluebird = require('bluebird'), - _ = require('lodash'), +var _ = require('lodash'), Errors = require('./errors'); /** @@ -180,7 +179,7 @@ function resultsQueueHandler(qi, options) { } if(result.type == 'Failure') { - return bluebird.reject(result.content); + return Promise.reject(result.content); } if(options.includeCreated) { @@ -189,7 +188,7 @@ function resultsQueueHandler(qi, options) { created = !!result.options.wasCreated; } - return bluebird.resolve([result.content, created]); + return Promise.resolve([result.content, created]); } if (options.includeAffectedRows) { var affectedRows = []; @@ -197,9 +196,9 @@ function resultsQueueHandler(qi, options) { affectedRows = result.options.affectedRows; } - return bluebird.resolve([result.content, affectedRows]); + return Promise.resolve([result.content, affectedRows]); } - return bluebird.resolve(result.content); + return Promise.resolve(result.content); } } @@ -256,7 +255,7 @@ QueryInterface.prototype.$query = function (options) { processHandler(handlers.shift()); // Always convert the result to a promise. If the promise was rejected, this method will return a rejected promise. - return bluebird.resolve(result); + return Promise.resolve(result); }; module.exports = QueryInterface; diff --git a/src/sequelize.js b/src/sequelize.js index 485b4d2..1e6e7f5 100644 --- a/src/sequelize.js +++ b/src/sequelize.js @@ -9,7 +9,6 @@ var path = require('path'), _ = require('lodash'), - bluebird = require('bluebird'), Model = require('./model'), Instance = require('./instance'), Utils = require('./utils'), @@ -17,6 +16,34 @@ var path = require('path'), DataTypes = require('./data-types')({}), QueryInterface = require('./queryinterface'); +/** + * Col object + * @class + * @param {String} val + */ +function Col(val) { + this.toString = function() { + return val; + }; +}; + +/** + * Fn object + * @class + * @param {String} val + * @param {any[]} [args] + */ +function Fn(val, args) { + if (typeof args === 'undefined') { + args = []; + } + + this.toString = function() { + return val + '(' + _.map(args, JSON.stringify).join(', ') + ')'; + }; +}; + + /** * Sequelize Mock Object. This can be initialize much the same way that Sequelize itself * is initialized. Any configuration or options is ignored, so it can be used as a drop-in @@ -87,6 +114,43 @@ Sequelize.version = require('../package.json').version; **/ Sequelize.options = {hooks: {}}; +/** + * Creates an object which represents a column in the DB, this allows referencing another column in your query. This is often useful in conjunction with `sequelize.fn`, since raw string arguments to fn will be escaped. + * @method col + * @memberof Sequelize + * @param {String} col The name of the column + * @return {Col} + */ +Sequelize.col = function(val) { + return new Col(val); +} + +/** + * Creates an object representing a database function. This can be used in search queries, both in where and order parts, and as default values in column definitions. + * If you want to refer to columns in your function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and not a strings. + * + * @method fn + * @memberof Sequelize + * @param {String} fn The function you want to call + * @param {any[]} args All further arguments will be passed as arguments to the function + * @return {Fn} + */ +Sequelize.fn = function(val, args) { + return new Fn(val, args); +} + +/** + * Creates an object representing a literal, i.e. something that will not be escaped. + * + * @method literal + * @memberof Sequelize + * @param {any} val + * @return {String} + */ +Sequelize.literal = function(val) { + return val; +} + /** * Reference to the mock Sequelize class * @@ -102,11 +166,11 @@ Sequelize.prototype.Sequelize = Sequelize; Sequelize.prototype.Utils = Sequelize.Utils = Utils; /** - * Reference to the bluebird promise library + * Reference to the Promise library * * @property **/ -Sequelize.prototype.Promise = Sequelize.Promise = bluebird; +Sequelize.prototype.Promise = Sequelize.Promise = Promise; /** * Object containing all of the [Sequelize QueryTypes](https://github.com/sequelize/sequelize/blob/3e5b8772ef75169685fc96024366bca9958fee63/lib/query-types.js). @@ -334,13 +398,8 @@ Sequelize.prototype.import = function (importPath) { importPath = path.resolve(callLoc, importPath); } - if(this.importCache[importPath] === 'string' || !this.importCache[importPath]) { - var defineCall = arguments.length > 1 ? arguments[1] : require(importPath); - if(typeof defineCall === 'object') { - // ES6 module compatibility - defineCall = defineCall.default; - } - this.importCache[importPath] = defineCall(this, DataTypes); + if(this.importCache[importPath] === 'string' || !this.importCache[importPath]) { + this.importCache[importPath] = require(importPath)(this, DataTypes); } return this.importCache[importPath]; @@ -382,37 +441,36 @@ Sequelize.prototype.query = function () { * @param {Function} [fn] Optional function to run as a tranasction * @return {Promise} Promise that resolves the code is successfully run, otherwise it is rejected */ -Sequelize.prototype.transaction = function (fn) { - if(!fn) { - fn = function (t) { - return bluebird.resolve(t); +Sequelize.prototype.transaction = function (options, autoCallback) { + if (typeof options === 'function') { + autoCallback = options; + options = undefined; + } + if(!autoCallback) { + autoCallback = function (t) { + return Promise.resolve(t); }; } - return new bluebird(function (resolve, reject) { + return new Promise(function (resolve, reject) { // TODO Return mock transaction object - return fn({}).then(resolve, reject); + return autoCallback({}).then(resolve, reject); }); }; -/** - * Simply returns the first argument passed in, unmodified. - * - * @param {Any} arg Value to return - * @return {Any} value passed in - */ -Sequelize.prototype.literal = function (arg) { - return arg; -}; - /** * Always returns a resolved promise * * @return {Promise} will always resolve as a successful authentication */ Sequelize.prototype.authenticate = function() { - return new bluebird(function (resolve) { + return new Promise(function (resolve) { return resolve(); }); }; +// Aliases +Sequelize.prototype.fn = Sequelize.fn; +Sequelize.prototype.col = Sequelize.col; +Sequelize.prototype.literal = Sequelize.asIs = Sequelize.prototype.asIs = Sequelize.literal; + module.exports = Sequelize; diff --git a/test/instance.spec.js b/test/instance.spec.js index e45c145..a7c79a6 100644 --- a/test/instance.spec.js +++ b/test/instance.spec.js @@ -1,7 +1,6 @@ 'use strict'; var should = require('should'); -var bluebird = require('bluebird'); var proxyquire = require('proxyquire').noCallThru(); var ErrorMock = { @@ -161,25 +160,7 @@ describe('Instance', function () { inst.get().should.be.eql({foo: 'bar'}); }); }); - - describe('#getDataValue', function () { - it('should get the value of a property on the object', function () { - var inst = new Instance(); - inst._values.foo = 'bar'; - - inst.getDataValue('foo').should.be.exactly('bar'); - }); - }); - - describe('#setDataValue', function () { - it('should set the value of a property on the object', function () { - var inst = new Instance(); - inst._values.foo = 'bar'; - inst.setDataValue('foo', 'baz'); - inst._values.foo.should.be.exactly('baz'); - }); - }); - + describe('#validate', function () { it('should return no validation errors if no errors are set on the instances', function (done) { var inst = new Instance(); @@ -262,7 +243,7 @@ describe('Instance', function () { describe('#destroy', function () { it('should return a promise object', function () { var inst = new Instance(); - inst.destroy().should.be.instanceOf(bluebird); + inst.destroy().should.be.instanceOf(Promise); }); }); diff --git a/test/model.spec.js b/test/model.spec.js index 02067cf..3626597 100644 --- a/test/model.spec.js +++ b/test/model.spec.js @@ -1,11 +1,10 @@ 'use strict'; var should = require('should'); -var bluebird = require('bluebird'); var proxyquire = require('proxyquire').noCallThru(); var InstanceMock = function () { this._args = arguments; }; -InstanceMock.prototype.save = function () { return bluebird.resolve(this); }; +InstanceMock.prototype.save = function () { return Promise.resolve(this); }; var UtilsMock = { uppercaseFirst: function (str) { return str; }, @@ -162,13 +161,14 @@ describe('Model', function () { // mdl.should.have.property('schema').which.is.a.Function(); mdl.should.have.property('getTableName').which.is.a.Function(); mdl.should.have.property('unscoped').which.is.a.Function(); - mdl.should.have.property('addScope').which.is.a.Function(); + // mdl.should.have.property('addScope').which.is.a.Function(); mdl.should.have.property('scope').which.is.a.Function(); mdl.should.have.property('find').which.is.a.Function(); mdl.should.have.property('findAll').which.is.a.Function(); mdl.should.have.property('findAndCount').which.is.a.Function(); mdl.should.have.property('findAndCountAll').which.is.a.Function(); - mdl.should.have.property('findById').which.is.a.Function(); + mdl.should.have.property("count").which.is.a.Function(); + mdl.should.have.property('findByPk').which.is.a.Function(); mdl.should.have.property('findOne').which.is.a.Function(); // mdl.should.have.property('aggregate').which.is.a.Function(); // mdl.should.have.property('count').which.is.a.Function(); @@ -209,7 +209,7 @@ describe('Model', function () { }); it('should return a promise', function () { - mdl.sync().should.be.instanceOf(bluebird); + mdl.sync().should.be.instanceOf(Promise); }); }); @@ -220,7 +220,7 @@ describe('Model', function () { }); it('should return a promise', function () { - mdl.drop().should.be.instanceOf(bluebird); + mdl.drop().should.be.instanceOf(Promise); }); }); @@ -283,7 +283,7 @@ describe('Model', function () { 'baz' : 'bin' }; - mdl.update(vals).fallbackFn().spread(function (number, rows) { + mdl.update(vals).fallbackFn().then(function ([number, rows]) { number.should.equal(1); done(); }).catch(done); @@ -295,7 +295,7 @@ describe('Model', function () { }; mdl.update(vals, {returning: true}) - .fallbackFn().spread(function (number, rows) { + .fallbackFn().then(function ([number, rows]) { rows.should.be.Array(); rows[0]._args[0].should.have.property('baz').which.is.exactly('bin'); done(); @@ -373,14 +373,14 @@ describe('Model', function () { }); }); - describe('#findById', function () { + describe('#findByPk', function () { var mdl; beforeEach(function () { mdl = new Model('foo'); }); it('should find a row with the given id', function (done) { - mdl.findById(1234) + mdl.findByPk(1234) .fallbackFn().then(function (inst) { inst._args[0].id.should.equal(1234); done(); @@ -389,17 +389,17 @@ describe('Model', function () { it('should not pass along a fallback function if auto fallback is turned off', function () { mdl.options.autoQueryFallback = false; - should.not.exist(mdl.findById().fallbackFn); + should.not.exist(mdl.findByPk().fallbackFn); }); it('should pass query info to the QueryInterface instance', function(done) { mdl.$query = function(options) { - options.query.should.equal('findById'); + options.query.should.equal('findByPk'); options.queryOptions.length.should.equal(1); options.queryOptions[0].should.equal(123); done(); } - mdl.findById(123); + mdl.findByPk(123); }); }); @@ -483,7 +483,7 @@ describe('Model', function () { }; mdl.findOrCreate(options) - .fallbackFn().spread(function (inst, created) { + .fallbackFn().then(function ([inst, created]) { inst._args[0].should.have.property('foo').which.is.exactly('bar'); done(); }).catch(done); @@ -491,7 +491,7 @@ describe('Model', function () { it('should return the createdDefault value for the model', function (done) { mdl.findOrCreate({}) - .fallbackFn().spread(function (inst, created) { + .fallbackFn().then(function ([inst, created]) { created.should.equal(mdl.options.createdDefault); done(); }).catch(done); @@ -656,6 +656,56 @@ describe('Model', function () { }); }); + describe("#Count", function() { + let mdl + beforeEach(function() { + mdl = new Model("foo"); + }); + + it("should pass along where value to Instance creation", function(done) { + var options = { + where: { + foo: "bar" + } + }; + + mdl.count(options) + .fallbackFn() + .then(function(result) { + result.should.equal(1); + done(); + }) + .catch(done); + }); + + it("should still find results if there is not options", function(done) { + mdl.count() + .fallbackFn() + .then(function(result) { + result.should.equal(1); + done(); + }) + .catch(done); + }); + + it("should not pass along a fallback function if auto fallback is turned off", function() { + mdl.options.autoQueryFallback = false; + should.not.exist(mdl.count().fallbackFn); + }); + + it("should pass query info to the QueryInterface instance", function(done) { + var queryOptions = {}; + + mdl.$query = function(options) { + options.query.should.equal("count"); + options.queryOptions.length.should.equal(1); + options.queryOptions[0].should.equal(queryOptions); + done(); + }; + mdl.count(queryOptions); + }); + }); + describe('#destroy', function () { var mdl; beforeEach(function () { diff --git a/test/queryinterface.spec.js b/test/queryinterface.spec.js index 8e7df8a..06b005e 100644 --- a/test/queryinterface.spec.js +++ b/test/queryinterface.spec.js @@ -1,7 +1,6 @@ 'use strict'; var should = require('should'); -var bluebird = require('bluebird'); var proxyquire = require('proxyquire').noCallThru(); var util = require('util'); @@ -348,7 +347,7 @@ describe('QueryInterface', function () { it('should return the promise of the handler', function(done) { qi.$useHandler(function(query, options) { - return bluebird.resolve('handler value'); + return Promise.resolve('handler value'); }); qi.$query().then(function(value) { value.should.equal('handler value'); @@ -358,7 +357,7 @@ describe('QueryInterface', function () { it('should respect rejected promises returned from handler', function(done) { qi.$useHandler(function(query, options) { - return bluebird.reject('error'); + return Promise.reject('error'); }); qi.$query().catch(function(error) { error.should.equal('error'); @@ -368,7 +367,7 @@ describe('QueryInterface', function () { it('should return a promise even if the value is undefined', function(done) { qi.$useHandler(function(query, options) { - return bluebird.resolve(undefined); + return Promise.resolve(undefined); }); qi.$query().then(function(value) { (typeof target).should.be.equal('undefined'); @@ -390,7 +389,7 @@ describe('QueryInterface', function () { it('should work with async handlers', function(done) { qi.$useHandler(function(query, options) { - return new bluebird(function(resolve, reject) { + return new Promise(function(resolve, reject) { resolve('done'); }); }); @@ -486,7 +485,7 @@ describe('QueryInterface', function () { }]; var result = qi.$query({ includeCreated: true }); - result.spread(function (content, created) { + result.then(function ([content, created]) { content.should.equal('foo'); created.should.be.true(); done(); @@ -502,7 +501,7 @@ describe('QueryInterface', function () { }]; var result = qi.$query({ includeCreated: true }); - result.spread(function (content, created) { + result.then(function ([content, created]) { content.should.equal('foo'); created.should.be.false(); done(); @@ -522,11 +521,11 @@ describe('QueryInterface', function () { }]; var result = qi.$query({ includeCreated: true }); - result.spread(function (content, created) { + result.then(function ([content, created]) { content.should.equal('foo'); created.should.be.true(); return qi.$query({ includeCreated: true }); - }).spread(function (content, created) { + }).then(function ([content, created]) { content.should.equal('bar'); created.should.be.false(); done(); @@ -550,7 +549,7 @@ describe('QueryInterface', function () { }]; var result = qi.$query({ includeAffectedRows: true }); - result.spread(function (content, affectedRows) { + result.then(function ([content, affectedRows]) { content.should.equal('foo'); affectedRows.should.be.an.Array(); affectedRows.length.should.equal(0); @@ -567,7 +566,7 @@ describe('QueryInterface', function () { }]; var result = qi.$query({ includeAffectedRows: true }); - result.spread(function (content, affectedRows) { + result.then(function ([content, affectedRows]) { content.should.equal('foo'); affectedRows.should.equal(rows); done(); diff --git a/test/sequelize.spec.js b/test/sequelize.spec.js index 5072d48..14a7a78 100644 --- a/test/sequelize.spec.js +++ b/test/sequelize.spec.js @@ -1,7 +1,6 @@ 'use strict'; var should = require('should'); -var bluebird = require('bluebird'); var proxyquire = require('proxyquire').noCallThru(); var ModelMock = function () {}; @@ -39,7 +38,6 @@ var Sequelize = proxyquire('../src/sequelize', { './data-types' : function () {}, 'import-test' : importTestFunc, - 'import-test-es6' : { default: importTestFunc }, }); describe('Sequelize', function () { @@ -48,14 +46,14 @@ describe('Sequelize', function () { Sequelize.should.have.property('version').which.is.equal('test'); Sequelize.should.have.property('options'); Sequelize.should.have.property('Utils').which.is.equal(UtilsMock); - Sequelize.should.have.property('Promise').which.is.equal(bluebird); + Sequelize.should.have.property('Promise').which.is.equal(Promise); Sequelize.should.have.property('Model').which.is.equal(ModelMock); }); it('should have top level constants on instances of class', function () { var seq = new Sequelize(); seq.should.have.property('Utils').which.is.equal(UtilsMock); - seq.should.have.property('Promise').which.is.equal(bluebird); + seq.should.have.property('Promise').which.is.equal(Promise); seq.should.have.property('Model').which.is.equal(ModelMock); }); @@ -273,18 +271,6 @@ describe('Sequelize', function () { }; seq.import('foo').should.be.exactly(findItem); }); - - it('should import an es6 model from the given path', function () { - seq.import('import-test-es6'); - should(lastImportTestCall).not.be.Null(); - lastImportTestCall[0].should.be.exactly(seq); - }); - - it('should import a model function as the second argument (for meteor compatibility)', function () { - seq.import('import-test', importTestFunc); - should(lastImportTestCall).not.be.Null(); - lastImportTestCall[0].should.be.exactly(seq); - }); }); describe('#model', function() { @@ -323,6 +309,18 @@ describe('Sequelize', function () { }); describe('#transaction', function () { + it('should allow an options object as the first optional argument', function (done) { + var seq = new Sequelize(), + count = 0; + seq.transaction({}, function () { + count++; + return Promise.resolve(); + }).then(function () { + count.should.equal(1); + done() + }).catch(done); + }); + it('should run a passed in function', function (done) { var seq = new Sequelize(), count = 0; @@ -344,6 +342,20 @@ describe('Sequelize', function () { }); }); + describe('#fn', function () { + it('should simply return the function for the fn function', function () { + var seq = new Sequelize(); + seq.fn('Test', ['string', 123]).toString().should.equal('Test("string", 123)'); + }); + }); + + describe('#col', function () { + it('should simply return the argument for the col function', function () { + var seq = new Sequelize(); + seq.col('Test').toString().should.equal('Test'); + }); + }); + describe('#literal', function () { it('should simply return the argument for the literal function', function () { var seq = new Sequelize();