mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-18 14:26:56 +00:00
fix test error
This commit is contained in:
parent
5655b1e792
commit
39bfa0352c
@ -280,12 +280,14 @@ export default class extends Base {
|
||||
this.readonlyFields.forEach(item => {
|
||||
delete data[item];
|
||||
});
|
||||
//check data is empty
|
||||
if (think.isEmpty(data)) {
|
||||
return think.reject(new Error(think.locale('DATA_EMPTY')));
|
||||
}
|
||||
|
||||
let parsedData = this.parseData(data);
|
||||
//check data is empty
|
||||
if (think.isEmpty(parsedData)) {
|
||||
return think.reject(new Error(think.locale('DATA_EMPTY')));
|
||||
}
|
||||
let copyData = think.extend({}, parsedData);
|
||||
|
||||
//check where condition
|
||||
if(think.isEmpty(options.where)){
|
||||
//get where condition from data
|
||||
@ -300,7 +302,7 @@ export default class extends Base {
|
||||
|
||||
parsedData = await this.beforeUpdate(parsedData, options);
|
||||
let rows = await this.db().update(parsedData, options);
|
||||
await this.afterUpdate(data, options);
|
||||
await this.afterUpdate(copyData, options);
|
||||
return rows;
|
||||
}
|
||||
/**
|
||||
|
||||
@ -127,7 +127,7 @@ describe('model/base.js', function(){
|
||||
return Promise.resolve({
|
||||
affectedRows: 3
|
||||
})
|
||||
}else if(sql.trim() === "UPDATE `think_user` SET `title`='title2' WHERE ( `id` = 106 )"){
|
||||
}else if(sql.trim() === "UPDATE `think_cate` SET `title`='title2' WHERE ( `id` = 106 )"){
|
||||
return Promise.resolve({
|
||||
affectedRows: 4
|
||||
})
|
||||
@ -499,16 +499,18 @@ describe('model/base.js', function(){
|
||||
})
|
||||
})
|
||||
it('update, where condition from data', function(done){
|
||||
var instance = new Base('cate', think.config('db'));
|
||||
instance.update({
|
||||
id: 102,
|
||||
name: 'name1',
|
||||
title: 'title1'
|
||||
}).then(function(rows){
|
||||
var sql = instance.getLastSql();
|
||||
//console.log(sql, rows)
|
||||
assert.equal(sql, "UPDATE `think_user` SET `title`='title1' WHERE ( `id` = 102 )")
|
||||
assert.equal(rows, 3);
|
||||
assert.equal(sql, "UPDATE `think_cate` SET `title`='title1' WHERE ( `id` = 102 )")
|
||||
assert.equal(rows, 0);
|
||||
done();
|
||||
}).catch(function(err){
|
||||
console.log(err.stack)
|
||||
})
|
||||
})
|
||||
it('update many, empty', function(done){
|
||||
@ -517,18 +519,20 @@ describe('model/base.js', function(){
|
||||
})
|
||||
})
|
||||
it('update many', function(done){
|
||||
var instance = new Base('cate', think.config('db'));
|
||||
instance.updateMany([{
|
||||
id: 105,
|
||||
name: 'name1',
|
||||
title: 'title1'
|
||||
}]).then(function(rows){
|
||||
var sql = instance.getLastSql();
|
||||
assert.equal(sql, "UPDATE `think_user` SET `title`='title1' WHERE ( `id` = 105 )")
|
||||
assert.equal(rows, 1);
|
||||
assert.equal(sql, "UPDATE `think_cate` SET `title`='title1' WHERE ( `id` = 105 )")
|
||||
assert.equal(rows, 0);
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('update many 2', function(done){
|
||||
var instance = new Base('cate', think.config('db'));
|
||||
instance.updateMany([{
|
||||
id: 100,
|
||||
name: 'name1',
|
||||
@ -539,7 +543,7 @@ describe('model/base.js', function(){
|
||||
title: 'title2'
|
||||
}]).then(function(rows){
|
||||
var sql = instance.getLastSql();
|
||||
assert.equal(sql, "UPDATE `think_user` SET `title`='title2' WHERE ( `id` = 106 )")
|
||||
assert.equal(sql, "UPDATE `think_cate` SET `title`='title2' WHERE ( `id` = 106 )")
|
||||
assert.equal(rows, 4);
|
||||
done();
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user