suite('DECIMAL', function () { testsql('DECIMAL', DataTypes.DECIMAL, { default: 'DECIMAL' }); testsql('DECIMAL(10, 2)', DataTypes.DECIMAL(10, 2), { default: 'DECIMAL(10,2)' }); testsql('DECIMAL(10)', DataTypes.DECIMAL(10), { default: 'DECIMAL(10)' }); });
suite('DECIMAL', function () { testsql('DECIMAL', DataTypes.DECIMAL, { default: 'DECIMAL' }); testsql('DECIMAL(10, 2)', DataTypes.DECIMAL(10, 2), { default: 'DECIMAL(10,2)' }); testsql('DECIMAL({ precision: 10, scale: 2 })', DataTypes.DECIMAL({ precision: 10, scale: 2 }), { default: 'DECIMAL(10,2)' }); testsql('DECIMAL(10)', DataTypes.DECIMAL(10), { default: 'DECIMAL(10)' }); testsql('DECIMAL({ precision: 10 })', DataTypes.DECIMAL({ precision: 10 }), { default: 'DECIMAL(10)' }); });
test('should return `true` if `value` is a decimal', () => { const type = DataTypes.DECIMAL(10); expect(type.validate(123)).to.equal(true); expect(type.validate(1.2)).to.equal(true); expect(type.validate(-0.25)).to.equal(true); expect(type.validate(0.0000000000001)).to.equal(true); expect(type.validate('123')).to.equal(true); expect(type.validate('1.2')).to.equal(true); expect(type.validate('-0.25')).to.equal(true); expect(type.validate('0.0000000000001')).to.equal(true); });
test('should throw an error if `value` is invalid', () => { const type = DataTypes.DECIMAL(10); expect(() => { type.validate('foobar'); }).to.throw(Sequelize.ValidationError, '"foobar" is not a valid decimal'); expect(() => { type.validate('0.1a'); }).to.throw(Sequelize.ValidationError, '"0.1a" is not a valid decimal'); expect(() => { type.validate(NaN); }).to.throw(Sequelize.ValidationError, 'null is not a valid decimal'); });
it('should return false when comparing DECIMAL and DECIMAL(10,2)', function(done) { expect(Sequelize.DECIMAL).to.not.equal(Sequelize.DECIMAL(10,2)) done() })
describe(Support.getTestDialectTeaser('DataTypes'), function() { it('should return false when comparing DECIMAL and DECIMAL(10,2)', function(done) { expect(Sequelize.DECIMAL).to.not.equal(Sequelize.DECIMAL(10,2)) done() }) it('DECIMAL(10,2) should be an instance of DECIMAL', function(done) { expect(Sequelize.DECIMAL(10,2)).to.be.an.instanceof(Sequelize.DECIMAL) done() }) it('should return false when comparing FLOAT and FLOAT(11)', function(done) { expect(Sequelize.FLOAT).to.not.equal(Sequelize.FLOAT(11)) done() }) it('FLOAT(11) should be an instance of FLOAT', function(done) { expect(Sequelize.FLOAT(11)).to.be.an.instanceof(Sequelize.FLOAT) done() }) it('should return false when comparing STRING and STRING(4096)', function(done) { expect(Sequelize.STRING).to.not.equal(Sequelize.STRING(4096)) done() }) it('STRING(4096) should be an instance of STRING', function(done) { expect(Sequelize.STRING(4096)).to.be.an.instanceof(Sequelize.STRING) done() }) it('should return false when comparing BIGINT and BIGINT(11)', function(done) { expect(Sequelize.BIGINT).to.not.equal(Sequelize.BIGINT(11)) done() }) it('BIGINT(11) should be an instance of BIGINT', function(done) { expect(Sequelize.BIGINT(11)).to.be.an.instanceof(Sequelize.BIGINT) done() }) var tests = [ [Sequelize.STRING, 'STRING', 'VARCHAR(255)'], [Sequelize.STRING(1234), 'STRING(1234)', 'VARCHAR(1234)'], [Sequelize.STRING(1234).BINARY, 'STRING(1234).BINARY', 'VARCHAR(1234) BINARY'], [Sequelize.STRING.BINARY, 'STRING.BINARY', 'VARCHAR(255) BINARY'], [Sequelize.CHAR, 'CHAR(255)', 'CHAR(255)'], [Sequelize.CHAR(12), 'CHAR(12)', 'CHAR(12)'], [Sequelize.CHAR(12).BINARY, 'CHAR(12).BINARY', 'CHAR(12) BINARY'], [Sequelize.CHAR.BINARY, 'CHAR(255).BINARY', 'CHAR(255) BINARY'], [Sequelize.TEXT, 'TEXT', 'TEXT'], [Sequelize.DATE, 'DATE', 'DATETIME'], [Sequelize.NOW, 'NOW', 'NOW'], [Sequelize.UUID, 'UUID', 'UUID'], [Sequelize.BOOLEAN, 'BOOLEAN', 'TINYINT(1)'], [Sequelize.BLOB, 'BLOB', 'BLOB'], [Sequelize.BLOB('tiny'), 'BLOB(\'tiny\')', 'TINYBLOB'], [Sequelize.BLOB('medium'), 'BLOB(\'medium\')', 'MEDIUMBLOB'], [Sequelize.BLOB('long'), 'BLOB(\'long\')', 'LONGBLOB'], [Sequelize.INTEGER, 'INTEGER', 'INTEGER'], [Sequelize.INTEGER.UNSIGNED, 'INTEGER.UNSIGNED', 'INTEGER UNSIGNED'], [Sequelize.INTEGER(11), 'INTEGER(11)','INTEGER(11)'], [Sequelize.INTEGER(11).UNSIGNED, 'INTEGER(11).UNSIGNED', 'INTEGER(11) UNSIGNED'], [Sequelize.INTEGER(11).UNSIGNED.ZEROFILL,'INTEGER(11).UNSIGNED.ZEROFILL','INTEGER(11) UNSIGNED ZEROFILL'], [Sequelize.INTEGER(11).ZEROFILL,'INTEGER(11).ZEROFILL', 'INTEGER(11) ZEROFILL'], [Sequelize.INTEGER(11).ZEROFILL.UNSIGNED,'INTEGER(11).ZEROFILL.UNSIGNED', 'INTEGER(11) UNSIGNED ZEROFILL'], [Sequelize.BIGINT, 'BIGINT', 'BIGINT'], [Sequelize.BIGINT.UNSIGNED, 'BIGINT.UNSIGNED', 'BIGINT UNSIGNED'], [Sequelize.BIGINT(11), 'BIGINT(11)','BIGINT(11)'], [Sequelize.BIGINT(11).UNSIGNED, 'BIGINT(11).UNSIGNED', 'BIGINT(11) UNSIGNED'], [Sequelize.BIGINT(11).UNSIGNED.ZEROFILL, 'BIGINT(11).UNSIGNED.ZEROFILL','BIGINT(11) UNSIGNED ZEROFILL'], [Sequelize.BIGINT(11).ZEROFILL, 'BIGINT(11).ZEROFILL', 'BIGINT(11) ZEROFILL'], [Sequelize.BIGINT(11).ZEROFILL.UNSIGNED, 'BIGINT(11).ZEROFILL.UNSIGNED', 'BIGINT(11) UNSIGNED ZEROFILL'], [Sequelize.FLOAT, 'FLOAT', 'FLOAT'], [Sequelize.FLOAT.UNSIGNED, 'FLOAT.UNSIGNED', 'FLOAT UNSIGNED'], [Sequelize.FLOAT(11), 'FLOAT(11)','FLOAT(11)'], [Sequelize.FLOAT(11).UNSIGNED, 'FLOAT(11).UNSIGNED', 'FLOAT(11) UNSIGNED'], [Sequelize.FLOAT(11).UNSIGNED.ZEROFILL,'FLOAT(11).UNSIGNED.ZEROFILL','FLOAT(11) UNSIGNED ZEROFILL'], [Sequelize.FLOAT(11).ZEROFILL,'FLOAT(11).ZEROFILL', 'FLOAT(11) ZEROFILL'], [Sequelize.FLOAT(11).ZEROFILL.UNSIGNED,'FLOAT(11).ZEROFILL.UNSIGNED', 'FLOAT(11) UNSIGNED ZEROFILL'], [Sequelize.FLOAT(11, 12), 'FLOAT(11,12)','FLOAT(11,12)'], [Sequelize.FLOAT(11, 12).UNSIGNED, 'FLOAT(11,12).UNSIGNED', 'FLOAT(11,12) UNSIGNED'], [Sequelize.FLOAT(11, 12).UNSIGNED.ZEROFILL,'FLOAT(11,12).UNSIGNED.ZEROFILL','FLOAT(11,12) UNSIGNED ZEROFILL'], [Sequelize.FLOAT(11, 12).ZEROFILL,'FLOAT(11,12).ZEROFILL', 'FLOAT(11,12) ZEROFILL'], [Sequelize.FLOAT(11, 12).ZEROFILL.UNSIGNED,'FLOAT(11,12).ZEROFILL.UNSIGNED', 'FLOAT(11,12) UNSIGNED ZEROFILL'], [Sequelize.DECIMAL, 'DECIMAL', 'DECIMAL'], [Sequelize.DECIMAL(10,2), 'DECIMAL(10,2)','DECIMAL(10,2)'] ] tests.forEach(function(test) { it('transforms "' + test[1] + '" to "' + test[2] + '"', function(done) { expect(test[0].toString()).to.equal(test[2]) done() }) }) })
it('DECIMAL(10,2) should be an instance of DECIMAL', function(done) { expect(Sequelize.DECIMAL(10,2)).to.be.an.instanceof(Sequelize.DECIMAL) done() })
suite('ARRAY', function () { testsql('ARRAY(VARCHAR)', DataTypes.ARRAY(DataTypes.STRING), { postgres: 'VARCHAR(255)[]' }); testsql('ARRAY(VARCHAR(100))', DataTypes.ARRAY(DataTypes.STRING(100)), { postgres: 'VARCHAR(100)[]' }); testsql('ARRAY(INTEGER)', DataTypes.ARRAY(DataTypes.INTEGER), { postgres: 'INTEGER[]' }); testsql('ARRAY(HSTORE)', DataTypes.ARRAY(DataTypes.HSTORE), { postgres: 'HSTORE[]' }); testsql('ARRAY(ARRAY(VARCHAR(255)))', DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.STRING)), { postgres: 'VARCHAR(255)[][]' }); testsql('ARRAY(TEXT)', DataTypes.ARRAY(DataTypes.TEXT), { postgres: 'TEXT[]' }); testsql('ARRAY(DATE)', DataTypes.ARRAY(DataTypes.DATE), { postgres: 'TIMESTAMP WITH TIME ZONE[]' }); testsql('ARRAY(BOOLEAN)', DataTypes.ARRAY(DataTypes.BOOLEAN), { postgres: 'BOOLEAN[]' }); testsql('ARRAY(DECIMAL)', DataTypes.ARRAY(DataTypes.DECIMAL), { postgres: 'DECIMAL[]' }); testsql('ARRAY(DECIMAL(6))', DataTypes.ARRAY(DataTypes.DECIMAL(6)), { postgres: 'DECIMAL(6)[]' }); testsql('ARRAY(DECIMAL(6,4))', DataTypes.ARRAY(DataTypes.DECIMAL(6,4)), { postgres: 'DECIMAL(6,4)[]' }); testsql('ARRAY(DOUBLE)', DataTypes.ARRAY(DataTypes.DOUBLE), { postgres: 'DOUBLE PRECISION[]' }); testsql('ARRAY(REAL))', DataTypes.ARRAY(DataTypes.REAL), { postgres: 'REAL[]' }); if (current.dialect.supports.JSON) { testsql('ARRAY(JSON)', DataTypes.ARRAY(DataTypes.JSON), { postgres: 'JSON[]' }); } if (current.dialect.supports.JSONB) { testsql('ARRAY(JSONB)', DataTypes.ARRAY(DataTypes.JSONB), { postgres: 'JSONB[]' }); } suite('validate', function () { test('should throw an error if `value` is invalid', function() { var type = DataTypes.ARRAY(); expect(function () { type.validate('foobar'); }).to.throw(Sequelize.ValidationError, '"foobar" is not a valid array'); }); test('should return `true` if `value` is an array', function() { var type = DataTypes.ARRAY(); expect(type.validate(['foo', 'bar'])).to.equal(true); }); }); });
suite('ARRAY', function () { testsql('ARRAY(VARCHAR)', DataTypes.ARRAY(DataTypes.STRING), { postgres: 'VARCHAR(255)[]' }); testsql('ARRAY(VARCHAR(100))', DataTypes.ARRAY(DataTypes.STRING(100)), { postgres: 'VARCHAR(100)[]' }); testsql('ARRAY(INTEGER)', DataTypes.ARRAY(DataTypes.INTEGER), { postgres: 'INTEGER[]' }); testsql('ARRAY(HSTORE)', DataTypes.ARRAY(DataTypes.HSTORE), { postgres: 'HSTORE[]' }); testsql('ARRAY(ARRAY(VARCHAR(255)))', DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.STRING)), { postgres: 'VARCHAR(255)[][]' }); testsql('ARRAY(TEXT)', DataTypes.ARRAY(DataTypes.TEXT), { postgres: 'TEXT[]' }); testsql('ARRAY(DATE)', DataTypes.ARRAY(DataTypes.DATE), { postgres: 'TIMESTAMP WITH TIME ZONE[]' }); testsql('ARRAY(DECIMAL)', DataTypes.ARRAY(DataTypes.DECIMAL), { postgres: 'DECIMAL[]' }); testsql('ARRAY(DECIMAL(6))', DataTypes.ARRAY(DataTypes.DECIMAL(6)), { postgres: 'DECIMAL(6)[]' }); testsql('ARRAY(DECIMAL(6,4))', DataTypes.ARRAY(DataTypes.DECIMAL(6,4)), { postgres: 'DECIMAL(6,4)[]' }); testsql('ARRAY(DOUBLE)', DataTypes.ARRAY(DataTypes.DOUBLE), { postgres: 'DOUBLE PRECISION[]' }); testsql('ARRAY(REAL))', DataTypes.ARRAY(DataTypes.REAL), { postgres: 'REAL[]' }); if (current.dialect.supports.JSON) { testsql('ARRAY(JSON)', DataTypes.ARRAY(DataTypes.JSON), { postgres: 'JSON[]' }); } if (current.dialect.supports.JSONB) { testsql('ARRAY(JSONB)', DataTypes.ARRAY(DataTypes.JSONB), { postgres: 'JSONB[]' }); } });
suite('DECIMAL', () => { testsql('DECIMAL', DataTypes.DECIMAL, { default: 'DECIMAL' }); testsql('DECIMAL(10, 2)', DataTypes.DECIMAL(10, 2), { default: 'DECIMAL(10,2)' }); testsql('DECIMAL({ precision: 10, scale: 2 })', DataTypes.DECIMAL({ precision: 10, scale: 2 }), { default: 'DECIMAL(10,2)' }); testsql('DECIMAL(10)', DataTypes.DECIMAL(10), { default: 'DECIMAL(10)' }); testsql('DECIMAL({ precision: 10 })', DataTypes.DECIMAL({ precision: 10 }), { default: 'DECIMAL(10)' }); testsql('DECIMAL.UNSIGNED', DataTypes.DECIMAL.UNSIGNED, { mysql: 'DECIMAL UNSIGNED', default: 'DECIMAL' }); testsql('DECIMAL.UNSIGNED.ZEROFILL', DataTypes.DECIMAL.UNSIGNED.ZEROFILL, { mysql: 'DECIMAL UNSIGNED ZEROFILL', default: 'DECIMAL' }); testsql('DECIMAL({ precision: 10, scale: 2 }).UNSIGNED', DataTypes.DECIMAL({ precision: 10, scale: 2 }).UNSIGNED, { mysql: 'DECIMAL(10,2) UNSIGNED', default: 'DECIMAL(10,2)' }); suite('validate', () => { test('should throw an error if `value` is invalid', () => { const type = DataTypes.DECIMAL(10); expect(() => { type.validate('foobar'); }).to.throw(Sequelize.ValidationError, '"foobar" is not a valid decimal'); expect(() => { type.validate('0.1a'); }).to.throw(Sequelize.ValidationError, '"0.1a" is not a valid decimal'); expect(() => { type.validate(NaN); }).to.throw(Sequelize.ValidationError, 'null is not a valid decimal'); }); test('should return `true` if `value` is a decimal', () => { const type = DataTypes.DECIMAL(10); expect(type.validate(123)).to.equal(true); expect(type.validate(1.2)).to.equal(true); expect(type.validate(-0.25)).to.equal(true); expect(type.validate(0.0000000000001)).to.equal(true); expect(type.validate('123')).to.equal(true); expect(type.validate('1.2')).to.equal(true); expect(type.validate('-0.25')).to.equal(true); expect(type.validate('0.0000000000001')).to.equal(true); }); }); });
it('should return DECIMAL(10,2) for the default decimal type with arguments', function(done) { expect(Sequelize.DECIMAL(10, 2)).to.equal('DECIMAL(10,2)') done() })