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

Commit 5af6cb8f by Sushant Committed by GitHub

test: check MySQL/Postgres return string for decimal/bigint (#7471)

1 parent e31ce8f6
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
- With `BelongsToMany` relationships `add/set/create` setters now set `through` attributes by passing them as `options.through` (previously second argument was used as `through` attributes, now its considered `options` with `through` being a sub option) - With `BelongsToMany` relationships `add/set/create` setters now set `through` attributes by passing them as `options.through` (previously second argument was used as `through` attributes, now its considered `options` with `through` being a sub option)
- `options.order` Now only excepts values with type of array or Sequelize method. Support for string values (ie `{order: 'name DESC'}`) has been deprecated. - `options.order` Now only excepts values with type of array or Sequelize method. Support for string values (ie `{order: 'name DESC'}`) has been deprecated.
- `DataTypes.DATE` now uses `DATETIMEOFFSET` instead of `DATETIME2` sql datatype in case of MSSQL to record timezone [#5403](https://github.com/sequelize/sequelize/issues/5403) - `DataTypes.DATE` now uses `DATETIMEOFFSET` instead of `DATETIME2` sql datatype in case of MSSQL to record timezone [#5403](https://github.com/sequelize/sequelize/issues/5403)
- `DataTypes.DECIMAL` returns string for MySQL and Postgres
# 4.0.0-2 # 4.0.0-2
- [ADDED] include now supports string as an argument (on top of model/association), string will expand into an association matched literally from Model.associations - [ADDED] include now supports string as an argument (on top of model/association), string will expand into an association matched literally from Model.associations
......
...@@ -355,7 +355,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -355,7 +355,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
}); });
} }
if (dialect === 'postgres') { if (dialect === 'postgres' || dialect === 'mysql') {
it('should parse DECIMAL as string', function() { it('should parse DECIMAL as string', function() {
const Model = this.sequelize.define('model', { const Model = this.sequelize.define('model', {
decimal: Sequelize.DECIMAL, decimal: Sequelize.DECIMAL,
...@@ -377,9 +377,18 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -377,9 +377,18 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
return Model.sync({ force: true }).then(() => { return Model.sync({ force: true }).then(() => {
return Model.create(sampleData); return Model.create(sampleData);
}).then(() => { }).then(() => {
return Model.find({id: 1}); return Model.findById(1);
}).then(user => { }).then(user => {
expect(user.get('decimal')).to.be.eql('12345678.12345678'); /**
* MYSQL default precision is 10 and scale is 0
* Thus test case below will return number without any fraction values
*/
if (dialect === 'mysql') {
expect(user.get('decimal')).to.be.eql('12345678');
} else {
expect(user.get('decimal')).to.be.eql('12345678.12345678');
}
expect(user.get('decimalPre')).to.be.eql('123456.1234'); expect(user.get('decimalPre')).to.be.eql('123456.1234');
expect(user.get('decimalWithParser')).to.be.eql('12345678123456781.123456781234567'); expect(user.get('decimalWithParser')).to.be.eql('12345678123456781.123456781234567');
expect(user.get('decimalWithIntParser')).to.be.eql('1.2340'); expect(user.get('decimalWithIntParser')).to.be.eql('1.2340');
...@@ -387,26 +396,6 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -387,26 +396,6 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
}); });
}); });
it('should return Int4 range properly #5747', function() {
const Model = this.sequelize.define('M', {
interval: {
type: Sequelize.RANGE(Sequelize.INTEGER),
allowNull: false,
unique: true
}
});
return Model.sync({ force: true })
.then(() => Model.create({ interval: [1, 4] }) )
.then(() => Model.findAll() )
.spread((m) => {
expect(m.interval[0]).to.be.eql(1);
expect(m.interval[1]).to.be.eql(4);
});
});
}
if (dialect === 'mysql') {
it('should parse BIGINT as string', function() { it('should parse BIGINT as string', function() {
const Model = this.sequelize.define('model', { const Model = this.sequelize.define('model', {
jewelPurity: Sequelize.BIGINT jewelPurity: Sequelize.BIGINT
...@@ -428,6 +417,26 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -428,6 +417,26 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
}); });
} }
if (dialect === 'postgres') {
it('should return Int4 range properly #5747', function() {
const Model = this.sequelize.define('M', {
interval: {
type: Sequelize.RANGE(Sequelize.INTEGER),
allowNull: false,
unique: true
}
});
return Model.sync({ force: true })
.then(() => Model.create({ interval: [1, 4] }) )
.then(() => Model.findAll() )
.spread((m) => {
expect(m.interval[0]).to.be.eql(1);
expect(m.interval[1]).to.be.eql(4);
});
});
}
it('should allow spaces in ENUM', function() { it('should allow spaces in ENUM', function() {
const Model = this.sequelize.define('user', { const Model = this.sequelize.define('user', {
name: Sequelize.STRING, name: Sequelize.STRING,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!