model-utils.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { Model, isModelStatic, isSameInitialModel } from '@sequelize/core';
  2. import { expect } from 'chai';
  3. import { sequelize } from '../../support';
  4. describe('isModelStatic', () => {
  5. it('returns true for model subclasses', () => {
  6. const MyModel = sequelize.define('MyModel', {});
  7. expect(isModelStatic(MyModel)).to.be.true;
  8. });
  9. it('returns false for model instances', () => {
  10. const MyModel = sequelize.define('MyModel', {});
  11. expect(isModelStatic(MyModel.build())).to.be.false;
  12. });
  13. it('returns false for the Model class', () => {
  14. expect(isModelStatic(Model)).to.be.false;
  15. });
  16. it('returns false for the anything else', () => {
  17. expect(isModelStatic(Date)).to.be.false;
  18. });
  19. });
  20. describe('isSameInitialModel', () => {
  21. it('returns true if both models have the same initial model', () => {
  22. const MyModel = sequelize.define(
  23. 'MyModel',
  24. {},
  25. {
  26. scopes: {
  27. scope1: {
  28. where: { id: 1 },
  29. },
  30. },
  31. },
  32. );
  33. expect(isSameInitialModel(MyModel.withSchema('abc'), MyModel.withScope('scope1'))).to.be.true;
  34. });
  35. it('returns false if the models are different', () => {
  36. const MyModel1 = sequelize.define('MyModel1', {});
  37. const MyModel2 = sequelize.define('MyModel2', {});
  38. expect(isSameInitialModel(MyModel1, MyModel2)).to.be.false;
  39. });
  40. });