不要怂,就是干,撸起袖子干!

Commit 5a1472ba by Andy Edwards Committed by GitHub

test: replace bluebird .throw calls (#12110)

1 parent 81ce8ee3
Showing with 28 additions and 39 deletions
...@@ -132,36 +132,27 @@ if (current.dialect.supports.transactions) { ...@@ -132,36 +132,27 @@ if (current.dialect.supports.transactions) {
}); });
it('does not allow queries after commit', function() { it('does not allow queries after commit', async function() {
return this.sequelize.transaction().then(t => { const t = await this.sequelize.transaction();
return this.sequelize.query('SELECT 1+1', { transaction: t, raw: true }).then(() => { await this.sequelize.query('SELECT 1+1', { transaction: t, raw: true });
return t.commit(); await t.commit();
}).then(() => { await expect(this.sequelize.query('SELECT 1+1', { transaction: t, raw: true })).to.be.eventually.rejectedWith(
return this.sequelize.query('SELECT 1+1', { transaction: t, raw: true }); Error,
}); /commit has been called on this transaction\([^)]+\), you can no longer use it\. \(The rejected query is attached as the 'sql' property of this error\)/
}).throw(new Error('Expected error not thrown')) ).and.have.deep.property('sql').that.equal('SELECT 1+1');
.catch(err => {
expect(err.message).to.match(/commit has been called on this transaction\([^)]+\), you can no longer use it\. \(The rejected query is attached as the 'sql' property of this error\)/);
expect(err.sql).to.equal('SELECT 1+1');
});
}); });
it('does not allow queries immediately after commit call', function() { it('does not allow queries immediately after commit call', async function() {
return expect( await expect(this.sequelize.transaction().then(async t => {
this.sequelize.transaction().then(t => { await this.sequelize.query('SELECT 1+1', { transaction: t, raw: true });
return this.sequelize.query('SELECT 1+1', { transaction: t, raw: true }).then(() => { await Promise.all([
return Promise.join( expect(t.commit()).to.eventually.be.fulfilled,
expect(t.commit()).to.eventually.be.fulfilled, expect(this.sequelize.query('SELECT 1+1', { transaction: t, raw: true })).to.be.eventually.rejectedWith(
this.sequelize.query('SELECT 1+1', { transaction: t, raw: true }) Error,
.throw(new Error('Expected error not thrown')) /commit has been called on this transaction\([^)]+\), you can no longer use it\. \(The rejected query is attached as the 'sql' property of this error\)/
.catch(err => { ).and.have.deep.property('sql').that.equal('SELECT 1+1')
expect(err.message).to.match(/commit has been called on this transaction\([^)]+\), you can no longer use it\. \(The rejected query is attached as the 'sql' property of this error\)/); ]);
expect(err.sql).to.equal('SELECT 1+1'); })).to.be.eventually.fulfilled;
})
);
});
})
).to.be.eventually.fulfilled;
}); });
it('does not allow queries after rollback', function() { it('does not allow queries after rollback', function() {
...@@ -186,18 +177,16 @@ if (current.dialect.supports.transactions) { ...@@ -186,18 +177,16 @@ if (current.dialect.supports.transactions) {
.to.eventually.be.rejectedWith('Transaction cannot be rolled back because it never started'); .to.eventually.be.rejectedWith('Transaction cannot be rolled back because it never started');
}); });
it('does not allow queries immediately after rollback call', function() { it('does not allow queries immediately after rollback call', async function() {
return expect( await expect(
this.sequelize.transaction().then(t => { this.sequelize.transaction().then(async t => {
return Promise.join( await Promise.all([
expect(t.rollback()).to.eventually.be.fulfilled, expect(t.rollback()).to.eventually.be.fulfilled,
this.sequelize.query('SELECT 1+1', { transaction: t, raw: true }) expect(this.sequelize.query('SELECT 1+1', { transaction: t, raw: true })).to.be.eventually.rejectedWith(
.throw(new Error('Expected error not thrown')) Error,
.catch(err => { /rollback has been called on this transaction\([^)]+\), you can no longer use it\. \(The rejected query is attached as the 'sql' property of this error\)/
expect(err.message).to.match(/rollback has been called on this transaction\([^)]+\), you can no longer use it\. \(The rejected query is attached as the 'sql' property of this error\)/); ).and.have.deep.property('sql').that.equal('SELECT 1+1')
expect(err.sql).to.equal('SELECT 1+1'); ]);
})
);
}) })
).to.eventually.be.fulfilled; ).to.eventually.be.fulfilled;
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!