delete.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { DataTypes } from '@sequelize/core';
  2. import { expect } from 'chai';
  3. import sinon from 'sinon';
  4. import { beforeAll2, expectsql, sequelize } from '../../support';
  5. describe('QueryInterface#delete', () => {
  6. const vars = beforeAll2(() => {
  7. const User = sequelize.define(
  8. 'User',
  9. {
  10. firstName: DataTypes.STRING,
  11. },
  12. { timestamps: false },
  13. );
  14. return { User };
  15. });
  16. afterEach(() => {
  17. sinon.restore();
  18. });
  19. // you'll find more replacement tests in query-generator tests
  20. it('does not parse replacements outside of raw sql', async () => {
  21. const { User } = vars;
  22. const stub = sinon.stub(sequelize, 'queryRaw');
  23. await sequelize.queryInterface.bulkDelete(User, {
  24. where: { firstName: ':id' },
  25. replacements: {
  26. limit: 1,
  27. id: '123',
  28. },
  29. });
  30. expect(stub.callCount).to.eq(1);
  31. const firstCall = stub.getCall(0);
  32. expectsql(firstCall.args[0], {
  33. default: `DELETE FROM [Users] WHERE [firstName] = ':id'`,
  34. mssql: `DELETE FROM [Users] WHERE [firstName] = N':id'; SELECT @@ROWCOUNT AS AFFECTEDROWS;`,
  35. });
  36. expect(firstCall.args[1]?.bind).to.be.undefined;
  37. });
  38. });