BlinkUX / sequelize-mock

A simple mock interface specifically for testing code relying on Sequelize models
https://sequelize-mock.readthedocs.io
MIT License
139 stars 73 forks source link

destroy and findOne returning all instances #79

Open AbreezaSaleem opened 4 years ago

AbreezaSaleem commented 4 years ago

I have created my model like this

const SequelizeMock = require('sequelize-mock');\n const DBConnectionMock = new SequelizeMock(); const SiteTag = DBConnectionMock.define('SiteTag',{ instanceMethods: { getSiteId: function () { return this.get('siteId'); }, getTag: function () { return this.get('tag'); }, }, }); SiteTag.$queueResult([ SiteTag.build({ siteId: 1, tag: 'First tag', }), SiteTag.build({ siteId: 2, tag: 'Second tag', }), ]); module.exports.SiteTag = SiteTag;

And later I want to delete the instance with the siteId 2. I have written this code

const destroyed = await SiteTag.destroy({where: {siteId: input.id}});

and this is what destroyed contains:

[ fakeModelInstance { options: { timestamps: true, paranoid: undefined, createdAt: undefined, updatedAt: undefined, deletedAt: undefined, isNewRecord: true }, _values: { instanceMethods: [Object], siteId: 1, tag: 'First tag', id: 1, createdAt: 2020-01-09T11:08:06.128Z, updatedAt: 2020-01-09T11:08:06.128Z }, dataValues: { instanceMethods: [Object], siteId: 1, tag: 'First tag', id: 1, createdAt: 2020-01-09T11:08:06.128Z, updatedAt: 2020-01-09T11:08:06.128Z }, hasPrimaryKeys: true, __validationErrors: [] }, fakeModelInstance { options: { timestamps: true, paranoid: undefined, createdAt: undefined, updatedAt: undefined, deletedAt: undefined, isNewRecord: true }, _values: { instanceMethods: [Object], siteId: 2, tag: 'Second tag', id: 2, createdAt: 2020-01-09T11:08:06.128Z, updatedAt: 2020-01-09T11:08:06.128Z }, dataValues: { instanceMethods: [Object], siteId: 2, tag: 'Second tag', id: 2, createdAt: 2020-01-09T11:08:06.128Z, updatedAt: 2020-01-09T11:08:06.128Z }, hasPrimaryKeys: true, __validationErrors: [] } ]

I am still getting the instance with siteId 2... can someone please explain to me what I am doing wrong?

I am getting the same result when I use SiteTag.findOne({where: {siteId: input.id}});