increment.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. const { expect } = require('chai');
  3. const { sequelize } = require('../../support');
  4. const { DataTypes } = require('@sequelize/core');
  5. const sinon = require('sinon');
  6. describe('Model#increment', () => {
  7. it('is not allowed if the instance does not have a primary key defined', async () => {
  8. const User = sequelize.define('User', {});
  9. const instance = User.build({});
  10. await expect(instance.increment()).to.be.rejectedWith(
  11. 'but this model instance is missing the value of its primary key',
  12. );
  13. });
  14. describe('options tests', () => {
  15. let stub;
  16. before(() => {
  17. stub = sinon.stub(sequelize, 'queryRaw').resolves({
  18. _previousDataValues: { id: 1 },
  19. dataValues: { id: 3 },
  20. });
  21. });
  22. after(() => {
  23. stub.restore();
  24. });
  25. it('should allow increments even if options are not given', () => {
  26. const User = sequelize.define('User', {
  27. id: {
  28. type: DataTypes.INTEGER,
  29. primaryKey: true,
  30. autoIncrement: true,
  31. },
  32. });
  33. const instance = User.build({ id: 1 }, { isNewRecord: false });
  34. expect(() => {
  35. instance.increment(['id']);
  36. }).to.not.throw();
  37. });
  38. });
  39. });