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

Commit 77506b42 by Sushant Committed by GitHub

fix(mssql): no unique constraint error thrown for PRIMARY case (#9415)

1 parent 6590873f
...@@ -259,7 +259,7 @@ class Query extends AbstractQuery { ...@@ -259,7 +259,7 @@ class Query extends AbstractQuery {
formatError(err) { formatError(err) {
let match; let match;
match = err.message.match(/Violation of UNIQUE KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'.(:? The duplicate key value is \((.*)\).)?/); match = err.message.match(/Violation of (?:UNIQUE|PRIMARY) KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'.(:? The duplicate key value is \((.*)\).)?/);
match = match || err.message.match(/Cannot insert duplicate key row in object .* with unique index '(.*)'/); match = match || err.message.match(/Cannot insert duplicate key row in object .* with unique index '(.*)'/);
if (match && match.length > 1) { if (match && match.length > 1) {
let fields = {}; let fields = {};
......
'use strict'; 'use strict';
const chai = require('chai'), const chai = require('chai'),
sinon = require('sinon'), sinon = require('sinon'),
expect = chai.expect, expect = chai.expect,
errors = require('../../lib/errors'), errors = require('../../lib/errors'),
...@@ -9,7 +9,6 @@ const chai = require('chai'), ...@@ -9,7 +9,6 @@ const chai = require('chai'),
describe(Support.getTestDialectTeaser('Sequelize Errors'), () => { describe(Support.getTestDialectTeaser('Sequelize Errors'), () => {
describe('API Surface', () => { describe('API Surface', () => {
it('Should have the Error constructors exposed', () => { it('Should have the Error constructors exposed', () => {
expect(Sequelize).to.have.property('Error'); expect(Sequelize).to.have.property('Error');
expect(Sequelize).to.have.property('ValidationError'); expect(Sequelize).to.have.property('ValidationError');
...@@ -348,16 +347,28 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => { ...@@ -348,16 +347,28 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => {
} }
}, { timestamps: false }); }, { timestamps: false });
return this.sequelize.sync({ force: true }).bind(this).then(() => { return this.sequelize.sync({ force: true })
return User.create({ name: 'jan' }); .then(() => {
}).then(() => { return User.create({ name: 'jan' });
return expect(User.create({ name: 'jan' })).to.be.rejected; }).then(() => {
}).then(function(error) { // Unique key
expect(error).to.be.instanceOf(this.sequelize.UniqueConstraintError); return expect(User.create({ name: 'jan' })).to.be.rejected;
expect(error).to.have.property('parent'); }).then(error => {
expect(error).to.have.property('original'); expect(error).to.be.instanceOf(this.sequelize.UniqueConstraintError);
expect(error).to.have.property('sql'); expect(error).to.have.property('parent');
}); expect(error).to.have.property('original');
expect(error).to.have.property('sql');
return User.create({ id: 2, name: 'jon' });
}).then(() => {
// Primary key
return expect(User.create({ id: 2, name: 'jon' })).to.be.rejected;
}).then(error => {
expect(error).to.be.instanceOf(this.sequelize.UniqueConstraintError);
expect(error).to.have.property('parent');
expect(error).to.have.property('original');
expect(error).to.have.property('sql');
});
}); });
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!