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

Commit a1ec8a18 by Andy Edwards Committed by GitHub

test: replace Promise.join calls with Promise.all (#12134)

1 parent 39a1f11f
...@@ -35,23 +35,19 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { ...@@ -35,23 +35,19 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
Task.User = Task.belongsTo(User, { as: 'user' }); Task.User = Task.belongsTo(User, { as: 'user' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Task.create({
Task.create({ id: 1,
id: 1, user: { id: 1 }
user: { id: 1 } }, {
}, { include: [Task.User]
include: [Task.User] }), Task.create({
}), id: 2,
Task.create({ user: { id: 2 }
id: 2, }, {
user: { id: 2 } include: [Task.User]
}, { }), Task.create({
include: [Task.User] id: 3
}), })]);
Task.create({
id: 3
})
);
}).then(tasks => { }).then(tasks => {
return Task.User.get(tasks).then(result => { return Task.User.get(tasks).then(result => {
expect(result[tasks[0].id].id).to.equal(tasks[0].user.id); expect(result[tasks[0].id].id).to.equal(tasks[0].user.id);
...@@ -366,10 +362,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { ...@@ -366,10 +362,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
Comment.belongsTo(Post, { foreignKey: 'post_id' }); Comment.belongsTo(Post, { foreignKey: 'post_id' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Post.create(), Comment.create()]).then(async ([post, comment]) => {
Post.create(),
Comment.create()
).then(async ([post, comment]) => {
expect(comment.get('post_id')).not.to.be.ok; expect(comment.get('post_id')).not.to.be.ok;
const setter = await comment.setPost(post, { save: false }); const setter = await comment.setPost(post, { save: false });
...@@ -1029,9 +1022,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { ...@@ -1029,9 +1022,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
it('should load with an alias', function() { it('should load with an alias', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Individual.create({ name: 'Foo Bar' }), this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' })); this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => { }).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat); return individual.setPersonwearinghat(hat);
}).then(() => { }).then(() => {
...@@ -1058,9 +1052,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { ...@@ -1058,9 +1052,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
it('should load all', function() { it('should load all', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Individual.create({ name: 'Foo Bar' }), this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' })); this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => { }).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat); return individual.setPersonwearinghat(hat);
}).then(() => { }).then(() => {
......
...@@ -33,23 +33,19 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { ...@@ -33,23 +33,19 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
Player.User = Player.hasOne(User, { as: 'user' }); Player.User = Player.hasOne(User, { as: 'user' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Player.create({
Player.create({ id: 1,
id: 1, user: {}
user: {} }, {
}, { include: [Player.User]
include: [Player.User] }), Player.create({
}), id: 2,
Player.create({ user: {}
id: 2, }, {
user: {} include: [Player.User]
}, { }), Player.create({
include: [Player.User] id: 3
}), })]);
Player.create({
id: 3
})
);
}).then(players => { }).then(players => {
return Player.User.get(players).then(result => { return Player.User.get(players).then(result => {
expect(result[players[0].id].id).to.equal(players[0].user.id); expect(result[players[0].id].id).to.equal(players[0].user.id);
...@@ -900,9 +896,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { ...@@ -900,9 +896,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
it('should load with an alias', function() { it('should load with an alias', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Individual.create({ name: 'Foo Bar' }), this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' })); this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => { }).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat); return individual.setPersonwearinghat(hat);
}).then(() => { }).then(() => {
...@@ -929,9 +926,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { ...@@ -929,9 +926,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
it('should load all', function() { it('should load all', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Individual.create({ name: 'Foo Bar' }), this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' })); this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => { }).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat); return individual.setPersonwearinghat(hat);
}).then(() => { }).then(() => {
......
...@@ -168,10 +168,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -168,10 +168,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
}; };
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Person.create(), Company.create()]).then(([person, company]) => {
Person.create(),
Company.create()
).then(([person, company]) => {
return person.setEmployer(company); return person.setEmployer(company);
}); });
}).then(() => { }).then(() => {
...@@ -214,14 +211,11 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -214,14 +211,11 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return User.create().then(user => { return User.create().then(user => {
return Promise.join( return Promise.all([user.createTask({
user.createTask({ title: 'trivial'
title: 'trivial' }), user.createTask({
}), title: 'pursuit'
user.createTask({ })]);
title: 'pursuit'
})
);
}).then(() => { }).then(() => {
return User.findOne({ return User.findOne({
include: [ include: [
...@@ -271,10 +265,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -271,10 +265,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
user: User.create(), user: User.create(),
group: Group.create() group: Group.create()
}).then(props => { }).then(props => {
return Promise.join( return Promise.all([props.task.setUser(props.user), props.user.setGroup(props.group)]).then(() => props);
props.task.setUser(props.user),
props.user.setGroup(props.group)
).then(() => props);
}).then(props => { }).then(props => {
return Task.findOne({ return Task.findOne({
where: { where: {
......
...@@ -32,28 +32,24 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -32,28 +32,24 @@ describe(Support.getTestDialectTeaser('Include'), () => {
// Sync them // Sync them
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
// Create an enviroment // Create an enviroment
return Promise.join( return Promise.all([Project.bulkCreate([
Project.bulkCreate([ { id: 1, name: 'No tasks' },
{ id: 1, name: 'No tasks' }, { id: 2, name: 'No tasks no employees' },
{ id: 2, name: 'No tasks no employees' }, { id: 3, name: 'No employees' },
{ id: 3, name: 'No employees' }, { id: 4, name: 'In progress A' },
{ id: 4, name: 'In progress A' }, { id: 5, name: 'In progress B' },
{ id: 5, name: 'In progress B' }, { id: 6, name: 'In progress C' }
{ id: 6, name: 'In progress C' } ]), Task.bulkCreate([
]), { name: 'Important task', fk: 3 },
Task.bulkCreate([ { name: 'Important task', fk: 4 },
{ name: 'Important task', fk: 3 }, { name: 'Important task', fk: 5 },
{ name: 'Important task', fk: 4 }, { name: 'Important task', fk: 6 }
{ name: 'Important task', fk: 5 }, ]), Employee.bulkCreate([
{ name: 'Important task', fk: 6 } { name: 'Jane Doe', fk: 1 },
]), { name: 'John Doe', fk: 4 },
Employee.bulkCreate([ { name: 'Jane John Doe', fk: 5 },
{ name: 'Jane Doe', fk: 1 }, { name: 'John Jane Doe', fk: 6 }
{ name: 'John Doe', fk: 4 }, ])]).then(() =>{
{ name: 'Jane John Doe', fk: 5 },
{ name: 'John Jane Doe', fk: 6 }
])
).then(() =>{
//Find all projects with tasks and employees //Find all projects with tasks and employees
const availableProjects = 3; const availableProjects = 3;
const limit = 2; const limit = 2;
...@@ -101,55 +97,49 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -101,55 +97,49 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
// Create an enviroment // Create an enviroment
return Promise.join( return Promise.all([User.bulkCreate([
User.bulkCreate([ { name: 'Youtube' },
{ name: 'Youtube' }, { name: 'Facebook' },
{ name: 'Facebook' }, { name: 'Google' },
{ name: 'Google' }, { name: 'Yahoo' },
{ name: 'Yahoo' }, { name: '404' }
{ name: '404' } ]), SomeConnection.bulkCreate([ // Lets count, m: A and u: 1
]), { u: 1, m: 'A', fk: 1 }, // 1 // Will be deleted
SomeConnection.bulkCreate([ // Lets count, m: A and u: 1 { u: 2, m: 'A', fk: 1 },
{ u: 1, m: 'A', fk: 1 }, // 1 // Will be deleted { u: 3, m: 'A', fk: 1 },
{ u: 2, m: 'A', fk: 1 }, { u: 4, m: 'A', fk: 1 },
{ u: 3, m: 'A', fk: 1 }, { u: 5, m: 'A', fk: 1 },
{ u: 4, m: 'A', fk: 1 }, { u: 1, m: 'B', fk: 1 },
{ u: 5, m: 'A', fk: 1 }, { u: 2, m: 'B', fk: 1 },
{ u: 1, m: 'B', fk: 1 }, { u: 3, m: 'B', fk: 1 },
{ u: 2, m: 'B', fk: 1 }, { u: 4, m: 'B', fk: 1 },
{ u: 3, m: 'B', fk: 1 }, { u: 5, m: 'B', fk: 1 },
{ u: 4, m: 'B', fk: 1 }, { u: 1, m: 'C', fk: 1 },
{ u: 5, m: 'B', fk: 1 }, { u: 2, m: 'C', fk: 1 },
{ u: 1, m: 'C', fk: 1 }, { u: 3, m: 'C', fk: 1 },
{ u: 2, m: 'C', fk: 1 }, { u: 4, m: 'C', fk: 1 },
{ u: 3, m: 'C', fk: 1 }, { u: 5, m: 'C', fk: 1 },
{ u: 4, m: 'C', fk: 1 }, { u: 1, m: 'A', fk: 2 }, // 2 // Will be deleted
{ u: 5, m: 'C', fk: 1 }, { u: 4, m: 'A', fk: 2 },
{ u: 1, m: 'A', fk: 2 }, // 2 // Will be deleted { u: 2, m: 'A', fk: 2 },
{ u: 4, m: 'A', fk: 2 }, { u: 1, m: 'A', fk: 3 }, // 3
{ u: 2, m: 'A', fk: 2 }, { u: 2, m: 'A', fk: 3 },
{ u: 1, m: 'A', fk: 3 }, // 3 { u: 3, m: 'A', fk: 3 },
{ u: 2, m: 'A', fk: 3 }, { u: 2, m: 'B', fk: 2 },
{ u: 3, m: 'A', fk: 3 }, { u: 1, m: 'A', fk: 4 }, // 4
{ u: 2, m: 'B', fk: 2 }, { u: 4, m: 'A', fk: 2 }
{ u: 1, m: 'A', fk: 4 }, // 4 ]), A.bulkCreate([
{ u: 4, m: 'A', fk: 2 } { name: 'Just' },
]), { name: 'for' },
A.bulkCreate([ { name: 'testing' },
{ name: 'Just' }, { name: 'proposes' },
{ name: 'for' }, { name: 'only' }
{ name: 'testing' }, ]), B.bulkCreate([
{ name: 'proposes' }, { name: 'this should not' },
{ name: 'only' } { name: 'be loaded' }
]), ]), C.bulkCreate([
B.bulkCreate([ { name: 'because we only want A' }
{ name: 'this should not' }, ])]).then(() => {
{ name: 'be loaded' }
]),
C.bulkCreate([
{ name: 'because we only want A' }
])
).then(() => {
// Delete some of conns to prove the concept // Delete some of conns to prove the concept
return SomeConnection.destroy({ where: { return SomeConnection.destroy({ where: {
m: 'A', m: 'A',
......
...@@ -151,10 +151,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -151,10 +151,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return this.sequelize return this.sequelize
.sync({ force: true }) .sync({ force: true })
.then(() => { .then(() => {
return Promise.join( return Promise.all([A.create({}), B.create({})]);
A.create({}),
B.create({})
);
}) })
.then(([a, b]) => { .then(([a, b]) => {
return a.addB(b, { through: { name: 'Foobar' } }); return a.addB(b, { through: { name: 'Foobar' } });
...@@ -293,39 +290,36 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -293,39 +290,36 @@ describe(Support.getTestDialectTeaser('Include'), () => {
G.belongsTo(H); G.belongsTo(H);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([A.create({}), (function(singles) {
A.create({}), let promise = Promise.resolve(),
(function(singles) { previousInstance,
let promise = Promise.resolve(), b;
previousInstance,
b;
singles.forEach(model => {
const values = {};
if (model.name === 'g') {
values.name = 'yolo';
}
promise = promise.then(() => { singles.forEach(model => {
return model.create(values).then(instance => { const values = {};
if (previousInstance) {
return previousInstance[`set${_.upperFirst(model.name)}`](instance).then(() => { if (model.name === 'g') {
previousInstance = instance; values.name = 'yolo';
}); }
}
previousInstance = b = instance;
});
});
});
promise = promise.then(() => { promise = promise.then(() => {
return b; return model.create(values).then(instance => {
if (previousInstance) {
return previousInstance[`set${_.upperFirst(model.name)}`](instance).then(() => {
previousInstance = instance;
});
}
previousInstance = b = instance;
});
}); });
});
promise = promise.then(() => {
return b;
});
return promise; return promise;
})([B, C, D, E, F, G, H]) })([B, C, D, E, F, G, H])]).then(([a, b]) => {
).then(([a, b]) => {
return a.setB(b); return a.setB(b);
}).then(() => { }).then(() => {
return A.findOne({ return A.findOne({
......
...@@ -1014,12 +1014,12 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ...@@ -1014,12 +1014,12 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => {
return User.findAll(); return User.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.users[1].setGroup(results.groups[0]), results.users[1].setGroup(results.groups[0]),
results.users[2].setGroup(results.groups[0]), results.users[2].setGroup(results.groups[0]),
results.users[3].setGroup(results.groups[1]), results.users[3].setGroup(results.groups[1]),
results.users[0].setGroup(results.groups[0]) results.users[0].setGroup(results.groups[0])
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
......
...@@ -21,26 +21,23 @@ if (current.dialect.supports.groupedLimit) { ...@@ -21,26 +21,23 @@ if (current.dialect.supports.groupedLimit) {
User.Tasks = User.hasMany(Task, { as: 'tasks' }); User.Tasks = User.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, tasks: [
tasks: [ {},
{}, {},
{}, {}
{} ]
] }, {
}, { include: [User.Tasks]
include: [User.Tasks] }), User.create({
}), id: 2,
User.create({ tasks: [
id: 2, {}
tasks: [ ]
{} }, {
] include: [User.Tasks]
}, { })]).then(() => {
include: [User.Tasks]
})
).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Tasks, separate: true } { association: User.Tasks, separate: true }
...@@ -193,29 +190,26 @@ if (current.dialect.supports.groupedLimit) { ...@@ -193,29 +190,26 @@ if (current.dialect.supports.groupedLimit) {
User.Tasks = User.hasMany(Task, { as: 'tasks', foreignKey: 'userId' }); User.Tasks = User.hasMany(Task, { as: 'tasks', foreignKey: 'userId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, tasks: [
tasks: [ {},
{}, {},
{}, {}
{} ]
] }, {
}, { include: [User.Tasks]
include: [User.Tasks] }), User.create({
}), id: 2,
User.create({ tasks: [
id: 2, {},
tasks: [ {},
{}, {},
{}, {}
{}, ]
{} }, {
] include: [User.Tasks]
}, { })]).then(() => {
include: [User.Tasks]
})
).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Tasks, limit: 2 } { association: User.Tasks, limit: 2 }
...@@ -245,34 +239,31 @@ if (current.dialect.supports.groupedLimit) { ...@@ -245,34 +239,31 @@ if (current.dialect.supports.groupedLimit) {
Company.Tasks = Company.hasMany(Task, { as: 'tasks' }); Company.Tasks = Company.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, company: {
company: { tasks: [
tasks: [ {},
{}, {},
{}, {}
{}
]
}
}, {
include: [
{ association: User.Company, include: [Company.Tasks] }
] ]
}), }
User.create({ }, {
id: 2, include: [
company: { { association: User.Company, include: [Company.Tasks] }
tasks: [ ]
{} }), User.create({
] id: 2,
} company: {
}, { tasks: [
include: [ {}
{ association: User.Company, include: [Company.Tasks] }
] ]
}) }
).then(() => { }, {
include: [
{ association: User.Company, include: [Company.Tasks] }
]
})]).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Company, include: [ { association: User.Company, include: [
...@@ -306,28 +297,26 @@ if (current.dialect.supports.groupedLimit) { ...@@ -306,28 +297,26 @@ if (current.dialect.supports.groupedLimit) {
Task.Project = Task.belongsTo(Project, { as: 'project' }); Task.Project = Task.belongsTo(Project, { as: 'project' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Company.create({
Company.create({ id: 1,
id: 1, users: [
users: [ {
{ tasks: [
tasks: [ { project: {} },
{ project: {} }, { project: {} },
{ project: {} }, { project: {} }
{ project: {} } ]
] }
} ]
] }, {
}, { include: [
include: [ { association: Company.Users, include: [
{ association: Company.Users, include: [ { association: User.Tasks, include: [
{ association: User.Tasks, include: [ Task.Project
Task.Project
] }
] } ] }
] ] }
}) ]
).then(() => { })]).then(() => {
return Company.findAll({ return Company.findAll({
include: [ include: [
{ association: Company.Users, include: [ { association: Company.Users, include: [
...@@ -359,47 +348,44 @@ if (current.dialect.supports.groupedLimit) { ...@@ -359,47 +348,44 @@ if (current.dialect.supports.groupedLimit) {
Project.Tasks = Project.hasMany(Task, { as: 'tasks' }); Project.Tasks = Project.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, projects: [
projects: [ {
{ id: 1,
id: 1, tasks: [
tasks: [ {},
{}, {},
{}, {}
{} ]
] },
}, {
{ id: 2,
id: 2, tasks: [
tasks: [ {}
{} ]
] }
} ]
] }, {
}, { include: [
include: [ { association: User.Projects, include: [Project.Tasks] }
{ association: User.Projects, include: [Project.Tasks] } ]
] }), User.create({
}), id: 2,
User.create({ projects: [
id: 2, {
projects: [ id: 3,
{ tasks: [
id: 3, {},
tasks: [ {}
{}, ]
{} }
] ]
} }, {
] include: [
}, { { association: User.Projects, include: [Project.Tasks] }
include: [ ]
{ association: User.Projects, include: [Project.Tasks] } })]).then(() => {
]
})
).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Projects, separate: true, include: [ { association: User.Projects, separate: true, include: [
...@@ -445,29 +431,26 @@ if (current.dialect.supports.groupedLimit) { ...@@ -445,29 +431,26 @@ if (current.dialect.supports.groupedLimit) {
return Support.dropTestSchemas(this.sequelize).then(() => { return Support.dropTestSchemas(this.sequelize).then(() => {
return this.sequelize.createSchema('archive').then(() => { return this.sequelize.createSchema('archive').then(() => {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, tasks: [
tasks: [ { id: 1, title: 'b' },
{ id: 1, title: 'b' }, { id: 2, title: 'd' },
{ id: 2, title: 'd' }, { id: 3, title: 'c' },
{ id: 3, title: 'c' }, { id: 4, title: 'a' }
{ id: 4, title: 'a' } ]
] }, {
}, { include: [User.Tasks]
include: [User.Tasks] }), User.create({
}), id: 2,
User.create({ tasks: [
id: 2, { id: 5, title: 'a' },
tasks: [ { id: 6, title: 'c' },
{ id: 5, title: 'a' }, { id: 7, title: 'b' }
{ id: 6, title: 'c' }, ]
{ id: 7, title: 'b' } }, {
] include: [User.Tasks]
}, { })]);
include: [User.Tasks]
})
);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [{ model: Task, limit: 2, as: 'tasks', order: [['id', 'ASC']] }], include: [{ model: Task, limit: 2, as: 'tasks', order: [['id', 'ASC']] }],
......
...@@ -46,10 +46,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -46,10 +46,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.Course.belongsToMany(this.Student, { through: this.Score, foreignKey: 'CourseId' }); this.Course.belongsToMany(this.Student, { through: this.Score, foreignKey: 'CourseId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Student.create({ no: 1, name: 'ryan' }), this.Student.create({ no: 1, name: 'ryan' }),
this.Course.create({ no: 100, name: 'history' }) this.Course.create({ no: 100, name: 'history' })
).then(([student, course]) => { ]).then(([student, course]) => {
return student.addCourse(course, { through: { score: 98, test_value: 1000 } }); return student.addCourse(course, { through: { score: 98, test_value: 1000 } });
}).then(() => { }).then(() => {
expect(callCount).to.equal(1); expect(callCount).to.equal(1);
...@@ -58,10 +58,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -58,10 +58,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
}) })
.then(() => { .then(() => {
return Promise.join( return Promise.all([
this.Student.build({ no: 1 }).getCourses({ where: { no: 100 } }), this.Student.build({ no: 1 }).getCourses({ where: { no: 100 } }),
this.Score.findOne({ where: { StudentId: 1, CourseId: 100 } }) this.Score.findOne({ where: { StudentId: 1, CourseId: 100 } })
); ]);
}) })
.then(([courses, score]) => { .then(([courses, score]) => {
expect(score.test_value).to.equal(1001); expect(score.test_value).to.equal(1001);
......
...@@ -542,14 +542,11 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -542,14 +542,11 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should work with a belongsTo association getter', function() { it('should work with a belongsTo association getter', function() {
const userId = Math.floor(Math.random() * 100000); const userId = Math.floor(Math.random() * 100000);
return Promise.join( return Promise.all([this.User.create({
this.User.create({ id: userId
id: userId }), this.Task.create({
}), user_id: userId
this.Task.create({ })]).then(([user, task]) => {
user_id: userId
})
).then(([user, task]) => {
return Promise.all([user, task.getUser()]); return Promise.all([user, task.getUser()]);
}).then(([userA, userB]) => { }).then(([userA, userB]) => {
expect(userA.get('id')).to.equal(userB.get('id')); expect(userA.get('id')).to.equal(userB.get('id'));
......
...@@ -432,26 +432,25 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -432,26 +432,25 @@ describe(Support.getTestDialectTeaser('Model'), () => {
if (current.dialect.supports.transactions) { if (current.dialect.supports.transactions) {
it('works with a transaction', function() { it('works with a transaction', function() {
return this.sequelize.transaction().then(transaction => { return this.sequelize.transaction().then(transaction => {
return Promise.join( return Promise.all([
this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction }), this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction }),
this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction }), this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction })
(first, second) => { ]).then(([first, second]) => {
const firstInstance = first[0], const firstInstance = first[0],
firstCreated = first[1], firstCreated = first[1],
secondInstance = second[0], secondInstance = second[0],
secondCreated = second[1]; secondCreated = second[1];
// Depending on execution order and MAGIC either the first OR the second call should return true // Depending on execution order and MAGIC either the first OR the second call should return true
expect(firstCreated ? !secondCreated : secondCreated).to.be.ok; // XOR expect(firstCreated ? !secondCreated : secondCreated).to.be.ok; // XOR
expect(firstInstance).to.be.ok; expect(firstInstance).to.be.ok;
expect(secondInstance).to.be.ok; expect(secondInstance).to.be.ok;
expect(firstInstance.id).to.equal(secondInstance.id); expect(firstInstance.id).to.equal(secondInstance.id);
return transaction.commit(); return transaction.commit();
} });
);
}); });
}); });
} }
...@@ -512,87 +511,82 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -512,87 +511,82 @@ describe(Support.getTestDialectTeaser('Model'), () => {
username: 'gottlieb' username: 'gottlieb'
}); });
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findOrCreate({
User.findOrCreate({ where: {
where: { objectId: 'asdasdasd'
objectId: 'asdasdasd' },
}, defaults: {
defaults: { username: 'gottlieb'
username: 'gottlieb' }
} }).then(() => {
}).then(() => { throw new Error('I should have ben rejected');
throw new Error('I should have ben rejected'); }).catch(err => {
}).catch(err => { expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok;
expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok; expect(err.fields).to.be.ok;
expect(err.fields).to.be.ok; }), User.findOrCreate({
}), where: {
User.findOrCreate({ objectId: 'asdasdasd'
where: { },
objectId: 'asdasdasd' defaults: {
}, username: 'gottlieb'
defaults: { }
username: 'gottlieb' }).then(() => {
} throw new Error('I should have ben rejected');
}).then(() => { }).catch(err => {
throw new Error('I should have ben rejected'); expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok;
}).catch(err => { expect(err.fields).to.be.ok;
expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok; })]);
expect(err.fields).to.be.ok;
})
);
}); });
}); });
// Creating two concurrent transactions and selecting / inserting from the same table throws sqlite off // Creating two concurrent transactions and selecting / inserting from the same table throws sqlite off
(dialect !== 'sqlite' ? it : it.skip)('works without a transaction', function() { (dialect !== 'sqlite' ? it : it.skip)('works without a transaction', function() {
return Promise.join( return Promise.all([
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } })
(first, second) => { ]).then(([first, second]) => {
const firstInstance = first[0], const firstInstance = first[0],
firstCreated = first[1], firstCreated = first[1],
secondInstance = second[0], secondInstance = second[0],
secondCreated = second[1]; secondCreated = second[1];
// Depending on execution order and MAGIC either the first OR the second call should return true // Depending on execution order and MAGIC either the first OR the second call should return true
expect(firstCreated ? !secondCreated : secondCreated).to.be.ok; // XOR expect(firstCreated ? !secondCreated : secondCreated).to.be.ok; // XOR
expect(firstInstance).to.be.ok; expect(firstInstance).to.be.ok;
expect(secondInstance).to.be.ok; expect(secondInstance).to.be.ok;
expect(firstInstance.id).to.equal(secondInstance.id); expect(firstInstance.id).to.equal(secondInstance.id);
} });
);
}); });
}); });
}); });
describe('findCreateFind', () => { describe('findCreateFind', () => {
(dialect !== 'sqlite' ? it : it.skip)('should work with multiple concurrent calls', function() { (dialect !== 'sqlite' ? it : it.skip)('should work with multiple concurrent calls', function() {
return Promise.join( return Promise.all([
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } })
(first, second, third) => { ]).then(([first, second, third]) => {
const firstInstance = first[0], const firstInstance = first[0],
firstCreated = first[1], firstCreated = first[1],
secondInstance = second[0], secondInstance = second[0],
secondCreated = second[1], secondCreated = second[1],
thirdInstance = third[0], thirdInstance = third[0],
thirdCreated = third[1]; thirdCreated = third[1];
expect([firstCreated, secondCreated, thirdCreated].filter(value => { expect([firstCreated, secondCreated, thirdCreated].filter(value => {
return value; return value;
}).length).to.equal(1); }).length).to.equal(1);
expect(firstInstance).to.be.ok; expect(firstInstance).to.be.ok;
expect(secondInstance).to.be.ok; expect(secondInstance).to.be.ok;
expect(thirdInstance).to.be.ok; expect(thirdInstance).to.be.ok;
expect(firstInstance.id).to.equal(secondInstance.id); expect(firstInstance.id).to.equal(secondInstance.id);
expect(secondInstance.id).to.equal(thirdInstance.id); expect(secondInstance.id).to.equal(thirdInstance.id);
} });
);
}); });
}); });
...@@ -656,13 +650,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -656,13 +650,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
Log.removeAttribute('id'); Log.removeAttribute('id');
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Log.create({ level: 'info' }), Log.bulkCreate([
Log.create({ level: 'info' }), { level: 'error' },
Log.bulkCreate([ { level: 'debug' }
{ level: 'error' }, ])]);
{ level: 'debug' }
])
);
}).then(() => { }).then(() => {
return Log.findAll(); return Log.findAll();
}).then(logs => { }).then(logs => {
......
...@@ -51,22 +51,22 @@ if (current.dialect.supports['UNION ALL']) { ...@@ -51,22 +51,22 @@ if (current.dialect.supports['UNION ALL']) {
this.User.Tasks = this.User.hasMany(this.Task); this.User.Tasks = this.User.hasMany(this.Task);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.User.bulkCreate([{ age: -5 }, { age: 45 }, { age: 7 }, { age: -9 }, { age: 8 }, { age: 15 }, { age: -9 }]), this.User.bulkCreate([{ age: -5 }, { age: 45 }, { age: 7 }, { age: -9 }, { age: 8 }, { age: 15 }, { age: -9 }]),
this.Project.bulkCreate([{}, {}]), this.Project.bulkCreate([{}, {}]),
this.Task.bulkCreate([{}, {}]) this.Task.bulkCreate([{}, {}])
); ]);
}) })
.then(() => Promise.all([this.User.findAll(), this.Project.findAll(), this.Task.findAll()])) .then(() => Promise.all([this.User.findAll(), this.Project.findAll(), this.Task.findAll()]))
.then(([users, projects, tasks]) => { .then(([users, projects, tasks]) => {
this.projects = projects; this.projects = projects;
return Promise.join( return Promise.all([
projects[0].setMembers(users.slice(0, 4)), projects[0].setMembers(users.slice(0, 4)),
projects[1].setMembers(users.slice(2)), projects[1].setMembers(users.slice(2)),
projects[0].setParanoidMembers(users.slice(0, 4)), projects[0].setParanoidMembers(users.slice(0, 4)),
projects[1].setParanoidMembers(users.slice(2)), projects[1].setParanoidMembers(users.slice(2)),
users[2].setTasks(tasks) users[2].setTasks(tasks)
); ]);
}); });
}); });
...@@ -218,19 +218,19 @@ if (current.dialect.supports['UNION ALL']) { ...@@ -218,19 +218,19 @@ if (current.dialect.supports['UNION ALL']) {
this.User.Tasks = this.User.hasMany(this.Task); this.User.Tasks = this.User.hasMany(this.Task);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.User.bulkCreate([{}, {}, {}]), this.User.bulkCreate([{}, {}, {}]),
this.Task.bulkCreate([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }]) this.Task.bulkCreate([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }])
); ]);
}) })
.then(() => Promise.all([this.User.findAll(), this.Task.findAll()])) .then(() => Promise.all([this.User.findAll(), this.Task.findAll()]))
.then(([users, tasks]) => { .then(([users, tasks]) => {
this.users = users; this.users = users;
return Promise.join( return Promise.all([
users[0].setTasks(tasks[0]), users[0].setTasks(tasks[0]),
users[1].setTasks(tasks.slice(1, 4)), users[1].setTasks(tasks.slice(1, 4)),
users[2].setTasks(tasks.slice(4)) users[2].setTasks(tasks.slice(4))
); ]);
}); });
}); });
......
...@@ -487,7 +487,7 @@ if (current.dialect.supports.transactions) { ...@@ -487,7 +487,7 @@ if (current.dialect.supports.transactions) {
}); });
}); });
}; };
return Promise.join(newTransactionFunc(), newTransactionFunc()).then(() => { return Promise.all([newTransactionFunc(), newTransactionFunc()]).then(() => {
return User.findAll().then(users => { return User.findAll().then(users => {
expect(users.length).to.equal(2); expect(users.length).to.equal(2);
}); });
...@@ -510,7 +510,7 @@ if (current.dialect.supports.transactions) { ...@@ -510,7 +510,7 @@ if (current.dialect.supports.transactions) {
}); });
}); });
}; };
return expect(Promise.join(newTransactionFunc(), newTransactionFunc())).to.be.rejectedWith('SQLITE_BUSY: database is locked'); return expect(Promise.all([newTransactionFunc(), newTransactionFunc()])).to.be.rejectedWith('SQLITE_BUSY: database is locked');
}); });
}); });
}); });
...@@ -570,16 +570,14 @@ if (current.dialect.supports.transactions) { ...@@ -570,16 +570,14 @@ if (current.dialect.supports.transactions) {
}).then(() => { }).then(() => {
return this.sequelize.transaction({ isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE }).then(transaction => { return this.sequelize.transaction({ isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE }).then(transaction => {
return User.findAll( { transaction } ) return User.findAll( { transaction } )
.then(() => Promise.join( .then(() => Promise.all([// Update should not succeed before transaction has committed
User.update({ username: 'joe' }, { User.update({ username: 'joe' }, {
where: { where: {
username: 'jan' username: 'jan'
} }
}).then(() => expect(transactionSpy).to.have.been.called ), // Update should not succeed before transaction has committed }).then(() => expect(transactionSpy).to.have.been.called ), delay(2000)
delay(2000)
.then(() => transaction.commit()) .then(() => transaction.commit())
.then(transactionSpy) .then(transactionSpy)]));
));
}); });
}); });
}); });
...@@ -612,31 +610,27 @@ if (current.dialect.supports.transactions) { ...@@ -612,31 +610,27 @@ if (current.dialect.supports.transactions) {
return this.sequelize.transaction({ return this.sequelize.transaction({
isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED
}).then(t2 => { }).then(t2 => {
return Promise.join( return Promise.all([User.findOne({
User.findOne({ where: {
where: { username: 'jan'
username: 'jan' },
}, lock: t2.LOCK.UPDATE,
lock: t2.LOCK.UPDATE, transaction: t2
transaction: t2 }).then(() => {
}).then(() => { t2Spy();
t2Spy(); return t2.commit().then(() => {
return t2.commit().then(() => { expect(t2Spy).to.have.been.calledAfter(t1Spy); // Find should not succeed before t1 has committed
expect(t2Spy).to.have.been.calledAfter(t1Spy); // Find should not succeed before t1 has committed });
}); }), t1Jan.update({
}), awesome: true
}, {
t1Jan.update({ transaction: t1
awesome: true }).then(() => {
}, { t1Spy();
transaction: t1 return delay(2000).then(() => {
}).then(() => { return t1.commit();
t1Spy(); });
return delay(2000).then(() => { })]);
return t1.commit();
});
})
);
}); });
}); });
}); });
...@@ -695,12 +689,12 @@ if (current.dialect.supports.transactions) { ...@@ -695,12 +689,12 @@ if (current.dialect.supports.transactions) {
Task.belongsToMany(User, { through: 'UserTasks' }); Task.belongsToMany(User, { through: 'UserTasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
User.create({ username: 'John' }), User.create({ username: 'John' }),
Task.create({ title: 'Get rich', active: false }), Task.create({ title: 'Get rich', active: false })
(john, task1) => { ]).then(([john, task1]) => {
return john.setTasks([task1]); return john.setTasks([task1]);
}) })
.then(() => { .then(() => {
return this.sequelize.transaction(t1 => { return this.sequelize.transaction(t1 => {
...@@ -738,13 +732,13 @@ if (current.dialect.supports.transactions) { ...@@ -738,13 +732,13 @@ if (current.dialect.supports.transactions) {
Task.belongsToMany(User, { through: 'UserTasks' }); Task.belongsToMany(User, { through: 'UserTasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
User.create({ username: 'John' }), User.create({ username: 'John' }),
Task.create({ title: 'Get rich', active: false }), Task.create({ title: 'Get rich', active: false }),
Task.create({ title: 'Die trying', active: false }), Task.create({ title: 'Die trying', active: false })
(john, task1) => { ]).then(([john, task1]) => {
return john.setTasks([task1]); return john.setTasks([task1]);
}) })
.then(() => { .then(() => {
return this.sequelize.transaction(t1 => { return this.sequelize.transaction(t1 => {
return User.findOne({ return User.findOne({
...@@ -801,29 +795,26 @@ if (current.dialect.supports.transactions) { ...@@ -801,29 +795,26 @@ if (current.dialect.supports.transactions) {
transaction: t1 transaction: t1
}).then(t1Jan => { }).then(t1Jan => {
return this.sequelize.transaction().then(t2 => { return this.sequelize.transaction().then(t2 => {
return Promise.join( return Promise.all([User.findOne({
User.findOne({ where: {
where: { username: 'jan'
username: 'jan' },
}, lock: t2.LOCK.KEY_SHARE,
lock: t2.LOCK.KEY_SHARE, transaction: t2
transaction: t2 }).then(() => {
}).then(() => { t2Spy();
t2Spy(); return t2.commit();
return t2.commit(); }), t1Jan.update({
}), awesome: true
t1Jan.update({ }, {
awesome: true transaction: t1
}, { }).then(() => {
transaction: t1 return delay(2000).then(() => {
}).then(() => { t1Spy();
return delay(2000).then(() => { expect(t1Spy).to.have.been.calledAfter(t2Spy);
t1Spy(); return t1.commit();
expect(t1Spy).to.have.been.calledAfter(t2Spy); });
return t1.commit(); })]);
});
})
);
}); });
}); });
}); });
...@@ -854,38 +845,34 @@ if (current.dialect.supports.transactions) { ...@@ -854,38 +845,34 @@ if (current.dialect.supports.transactions) {
return this.sequelize.transaction({ return this.sequelize.transaction({
isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED
}).then(t2 => { }).then(t2 => {
return Promise.join( return Promise.all([User.findOne({
User.findOne({ where: {
where: { username: 'jan'
username: 'jan' },
}, transaction: t2
transaction: t2 }).then(t2Jan => {
}).then(t2Jan => { t2FindSpy();
t2FindSpy(); return t2Jan.update({
return t2Jan.update({ awesome: false
awesome: false
}, {
transaction: t2
}).then(() => {
t2UpdateSpy();
return t2.commit().then(() => {
expect(t2FindSpy).to.have.been.calledBefore(t1Spy); // The find call should have returned
expect(t2UpdateSpy).to.have.been.calledAfter(t1Spy); // But the update call should not happen before the first transaction has committed
});
});
}),
t1Jan.update({
awesome: true
}, { }, {
transaction: t1 transaction: t2
}).then(() => { }).then(() => {
return delay(2000).then(() => { t2UpdateSpy();
t1Spy(); return t2.commit().then(() => {
return t1.commit(); expect(t2FindSpy).to.have.been.calledBefore(t1Spy); // The find call should have returned
expect(t2UpdateSpy).to.have.been.calledAfter(t1Spy); // But the update call should not happen before the first transaction has committed
}); });
}) });
); }), t1Jan.update({
awesome: true
}, {
transaction: t1
}).then(() => {
return delay(2000).then(() => {
t1Spy();
return t1.commit();
});
})]);
}); });
}); });
}); });
......
...@@ -309,17 +309,13 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -309,17 +309,13 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
it('should allow decimal as scientific notation', () => { it('should allow decimal as scientific notation', () => {
return Promise.join( return Promise.all([expect(User.create({
expect(User.create({ number: '2321312301230128391820e219'
number: '2321312301230128391820e219' })).not.to.be.rejected, expect(User.create({
})).not.to.be.rejected, number: '2321312301230128391820e+219'
expect(User.create({ })).not.to.be.rejected, expect(User.create({
number: '2321312301230128391820e+219' number: '2321312301230128391820f219'
})).not.to.be.rejected, })).to.be.rejected]);
expect(User.create({
number: '2321312301230128391820f219'
})).to.be.rejected
);
}); });
it('should allow string as a number', () => { it('should allow string as a number', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!