Skip to content

Commit

Permalink
fix: throw error on null sequelize models (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
DayTF authored Jul 19, 2023
1 parent 7eed822 commit aeb3b01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/datasource-sequelize/src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class SequelizeDataSource extends BaseDataSource<SequelizeCollect
super();

if (!sequelize) throw new Error('Invalid (null) Sequelize instance.');
if (!sequelize.models) throw new Error('Invalid (null) Sequelize models.');

this.sequelize = sequelize;

Expand Down
8 changes: 7 additions & 1 deletion packages/datasource-sequelize/test/datasource.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import { Sequelize } from 'sequelize';
import { SequelizeCollection, SequelizeDataSource } from '../src';

describe('SequelizeDataSource', () => {
it('should fail to instanciate without a Sequelize instance', () => {
it('should fail to instantiate without a Sequelize instance', () => {
expect(() => new SequelizeDataSource(null)).toThrow('Invalid (null) Sequelize instance.');
});

it('should fail to instantiate without a Sequelize models defined', () => {
expect(() => new SequelizeDataSource({} as Sequelize)).toThrow(
'Invalid (null) Sequelize models.',
);
});

it('should have no predefined collection', () => {
expect(
new SequelizeDataSource({ models: {} } as unknown as Sequelize).collections,
Expand Down

0 comments on commit aeb3b01

Please sign in to comment.