From 8ecd52520982039748107384222389dbf40f9215 Mon Sep 17 00:00:00 2001 From: Sascha Depold Date: Sat, 22 Jan 2022 14:11:46 +0100 Subject: [PATCH] fix: don't call overloaded versions of find functions internally (#13951) --- dev/release-v6.ts | 23 +++++++--- lib/model.js | 8 ++-- ...bulkcreate.test.js => bulk-create.test.js} | 0 .../{findall.test.js => find-all.test.js} | 0 test/unit/model/find-by-pk.test.js | 42 +++++++++++++++++++ .../{findone.test.js => find-one.test.js} | 17 ++++++++ ...ributes.test.js => get-attributes.test.js} | 0 ...ibute.test.js => remove-attribute.test.js} | 0 8 files changed, 80 insertions(+), 10 deletions(-) rename test/unit/model/{bulkcreate.test.js => bulk-create.test.js} (100%) rename test/unit/model/{findall.test.js => find-all.test.js} (100%) create mode 100644 test/unit/model/find-by-pk.test.js rename test/unit/model/{findone.test.js => find-one.test.js} (86%) rename test/unit/model/{getAttributes.test.js => get-attributes.test.js} (100%) rename test/unit/model/{removeAttribute.test.js => remove-attribute.test.js} (100%) diff --git a/dev/release-v6.ts b/dev/release-v6.ts index d8cfe4ca8d23..dda5fd792e7b 100755 --- a/dev/release-v6.ts +++ b/dev/release-v6.ts @@ -35,16 +35,23 @@ const RELEASING_COLUMN_ID = 17444349; process.exit(1); } - const github = new Octokit({ - auth: token - }); + const github = new Octokit({ auth: token }); const commits = await getCommitsFromProject(github); - await Promise.all(commits.map(commit => mergeCommit(github, commit))); + await processCommitsInSeries(github, commits); })(); // Helpers +async function processCommitsInSeries(github: Octokit, commits: CardCommit[]) { + let commit: CardCommit | undefined = commits.shift(); + + while (commit) { + await mergeCommit(github, commit); + commit = commits.shift(); + } +} + async function getCommitsFromProject(github: Octokit): Promise { const cards = await github.rest.projects.listCards({ column_id: TO_BE_RELEASED_COLUMN_ID @@ -110,15 +117,19 @@ function mergeCommitTeaser(commit: PullRequest) { } async function moveCard(github: Octokit, card: Card, to: number) { + let result = 'skipped'; + if (process.env.DRY_RUN === 'false') { - const a = await github.rest.projects.moveCard({ + const response = await github.rest.projects.moveCard({ card_id: card.id, position: 'bottom', column_id: to }); - console.log(a); + result = response.status === 201 ? 'success' : 'error'; } + + console.info('- Card moved to column:', result); } async function gitMerge(sha: string) { diff --git a/lib/model.js b/lib/model.js index 2a472a6f175d..aa728404e345 100644 --- a/lib/model.js +++ b/lib/model.js @@ -1916,7 +1916,7 @@ class Model { } // Bypass a possible overloaded findOne - return await this.findOne(options); + return await Model.findOne.call(this, options); } /** @@ -1950,9 +1950,9 @@ class Model { } // Bypass a possible overloaded findAll. - return await this.findAll(_.defaults(options, { - plain: true - })); + return await Model.findAll.call(this, (_.defaults(options, { + plain: true, + }))); } /** diff --git a/test/unit/model/bulkcreate.test.js b/test/unit/model/bulk-create.test.js similarity index 100% rename from test/unit/model/bulkcreate.test.js rename to test/unit/model/bulk-create.test.js diff --git a/test/unit/model/findall.test.js b/test/unit/model/find-all.test.js similarity index 100% rename from test/unit/model/findall.test.js rename to test/unit/model/find-all.test.js diff --git a/test/unit/model/find-by-pk.test.js b/test/unit/model/find-by-pk.test.js new file mode 100644 index 000000000000..d87dfa0399e7 --- /dev/null +++ b/test/unit/model/find-by-pk.test.js @@ -0,0 +1,42 @@ +'use strict'; + +const chai = require('chai'); + +const expect = chai.expect; +const Support = require('../support'); + +const Sequelize = Support.Sequelize; +const Op = Sequelize.Op; +const current = Support.sequelize; +const sinon = require('sinon'); +const DataTypes = require('../../../lib/data-types'); + +describe(Support.getTestDialectTeaser('Model'), () => { + describe('method findByPk', () => { + beforeEach(function () { + this.stub = sinon.stub(Sequelize.Model, 'findAll').resolves(); + }); + afterEach(() => { + sinon.restore(); + }); + + it('should call internal findOne() method if findOne() is overridden', async () => { + const Model = current.define('model', { + unique1: { + type: DataTypes.INTEGER, + unique: 'unique', + }, + unique2: { + type: DataTypes.INTEGER, + unique: 'unique', + }, + }); + Model.findOne = sinon.stub(); + sinon.spy(Sequelize.Model, 'findOne'); + + await Model.findByPk(1); + Model.findOne.should.not.have.been.called; + Sequelize.Model.findOne.should.have.been.called; + }); + }); +}); diff --git a/test/unit/model/findone.test.js b/test/unit/model/find-one.test.js similarity index 86% rename from test/unit/model/findone.test.js rename to test/unit/model/find-one.test.js index a4ce8358cb94..bed619a26eaa 100644 --- a/test/unit/model/findone.test.js +++ b/test/unit/model/find-one.test.js @@ -105,5 +105,22 @@ describe(Support.getTestDialectTeaser('Model'), () => { await Model.findOne({ where: { unique1: 42 } }); expect(this.stub.getCall(0).args[0]).to.be.an('object').to.have.property('limit'); }); + it('should call internal findAll() method if findOne() is overridden', async () => { + const Model = current.define('model', { + unique1: { + type: DataTypes.INTEGER, + unique: 'unique', + }, + unique2: { + type: DataTypes.INTEGER, + unique: 'unique', + }, + }); + Model.findAll = sinon.stub(); + + await Model.findOne(); + Model.findAll.should.not.have.been.called; + Sequelize.Model.findAll.should.have.been.called; + }); }); }); diff --git a/test/unit/model/getAttributes.test.js b/test/unit/model/get-attributes.test.js similarity index 100% rename from test/unit/model/getAttributes.test.js rename to test/unit/model/get-attributes.test.js diff --git a/test/unit/model/removeAttribute.test.js b/test/unit/model/remove-attribute.test.js similarity index 100% rename from test/unit/model/removeAttribute.test.js rename to test/unit/model/remove-attribute.test.js