Example #1
0
        test('should throw an error if `value` is invalid', () => {
          const type = DataTypes.TINYINT();

          expect(() => {
            type.validate('foobar');
          }).to.throw(Sequelize.ValidationError, '"foobar" is not a valid tinyint');

          expect(() => {
            type.validate(123.45);
          }).to.throw(Sequelize.ValidationError, '123.45 is not a valid tinyint');
        });
Example #2
0
        test('should return `true` if `value` is an integer', () => {
          const type = DataTypes.TINYINT();

          expect(type.validate(-128)).to.equal(true);
          expect(type.validate('127')).to.equal(true);
        });
Example #3
0
    suite('TINYINT', () => {
      const cases = [
        {
          title: 'TINYINT',
          dataType: DataTypes.TINYINT,
          expect: {
            default: 'TINYINT'
          }
        },
        {
          title: 'TINYINT(2)',
          dataType: DataTypes.TINYINT(2),
          expect: {
            default: 'TINYINT(2)',
            mssql: 'TINYINT'
          }
        },
        {
          title: 'TINYINT({ length: 2 })',
          dataType: DataTypes.TINYINT({ length: 2 }),
          expect: {
            default: 'TINYINT(2)',
            mssql: 'TINYINT'
          }
        },
        {
          title: 'TINYINT.UNSIGNED',
          dataType: DataTypes.TINYINT.UNSIGNED,
          expect: {
            default: 'TINYINT UNSIGNED',
            mssql: 'TINYINT'
          }
        },
        {
          title: 'TINYINT(2).UNSIGNED',
          dataType: DataTypes.TINYINT(2).UNSIGNED,
          expect: {
            default: 'TINYINT(2) UNSIGNED',
            sqlite: 'TINYINT UNSIGNED(2)',
            mssql: 'TINYINT'
          }
        },
        {
          title: 'TINYINT.UNSIGNED.ZEROFILL',
          dataType: DataTypes.TINYINT.UNSIGNED.ZEROFILL,
          expect: {
            default: 'TINYINT UNSIGNED ZEROFILL',
            mssql: 'TINYINT'
          }
        },
        {
          title: 'TINYINT(2).UNSIGNED.ZEROFILL',
          dataType: DataTypes.TINYINT(2).UNSIGNED.ZEROFILL,
          expect: {
            default: 'TINYINT(2) UNSIGNED ZEROFILL',
            sqlite: 'TINYINT UNSIGNED ZEROFILL(2)',
            mssql: 'TINYINT'
          }
        },
        {
          title: 'TINYINT.ZEROFILL',
          dataType: DataTypes.TINYINT.ZEROFILL,
          expect: {
            default: 'TINYINT ZEROFILL',
            mssql: 'TINYINT'
          }
        },
        {
          title: 'TINYINT(2).ZEROFILL',
          dataType: DataTypes.TINYINT(2).ZEROFILL,
          expect: {
            default: 'TINYINT(2) ZEROFILL',
            sqlite: 'TINYINT ZEROFILL(2)',
            mssql: 'TINYINT'
          }
        },
        {
          title: 'TINYINT.ZEROFILL.UNSIGNED',
          dataType: DataTypes.TINYINT.ZEROFILL.UNSIGNED,
          expect: {
            default: 'TINYINT UNSIGNED ZEROFILL',
            mssql: 'TINYINT'
          }
        },
        {
          title: 'TINYINT(2).ZEROFILL.UNSIGNED',
          dataType: DataTypes.TINYINT(2).ZEROFILL.UNSIGNED,
          expect: {
            default: 'TINYINT(2) UNSIGNED ZEROFILL',
            sqlite: 'TINYINT UNSIGNED ZEROFILL(2)',
            mssql: 'TINYINT'
          }
        }
      ];
      cases.forEach(row => {
        testsql(row.title, row.dataType, row.expect);
      });

      suite('validate', () => {
        test('should throw an error if `value` is invalid', () => {
          const type = DataTypes.TINYINT();

          expect(() => {
            type.validate('foobar');
          }).to.throw(Sequelize.ValidationError, '"foobar" is not a valid tinyint');

          expect(() => {
            type.validate(123.45);
          }).to.throw(Sequelize.ValidationError, '123.45 is not a valid tinyint');
        });

        test('should return `true` if `value` is an integer', () => {
          const type = DataTypes.TINYINT();

          expect(type.validate(-128)).to.equal(true);
          expect(type.validate('127')).to.equal(true);
        });
      });
    });