不要怂,就是干,撸起袖子干!

Commit 8cd25ce9 by smihica

Added tests.

1 parent fb6a4451
'use strict';
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, Sequelize = Support.Sequelize
, sinon = require('sinon');
describe(Support.getTestDialectTeaser('Instance'), function() {
describe('decrement', function () {
describe('options tests', function() {
var stub
, Model = current.define('User', {
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
}
})
, instance;
before(function() {
stub = sinon.stub(current, 'query').returns(
Sequelize.Promise.resolve({
_previousDataValues: {id: 3},
dataValues: {id: 1}
})
);
});
after(function() {
stub.restore();
});
it('should allow decrements even if options are not given', function () {
instance = Model.build({id: 3}, {isNewRecord: false});
expect(function () {
instance.decrement(['id']);
}).to.not.throw();
});
it('should not modify options when it given to decrement', function () {
instance = Model.build({id: 3}, {isNewRecord: false});
var options = { by: 2 };
instance.decrement(['id'], options);
expect(options).to.deep.equal({ by: 2 });
});
});
});
});
'use strict';
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, Sequelize = Support.Sequelize
, sinon = require('sinon');
describe(Support.getTestDialectTeaser('Instance'), function() {
describe('destroy', function () {
describe('options tests', function() {
var stub
, Model = current.define('User', {
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
}
})
, instance;
before(function() {
stub = sinon.stub(current, 'query').returns(
Sequelize.Promise.resolve({
_previousDataValues: {},
dataValues: {id: 1}
})
);
});
after(function() {
stub.restore();
});
it('should allow destroies even if options are not given', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
expect(function () {
instance.destroy();
}).to.not.throw();
});
it('should not modify options when it given to destroy', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
var options = { transaction: null };
instance.destroy(options);
expect(options).to.deep.equal({ transaction: null });
});
});
});
});
'use strict';
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, Sequelize = Support.Sequelize
, sinon = require('sinon');
describe(Support.getTestDialectTeaser('Instance'), function() {
describe('increment', function () {
describe('options tests', function() {
var stub
, Model = current.define('User', {
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
}
})
, instance;
before(function() {
stub = sinon.stub(current, 'query').returns(
Sequelize.Promise.resolve({
_previousDataValues: {id: 1},
dataValues: {id: 3}
})
);
});
after(function() {
stub.restore();
});
it('should allow increments even if options are not given', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
expect(function () {
instance.increment(['id']);
}).to.not.throw();
});
it('should not modify options when it given to increment', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
var options = { by: 2 };
instance.increment(['id'], options);
expect(options).to.deep.equal({ by: 2 });
});
});
});
});
'use strict';
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, Sequelize = Support.Sequelize
, sinon = require('sinon');
describe(Support.getTestDialectTeaser('Instance'), function() {
describe('reload', function () {
describe('options tests', function() {
var stub
, Model = current.define('User', {
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
},
deletedAt: {
type: Sequelize.DATE,
}
}, {
paranoid: true
})
, instance;
before(function() {
stub = sinon.stub(current, 'query').returns(
Sequelize.Promise.resolve({
_previousDataValues: {id: 1},
dataValues: {id: 2}
})
);
});
after(function() {
stub.restore();
});
it('should allow reloads even if options are not given', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
expect(function () {
instance.reload();
}).to.not.throw();
});
it('should not modify options when it given to reload', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
var options = { transaction: null };
instance.reload(options);
expect(options).to.deep.equal({ transaction: null });
});
});
});
});
'use strict';
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, Sequelize = Support.Sequelize
, sinon = require('sinon');
describe(Support.getTestDialectTeaser('Instance'), function() {
describe('restore', function () {
describe('options tests', function() {
var stub
, Model = current.define('User', {
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
},
deletedAt: {
type: Sequelize.DATE,
}
}, {
paranoid: true
})
, instance;
before(function() {
stub = sinon.stub(current, 'query').returns(
Sequelize.Promise.resolve({
_previousDataValues: {id: 1},
dataValues: {id: 2}
})
);
});
after(function() {
stub.restore();
});
it('should allow restores even if options are not given', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
expect(function () {
instance.restore();
}).to.not.throw();
});
it('should not modify options when it given to restore', function () {
instance = Model.build({id: 1}, {isNewRecord: false});
var options = { transaction: null };
instance.restore(options);
expect(options).to.deep.equal({ transaction: null });
});
});
});
});
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
var chai = require('chai') var chai = require('chai')
, expect = chai.expect , expect = chai.expect
, Support = require(__dirname + '/../support') , Support = require(__dirname + '/../support')
, current = Support.sequelize; , current = Support.sequelize
, Sequelize = Support.Sequelize
, sinon = require('sinon');
describe(Support.getTestDialectTeaser('Instance'), function() { describe(Support.getTestDialectTeaser('Instance'), function() {
describe('save', function () { describe('save', function () {
...@@ -19,5 +21,44 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -19,5 +21,44 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
instance.save(); instance.save();
}).to.throw(); }).to.throw();
}); });
describe('options tests', function() {
var stub
, Model = current.define('User', {
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
}
})
, instance;
before(function() {
stub = sinon.stub(current, 'query').returns(
Sequelize.Promise.resolve({
_previousDataValues: {},
dataValues: {id: 1}
})
);
});
after(function() {
stub.restore();
});
it('should allow saves even if options are not given', function () {
instance = Model.build({});
expect(function () {
instance.save();
}).to.not.throw();
});
it('should not modify options when it given to save', function () {
instance = Model.build({});
var options = { transaction: null };
instance.save(options);
expect(options).to.deep.equal({ transaction: null });
});
});
}); });
}); });
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!