update.test.ts 965 B

123456789101112131415161718192021222324252627
  1. import { DataTypes } from '@sequelize/core';
  2. import { expect } from 'chai';
  3. import { sequelize } from '../../support';
  4. describe('Model#update', () => {
  5. it('is not allowed if the primary key is not defined', async () => {
  6. const User = sequelize.define('User', {
  7. name: { type: DataTypes.STRING },
  8. });
  9. const instance = User.build({}, { isNewRecord: false });
  10. await expect(instance.update({ name: 'john' })).to.be.rejectedWith(
  11. 'You attempted to save an instance with no primary key, this is not allowed since',
  12. );
  13. });
  14. it('is not allowed if the primary key is not defined and is a newly created record', async () => {
  15. const User = sequelize.define('User', {
  16. name: { type: DataTypes.STRING },
  17. });
  18. const instance = User.build({}, { isNewRecord: true });
  19. await expect(instance.update({ name: 'john' })).to.be.rejectedWith(
  20. 'You attempted to update an instance that is not persisted.',
  21. );
  22. });
  23. });