remove-attribute.test.ts 988 B

123456789101112131415161718192021222324252627282930313233
  1. import { DataTypes } from '@sequelize/core';
  2. import { expect } from 'chai';
  3. import size from 'lodash/size';
  4. import { getTestDialectTeaser, sequelize } from '../../support';
  5. describe(getTestDialectTeaser('Model'), () => {
  6. describe('removeAttribute', () => {
  7. it('should support removing the primary key', () => {
  8. const Model = sequelize.define('m', {
  9. name: DataTypes.STRING,
  10. });
  11. expect(Model.primaryKeyAttribute).to.equal('id');
  12. expect(size(Model.primaryKeys)).to.equal(1);
  13. Model.removeAttribute('id');
  14. expect(Model.primaryKeyAttribute).to.be.null;
  15. expect(size(Model.primaryKeys)).to.equal(0);
  16. });
  17. it('should not add undefined attribute after removing primary key', () => {
  18. const Model = sequelize.define('m', {
  19. name: DataTypes.STRING,
  20. });
  21. Model.removeAttribute('id');
  22. const instance = Model.build();
  23. expect(instance.dataValues).not.to.include.keys('undefined');
  24. });
  25. });
  26. });