notExist.test.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use strict';
  2. const chai = require('chai');
  3. const expect = chai.expect;
  4. const Support = require('../support');
  5. const { DataTypes } = require('@sequelize/core');
  6. describe(Support.getTestDialectTeaser('Model'), () => {
  7. beforeEach(async function () {
  8. this.Order = this.sequelize.define('Order', {
  9. id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  10. sequence: DataTypes.INTEGER,
  11. amount: DataTypes.FLOAT,
  12. type: DataTypes.STRING,
  13. });
  14. await this.sequelize.sync({ force: true });
  15. await this.Order.bulkCreate([
  16. { sequence: 1, amount: 3, type: 'A' },
  17. { sequence: 2, amount: 4, type: 'A' },
  18. { sequence: 3, amount: 5, type: 'A' },
  19. { sequence: 4, amount: 1, type: 'A' },
  20. { sequence: 1, amount: 2, type: 'B' },
  21. { sequence: 2, amount: 6, type: 'B' },
  22. { sequence: 0, amount: 0, type: 'C' },
  23. ]);
  24. });
  25. describe('max', () => {
  26. it('type A to C should exist', async function () {
  27. await expect(this.Order.sum('sequence', { where: { type: 'A' } })).to.eventually.be.equal(10);
  28. await expect(this.Order.max('sequence', { where: { type: 'A' } })).to.eventually.be.equal(4);
  29. await expect(this.Order.min('sequence', { where: { type: 'A' } })).to.eventually.be.equal(1);
  30. await expect(this.Order.sum('amount', { where: { type: 'A' } })).to.eventually.be.equal(13);
  31. await expect(this.Order.max('amount', { where: { type: 'A' } })).to.eventually.be.equal(5);
  32. await expect(this.Order.min('amount', { where: { type: 'A' } })).to.eventually.be.equal(1);
  33. await expect(this.Order.sum('sequence', { where: { type: 'B' } })).to.eventually.be.equal(3);
  34. await expect(this.Order.max('sequence', { where: { type: 'B' } })).to.eventually.be.equal(2);
  35. await expect(this.Order.min('sequence', { where: { type: 'B' } })).to.eventually.be.equal(1);
  36. await expect(this.Order.sum('amount', { where: { type: 'B' } })).to.eventually.be.equal(8);
  37. await expect(this.Order.max('amount', { where: { type: 'B' } })).to.eventually.be.equal(6);
  38. await expect(this.Order.min('amount', { where: { type: 'B' } })).to.eventually.be.equal(2);
  39. await expect(this.Order.sum('sequence', { where: { type: 'C' } })).to.eventually.be.equal(0);
  40. await expect(this.Order.max('sequence', { where: { type: 'C' } })).to.eventually.be.equal(0);
  41. await expect(this.Order.min('sequence', { where: { type: 'C' } })).to.eventually.be.equal(0);
  42. await expect(this.Order.sum('amount', { where: { type: 'C' } })).to.eventually.be.equal(0);
  43. await expect(this.Order.max('amount', { where: { type: 'C' } })).to.eventually.be.equal(0);
  44. await expect(this.Order.min('amount', { where: { type: 'C' } })).to.eventually.be.equal(0);
  45. });
  46. it('type D should not exist', async function () {
  47. await expect(this.Order.sum('sequence', { where: { type: 'D' } })).to.eventually.be.null;
  48. await expect(this.Order.max('sequence', { where: { type: 'D' } })).to.eventually.be.null;
  49. await expect(this.Order.min('sequence', { where: { type: 'D' } })).to.eventually.be.null;
  50. await expect(this.Order.sum('amount', { where: { type: 'D' } })).to.eventually.be.null;
  51. await expect(this.Order.max('amount', { where: { type: 'D' } })).to.eventually.be.null;
  52. await expect(this.Order.min('amount', { where: { type: 'D' } })).to.eventually.be.null;
  53. });
  54. });
  55. });