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

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'), () => {
Task.User = Task.belongsTo(User, { as: 'user' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
Task.create({
return Promise.all([Task.create({
id: 1,
user: { id: 1 }
}, {
include: [Task.User]
}),
Task.create({
}), Task.create({
id: 2,
user: { id: 2 }
}, {
include: [Task.User]
}),
Task.create({
}), Task.create({
id: 3
})
);
})]);
}).then(tasks => {
return Task.User.get(tasks).then(result => {
expect(result[tasks[0].id].id).to.equal(tasks[0].user.id);
......@@ -366,10 +362,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
Comment.belongsTo(Post, { foreignKey: 'post_id' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
Post.create(),
Comment.create()
).then(async ([post, comment]) => {
return Promise.all([Post.create(), Comment.create()]).then(async ([post, comment]) => {
expect(comment.get('post_id')).not.to.be.ok;
const setter = await comment.setPost(post, { save: false });
......@@ -1029,9 +1022,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
it('should load with an alias', function() {
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' }));
this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat);
}).then(() => {
......@@ -1058,9 +1052,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
it('should load all', function() {
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' }));
this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat);
}).then(() => {
......
......@@ -45,10 +45,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
include: [Task]
});
}).then(user => {
return Promise.join(
return Promise.all([
user.get('Tasks')[0].createSubtask({ title: 'Make a startup', active: false }),
user.get('Tasks')[0].createSubtask({ title: 'Engage rock stars', active: true })
).then(() => user);
]).then(() => user);
}).then(user => {
return expect(user.countTasks({
attributes: [Task.primaryKeyField, 'title'],
......@@ -75,8 +75,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
User.Tasks = User.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
id: 1,
tasks: [
{},
......@@ -85,19 +84,16 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
]
}, {
include: [User.Tasks]
}),
User.create({
}), User.create({
id: 2,
tasks: [
{}
]
}, {
include: [User.Tasks]
}),
User.create({
}), User.create({
id: 3
})
);
})]);
}).then(users => {
return User.Tasks.get(users).then(result => {
expect(result[users[0].id].length).to.equal(3);
......@@ -116,8 +112,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
User.Tasks = User.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
tasks: [
{ title: 'b' },
{ title: 'd' },
......@@ -126,8 +121,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
]
}, {
include: [User.Tasks]
}),
User.create({
}), User.create({
tasks: [
{ title: 'a' },
{ title: 'c' },
......@@ -135,8 +129,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
]
}, {
include: [User.Tasks]
})
);
})]);
}).then(users => {
return User.Tasks.get(users, {
limit: 2,
......@@ -168,8 +161,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
Task.SubTasks = Task.hasMany(SubTask, { as: 'subtasks' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
id: 1,
tasks: [
{ title: 'b', subtasks: [
......@@ -190,8 +182,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
]
}, {
include: [{ association: User.Tasks, include: [Task.SubTasks] }]
}),
User.create({
}), User.create({
id: 2,
tasks: [
{ title: 'a', subtasks: [
......@@ -209,8 +200,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
]
}, {
include: [{ association: User.Tasks, include: [Task.SubTasks] }]
})
);
})]);
}).then(() => {
return User.findAll({
include: [{
......@@ -275,8 +265,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
Task.Category = Task.belongsTo(Category, { as: 'category', foreignKey: 'categoryId' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
tasks: [
{ title: 'b', category: {} },
{ title: 'd', category: {} },
......@@ -285,8 +274,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
]
}, {
include: [{ association: User.Tasks, include: [Task.Category] }]
}),
User.create({
}), User.create({
tasks: [
{ title: 'a', category: {} },
{ title: 'c', category: {} },
......@@ -294,8 +282,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
]
}, {
include: [{ association: User.Tasks, include: [Task.Category] }]
})
);
})]);
}).then(users => {
return User.Tasks.get(users, {
limit: 2,
......@@ -340,8 +327,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
}).then(() => {
return SubTask.sync({ force: true });
}).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
id: 1,
tasks: [
{ title: 'b', subtasks: [
......@@ -362,8 +348,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
]
}, {
include: [{ association: User.Tasks, include: [Task.SubTasks] }]
}),
User.create({
}), User.create({
id: 2,
tasks: [
{ title: 'a', subtasks: [
......@@ -381,8 +366,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
]
}, {
include: [{ association: User.Tasks, include: [Task.SubTasks] }]
})
);
})]);
}).then(() => {
return User.findAll({
include: [{
......@@ -1719,9 +1703,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
it('should load with an alias', function() {
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' }));
this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => {
return individual.addPersonwearinghat(hat);
}).then(() => {
......@@ -1738,9 +1723,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
it('should load all', function() {
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' }));
this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => {
return individual.addPersonwearinghat(hat);
}).then(() => {
......
......@@ -33,23 +33,19 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
Player.User = Player.hasOne(User, { as: 'user' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
Player.create({
return Promise.all([Player.create({
id: 1,
user: {}
}, {
include: [Player.User]
}),
Player.create({
}), Player.create({
id: 2,
user: {}
}, {
include: [Player.User]
}),
Player.create({
}), Player.create({
id: 3
})
);
})]);
}).then(players => {
return Player.User.get(players).then(result => {
expect(result[players[0].id].id).to.equal(players[0].user.id);
......@@ -900,9 +896,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
it('should load with an alias', function() {
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' }));
this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat);
}).then(() => {
......@@ -929,9 +926,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
it('should load all', function() {
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' }));
this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat);
}).then(() => {
......
......@@ -168,10 +168,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
};
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
Person.create(),
Company.create()
).then(([person, company]) => {
return Promise.all([Person.create(), Company.create()]).then(([person, company]) => {
return person.setEmployer(company);
});
}).then(() => {
......@@ -214,14 +211,11 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return this.sequelize.sync({ force: true }).then(() => {
return User.create().then(user => {
return Promise.join(
user.createTask({
return Promise.all([user.createTask({
title: 'trivial'
}),
user.createTask({
}), user.createTask({
title: 'pursuit'
})
);
})]);
}).then(() => {
return User.findOne({
include: [
......@@ -271,10 +265,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
user: User.create(),
group: Group.create()
}).then(props => {
return Promise.join(
props.task.setUser(props.user),
props.user.setGroup(props.group)
).then(() => props);
return Promise.all([props.task.setUser(props.user), props.user.setGroup(props.group)]).then(() => props);
}).then(props => {
return Task.findOne({
where: {
......
......@@ -250,28 +250,20 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Tag.belongsToMany(Product, { through: ProductTag });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
Set.bulkCreate([
return Promise.all([Set.bulkCreate([
{ title: 'office' }
]),
Product.bulkCreate([
]), Product.bulkCreate([
{ title: 'Chair' },
{ title: 'Desk' },
{ title: 'Dress' }
]),
Tag.bulkCreate([
]), Tag.bulkCreate([
{ name: 'A' },
{ name: 'B' },
{ name: 'C' }
])
).then(() => {
return Promise.join(
Set.findAll(),
Product.findAll(),
Tag.findAll()
);
])]).then(() => {
return Promise.all([Set.findAll(), Product.findAll(), Tag.findAll()]);
}).then(([sets, products, tags]) => {
return Promise.join(
return Promise.all([
sets[0].addProducts([products[0], products[1]]),
products[0].addTag(tags[0], { priority: 1 }).then(() => {
return products[0].addTag(tags[1], { priority: 2 });
......@@ -283,7 +275,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
}).then(() => {
return products[2].addTag(tags[2], { priority: 0 });
})
);
]);
}).then(() => {
return Set.findAll({
include: [{
......@@ -453,8 +445,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
G.belongsTo(H);
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
A.bulkCreate([
return Promise.all([A.bulkCreate([
{},
{},
{},
......@@ -465,8 +456,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{}
]).then(() => {
return A.findAll();
}),
(function(singles) {
}), (function(singles) {
let promise = Promise.resolve(),
previousInstance,
b;
......@@ -489,8 +479,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
});
return promise;
})([B, C, D, E, F, G, H])
).then(([as, b]) => {
})([B, C, D, E, F, G, H])]).then(([as, b]) => {
return Promise.all(as.map(a => {
return a.setB(b);
}));
......@@ -545,8 +534,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
G.belongsTo(H);
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
A.bulkCreate([
return Promise.all([A.bulkCreate([
{},
{},
{},
......@@ -557,8 +545,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{}
]).then(() => {
return A.findAll();
}),
(function(singles) {
}), (function(singles) {
let promise = Promise.resolve(),
previousInstance,
b;
......@@ -587,8 +574,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
});
return promise;
})([B, C, D, E, F, G, H])
).then(([as, b]) => {
})([B, C, D, E, F, G, H])]).then(([as, b]) => {
return Promise.all(as.map(a => {
return a.setB(b);
}));
......@@ -665,7 +651,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
const order2 = results.orders[1];
const order3 = results.orders[2];
return Promise.join(
return Promise.all([
user1.setItemA(item1),
user1.setItemB(item2),
user1.setOrder(order3),
......@@ -675,7 +661,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
user3.setItemA(item1),
user3.setItemB(item4),
user3.setOrder(order1)
);
]);
}).then(() => {
return User.findAll({
'include': [
......@@ -729,14 +715,14 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Tag.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.products[0].addTag(results.tags[0], { through: { priority: 1 } }),
results.products[0].addTag(results.tags[1], { through: { priority: 2 } }),
results.products[1].addTag(results.tags[1], { through: { priority: 1 } }),
results.products[2].addTag(results.tags[0], { through: { priority: 3 } }),
results.products[2].addTag(results.tags[1], { through: { priority: 1 } }),
results.products[2].addTag(results.tags[2], { through: { priority: 2 } })
);
]);
}).then(() => {
return Product.findAll({
include: [
......@@ -809,10 +795,10 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.users[0].setGroup(results.groups[1]),
results.users[1].setGroup(results.groups[0])
);
]);
}).then(() => {
return User.findAll({
include: [
......@@ -847,10 +833,10 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.users[0].setGroup(results.groups[1]),
results.users[1].setGroup(results.groups[0])
);
]);
}).then(() => {
return User.findAll({
include: [
......@@ -931,13 +917,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Category.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.users[0].setGroup(results.groups[1]),
results.users[1].setGroup(results.groups[0]),
Promise.all(results.groups.map(group => {
return group.setCategories(results.categories);
}))
);
]);
}).then(() => {
return User.findAll({
include: [
......@@ -984,13 +970,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Category.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.users[0].setTeam(results.groups[1]),
results.users[1].setTeam(results.groups[0]),
Promise.all(results.groups.map(group => {
return group.setTags(results.categories);
}))
);
]);
}).then(() => {
return User.findAll({
include: [
......@@ -1037,13 +1023,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Category.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.users[0].setGroup(results.groups[1]),
results.users[1].setGroup(results.groups[0]),
Promise.all(results.groups.map(group => {
return group.setCategories(results.categories);
}))
);
]);
}).then(() => {
return User.findAll({
include: [
......@@ -1083,10 +1069,10 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.users[1].setLeaderOf(results.projects[1]),
results.users[0].setLeaderOf(results.projects[0])
);
]);
}).then(() => {
return User.findAll({
include: [
......@@ -1132,14 +1118,14 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Tag.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.products[0].addTag(results.tags[0], { priority: 1 }),
results.products[0].addTag(results.tags[1], { priority: 2 }),
results.products[1].addTag(results.tags[1], { priority: 1 }),
results.products[2].addTag(results.tags[0], { priority: 3 }),
results.products[2].addTag(results.tags[1], { priority: 1 }),
results.products[2].addTag(results.tags[2], { priority: 2 })
);
]);
}).then(() => {
return Product.findAll({
include: [
......@@ -1297,12 +1283,12 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.users[0].setGroup(results.groups[0]),
results.users[1].setGroup(results.groups[0]),
results.users[2].setGroup(results.groups[0]),
results.users[3].setGroup(results.groups[1])
);
]);
}).then(() => {
return User.findAll({
include: [
......@@ -1639,12 +1625,12 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Category.belongsTo(Post);
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
Post.create({ 'public': true }),
Post.create({ 'public': true }),
Post.create({ 'public': true }),
Post.create({ 'public': true })
).then(posts => {
]).then(posts => {
return Promise.all(posts.slice(1, 3).map(post => {
return post.createCategory({ slug: 'food' });
}));
......@@ -1779,18 +1765,18 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Company.hasMany(User);
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
User.create({ lastName: 'Albertsen' }),
User.create({ lastName: 'Zenith' }),
User.create({ lastName: 'Hansen' }),
Company.create({ rank: 1 }),
Company.create({ rank: 2 })
).then(([albertsen, zenith, hansen, company1, company2]) => {
return Promise.join(
]).then(([albertsen, zenith, hansen, company1, company2]) => {
return Promise.all([
albertsen.setCompany(company1),
zenith.setCompany(company2),
hansen.setCompany(company2)
);
]);
}).then(() => {
return User.findAll({
include: [
......
......@@ -32,28 +32,24 @@ describe(Support.getTestDialectTeaser('Include'), () => {
// Sync them
return this.sequelize.sync({ force: true }).then(() => {
// Create an enviroment
return Promise.join(
Project.bulkCreate([
return Promise.all([Project.bulkCreate([
{ id: 1, name: 'No tasks' },
{ id: 2, name: 'No tasks no employees' },
{ id: 3, name: 'No employees' },
{ id: 4, name: 'In progress A' },
{ id: 5, name: 'In progress B' },
{ id: 6, name: 'In progress C' }
]),
Task.bulkCreate([
]), Task.bulkCreate([
{ name: 'Important task', fk: 3 },
{ name: 'Important task', fk: 4 },
{ name: 'Important task', fk: 5 },
{ name: 'Important task', fk: 6 }
]),
Employee.bulkCreate([
]), Employee.bulkCreate([
{ name: 'Jane Doe', fk: 1 },
{ name: 'John Doe', fk: 4 },
{ name: 'Jane John Doe', fk: 5 },
{ name: 'John Jane Doe', fk: 6 }
])
).then(() =>{
])]).then(() =>{
//Find all projects with tasks and employees
const availableProjects = 3;
const limit = 2;
......@@ -101,15 +97,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return this.sequelize.sync({ force: true }).then(() => {
// Create an enviroment
return Promise.join(
User.bulkCreate([
return Promise.all([User.bulkCreate([
{ name: 'Youtube' },
{ name: 'Facebook' },
{ name: 'Google' },
{ name: 'Yahoo' },
{ name: '404' }
]),
SomeConnection.bulkCreate([ // Lets count, m: A and u: 1
]), SomeConnection.bulkCreate([ // Lets count, m: A and u: 1
{ u: 1, m: 'A', fk: 1 }, // 1 // Will be deleted
{ u: 2, m: 'A', fk: 1 },
{ u: 3, m: 'A', fk: 1 },
......@@ -134,22 +128,18 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{ u: 2, m: 'B', fk: 2 },
{ u: 1, m: 'A', fk: 4 }, // 4
{ u: 4, m: 'A', fk: 2 }
]),
A.bulkCreate([
]), A.bulkCreate([
{ name: 'Just' },
{ name: 'for' },
{ name: 'testing' },
{ name: 'proposes' },
{ name: 'only' }
]),
B.bulkCreate([
]), B.bulkCreate([
{ name: 'this should not' },
{ name: 'be loaded' }
]),
C.bulkCreate([
]), C.bulkCreate([
{ name: 'because we only want A' }
])
).then(() => {
])]).then(() => {
// Delete some of conns to prove the concept
return SomeConnection.destroy({ where: {
m: 'A',
......
......@@ -151,10 +151,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return this.sequelize
.sync({ force: true })
.then(() => {
return Promise.join(
A.create({}),
B.create({})
);
return Promise.all([A.create({}), B.create({})]);
})
.then(([a, b]) => {
return a.addB(b, { through: { name: 'Foobar' } });
......@@ -293,9 +290,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
G.belongsTo(H);
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
A.create({}),
(function(singles) {
return Promise.all([A.create({}), (function(singles) {
let promise = Promise.resolve(),
previousInstance,
b;
......@@ -324,8 +319,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
});
return promise;
})([B, C, D, E, F, G, H])
).then(([a, b]) => {
})([B, C, D, E, F, G, H])]).then(([a, b]) => {
return a.setB(b);
}).then(() => {
return A.findOne({
......
......@@ -1014,12 +1014,12 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => {
return User.findAll();
})
}).then(results => {
return Promise.join(
return Promise.all([
results.users[1].setGroup(results.groups[0]),
results.users[2].setGroup(results.groups[0]),
results.users[3].setGroup(results.groups[1]),
results.users[0].setGroup(results.groups[0])
);
]);
}).then(() => {
return User.findAll({
include: [
......
......@@ -21,8 +21,7 @@ if (current.dialect.supports.groupedLimit) {
User.Tasks = User.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
id: 1,
tasks: [
{},
......@@ -31,16 +30,14 @@ if (current.dialect.supports.groupedLimit) {
]
}, {
include: [User.Tasks]
}),
User.create({
}), User.create({
id: 2,
tasks: [
{}
]
}, {
include: [User.Tasks]
})
).then(() => {
})]).then(() => {
return User.findAll({
include: [
{ association: User.Tasks, separate: true }
......@@ -193,8 +190,7 @@ if (current.dialect.supports.groupedLimit) {
User.Tasks = User.hasMany(Task, { as: 'tasks', foreignKey: 'userId' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
id: 1,
tasks: [
{},
......@@ -203,8 +199,7 @@ if (current.dialect.supports.groupedLimit) {
]
}, {
include: [User.Tasks]
}),
User.create({
}), User.create({
id: 2,
tasks: [
{},
......@@ -214,8 +209,7 @@ if (current.dialect.supports.groupedLimit) {
]
}, {
include: [User.Tasks]
})
).then(() => {
})]).then(() => {
return User.findAll({
include: [
{ association: User.Tasks, limit: 2 }
......@@ -245,8 +239,7 @@ if (current.dialect.supports.groupedLimit) {
Company.Tasks = Company.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
id: 1,
company: {
tasks: [
......@@ -259,8 +252,7 @@ if (current.dialect.supports.groupedLimit) {
include: [
{ association: User.Company, include: [Company.Tasks] }
]
}),
User.create({
}), User.create({
id: 2,
company: {
tasks: [
......@@ -271,8 +263,7 @@ if (current.dialect.supports.groupedLimit) {
include: [
{ association: User.Company, include: [Company.Tasks] }
]
})
).then(() => {
})]).then(() => {
return User.findAll({
include: [
{ association: User.Company, include: [
......@@ -306,8 +297,7 @@ if (current.dialect.supports.groupedLimit) {
Task.Project = Task.belongsTo(Project, { as: 'project' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
Company.create({
return Promise.all([Company.create({
id: 1,
users: [
{
......@@ -326,8 +316,7 @@ if (current.dialect.supports.groupedLimit) {
] }
] }
]
})
).then(() => {
})]).then(() => {
return Company.findAll({
include: [
{ association: Company.Users, include: [
......@@ -359,8 +348,7 @@ if (current.dialect.supports.groupedLimit) {
Project.Tasks = Project.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
id: 1,
projects: [
{
......@@ -382,8 +370,7 @@ if (current.dialect.supports.groupedLimit) {
include: [
{ association: User.Projects, include: [Project.Tasks] }
]
}),
User.create({
}), User.create({
id: 2,
projects: [
{
......@@ -398,8 +385,7 @@ if (current.dialect.supports.groupedLimit) {
include: [
{ association: User.Projects, include: [Project.Tasks] }
]
})
).then(() => {
})]).then(() => {
return User.findAll({
include: [
{ association: User.Projects, separate: true, include: [
......@@ -445,8 +431,7 @@ if (current.dialect.supports.groupedLimit) {
return Support.dropTestSchemas(this.sequelize).then(() => {
return this.sequelize.createSchema('archive').then(() => {
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
User.create({
return Promise.all([User.create({
id: 1,
tasks: [
{ id: 1, title: 'b' },
......@@ -456,8 +441,7 @@ if (current.dialect.supports.groupedLimit) {
]
}, {
include: [User.Tasks]
}),
User.create({
}), User.create({
id: 2,
tasks: [
{ id: 5, title: 'a' },
......@@ -466,8 +450,7 @@ if (current.dialect.supports.groupedLimit) {
]
}, {
include: [User.Tasks]
})
);
})]);
}).then(() => {
return User.findAll({
include: [{ model: Task, limit: 2, as: 'tasks', order: [['id', 'ASC']] }],
......
......@@ -46,10 +46,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.Course.belongsToMany(this.Student, { through: this.Score, foreignKey: 'CourseId' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
this.Student.create({ no: 1, name: 'ryan' }),
this.Course.create({ no: 100, name: 'history' })
).then(([student, course]) => {
]).then(([student, course]) => {
return student.addCourse(course, { through: { score: 98, test_value: 1000 } });
}).then(() => {
expect(callCount).to.equal(1);
......@@ -58,10 +58,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
})
.then(() => {
return Promise.join(
return Promise.all([
this.Student.build({ no: 1 }).getCourses({ where: { no: 100 } }),
this.Score.findOne({ where: { StudentId: 1, CourseId: 100 } })
);
]);
})
.then(([courses, score]) => {
expect(score.test_value).to.equal(1001);
......
......@@ -542,14 +542,11 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should work with a belongsTo association getter', function() {
const userId = Math.floor(Math.random() * 100000);
return Promise.join(
this.User.create({
return Promise.all([this.User.create({
id: userId
}),
this.Task.create({
}), this.Task.create({
user_id: userId
})
).then(([user, task]) => {
})]).then(([user, task]) => {
return Promise.all([user, task.getUser()]);
}).then(([userA, userB]) => {
expect(userA.get('id')).to.equal(userB.get('id'));
......
......@@ -432,10 +432,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
if (current.dialect.supports.transactions) {
it('works with a transaction', function() {
return this.sequelize.transaction().then(transaction => {
return Promise.join(
this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction }),
return Promise.all([
this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction }),
(first, second) => {
this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction })
]).then(([first, second]) => {
const firstInstance = first[0],
firstCreated = first[1],
secondInstance = second[0],
......@@ -450,8 +450,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(firstInstance.id).to.equal(secondInstance.id);
return transaction.commit();
}
);
});
});
});
}
......@@ -512,8 +511,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
username: 'gottlieb'
});
}).then(() => {
return Promise.join(
User.findOrCreate({
return Promise.all([User.findOrCreate({
where: {
objectId: 'asdasdasd'
},
......@@ -525,8 +523,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}).catch(err => {
expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok;
expect(err.fields).to.be.ok;
}),
User.findOrCreate({
}), User.findOrCreate({
where: {
objectId: 'asdasdasd'
},
......@@ -538,17 +535,16 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}).catch(err => {
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
(dialect !== 'sqlite' ? it : it.skip)('works without a transaction', function() {
return Promise.join(
this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
return Promise.all([
this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
(first, second) => {
this.User.findOrCreate({ where: { uniqueName: 'winner' } })
]).then(([first, second]) => {
const firstInstance = first[0],
firstCreated = first[1],
secondInstance = second[0],
......@@ -561,19 +557,18 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(secondInstance).to.be.ok;
expect(firstInstance.id).to.equal(secondInstance.id);
}
);
});
});
});
});
describe('findCreateFind', () => {
(dialect !== 'sqlite' ? it : it.skip)('should work with multiple concurrent calls', function() {
return Promise.join(
this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
return Promise.all([
this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
(first, second, third) => {
this.User.findOrCreate({ where: { uniqueName: 'winner' } })
]).then(([first, second, third]) => {
const firstInstance = first[0],
firstCreated = first[1],
secondInstance = second[0],
......@@ -591,8 +586,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(firstInstance.id).to.equal(secondInstance.id);
expect(secondInstance.id).to.equal(thirdInstance.id);
}
);
});
});
});
......@@ -656,13 +650,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
Log.removeAttribute('id');
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
Log.create({ level: 'info' }),
Log.bulkCreate([
return Promise.all([Log.create({ level: 'info' }), Log.bulkCreate([
{ level: 'error' },
{ level: 'debug' }
])
);
])]);
}).then(() => {
return Log.findAll();
}).then(logs => {
......
......@@ -51,22 +51,22 @@ if (current.dialect.supports['UNION ALL']) {
this.User.Tasks = this.User.hasMany(this.Task);
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.Project.bulkCreate([{}, {}]),
this.Task.bulkCreate([{}, {}])
);
]);
})
.then(() => Promise.all([this.User.findAll(), this.Project.findAll(), this.Task.findAll()]))
.then(([users, projects, tasks]) => {
this.projects = projects;
return Promise.join(
return Promise.all([
projects[0].setMembers(users.slice(0, 4)),
projects[1].setMembers(users.slice(2)),
projects[0].setParanoidMembers(users.slice(0, 4)),
projects[1].setParanoidMembers(users.slice(2)),
users[2].setTasks(tasks)
);
]);
});
});
......@@ -218,19 +218,19 @@ if (current.dialect.supports['UNION ALL']) {
this.User.Tasks = this.User.hasMany(this.Task);
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
this.User.bulkCreate([{}, {}, {}]),
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(([users, tasks]) => {
this.users = users;
return Promise.join(
return Promise.all([
users[0].setTasks(tasks[0]),
users[1].setTasks(tasks.slice(1, 4)),
users[2].setTasks(tasks.slice(4))
);
]);
});
});
......
......@@ -210,8 +210,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
describe('find', () => {
it('should be possible to query a nested value', function() {
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
data: {
name: {
first: 'Homer',
......@@ -219,8 +218,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'Nuclear Safety Inspector'
}
}),
this.Event.create({
}), this.Event.create({
data: {
name: {
first: 'Marge',
......@@ -228,8 +226,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'Housewife'
}
})
).then(() => {
})]).then(() => {
return this.Event.findAll({
where: {
data: {
......@@ -255,14 +252,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const now = moment().milliseconds(0).toDate();
const before = moment().milliseconds(0).subtract(1, 'day').toDate();
const after = moment().milliseconds(0).add(1, 'day').toDate();
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
json: {
user: 'Homer',
lastLogin: now
}
})
).then(() => {
})]).then(() => {
return this.Event.findAll({
where: {
json: {
......@@ -298,14 +293,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
it('should be possible to query a boolean with array operators', function() {
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
json: {
user: 'Homer',
active: true
}
})
).then(() => {
})]).then(() => {
return this.Event.findAll({
where: {
json: {
......@@ -341,8 +334,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
it('should be possible to query a nested integer value', function() {
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
data: {
name: {
first: 'Homer',
......@@ -350,8 +342,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
age: 40
}
}),
this.Event.create({
}), this.Event.create({
data: {
name: {
first: 'Marge',
......@@ -359,8 +350,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
age: 37
}
})
).then(() => {
})]).then(() => {
return this.Event.findAll({
where: {
data: {
......@@ -385,8 +375,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
it('should be possible to query a nested null value', function() {
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
data: {
name: {
first: 'Homer',
......@@ -394,8 +383,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'Nuclear Safety Inspector'
}
}),
this.Event.create({
}), this.Event.create({
data: {
name: {
first: 'Marge',
......@@ -403,8 +391,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: null
}
})
).then(() => {
})]).then(() => {
return this.Event.findAll({
where: {
data: {
......@@ -425,8 +412,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
it('should be possible to query for nested fields with hyphens/dashes, #8718', function() {
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
data: {
name: {
first: 'Homer',
......@@ -439,8 +425,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'Nuclear Safety Inspector'
}
}),
this.Event.create({
}), this.Event.create({
data: {
name: {
first: 'Marge',
......@@ -448,8 +433,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: null
}
})
).then(() => {
})]).then(() => {
return this.Event.findAll({
where: {
data: {
......@@ -488,8 +472,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
employment: 'Nuclear Safety Inspector'
}
}).then(() => {
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
data: {
name: {
first: 'Marge',
......@@ -497,8 +480,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'Housewife'
}
}),
this.Event.create({
}), this.Event.create({
data: {
name: {
first: 'Bart',
......@@ -506,8 +488,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'None'
}
})
);
})]);
}).then(() => {
return this.Event.findAll({
where: {
......@@ -555,8 +536,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
employment: 'Nuclear Safety Inspector'
}
}).then(() => {
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
data: {
name: {
first: 'Marge',
......@@ -564,8 +544,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'Housewife'
}
}),
this.Event.create({
}), this.Event.create({
data: {
name: {
first: 'Bart',
......@@ -573,8 +552,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'None'
}
})
);
})]);
}).then(() => {
return this.Event.findAll({
where: {
......@@ -628,8 +606,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}
};
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
data: {
name: {
first: 'Elliot',
......@@ -637,8 +614,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'Hacker'
}
}),
this.Event.create({
}), this.Event.create({
data: {
name: {
first: 'Christian',
......@@ -646,8 +622,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'Hacker'
}
}),
this.Event.create({
}), this.Event.create({
data: {
name: {
first: ' Tyrell',
......@@ -655,8 +630,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'CTO'
}
})
).then(() => {
})]).then(() => {
return expect(this.Event.findAll(conditionSearch)).to.eventually.have.length(2);
}).then(() => {
return this.Event.destroy(conditionSearch);
......@@ -753,8 +727,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
employment: 'Nuclear Safety Inspector'
}
}).then(() => {
return Promise.join(
this.Event.create({
return Promise.all([this.Event.create({
data: {
name: {
first: 'Marge',
......@@ -762,8 +735,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'Housewife'
}
}),
this.Event.create({
}), this.Event.create({
data: {
name: {
first: 'Bart',
......@@ -771,8 +743,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
employment: 'None'
}
})
);
})]);
}).then(() => {
if (current.options.dialect === 'sqlite') {
return this.Event.findAll({
......
......@@ -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 => {
expect(users.length).to.equal(2);
});
......@@ -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) {
}).then(() => {
return this.sequelize.transaction({ isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE }).then(transaction => {
return User.findAll( { transaction } )
.then(() => Promise.join(
.then(() => Promise.all([// Update should not succeed before transaction has committed
User.update({ username: 'joe' }, {
where: {
username: 'jan'
}
}).then(() => expect(transactionSpy).to.have.been.called ), // Update should not succeed before transaction has committed
delay(2000)
}).then(() => expect(transactionSpy).to.have.been.called ), delay(2000)
.then(() => transaction.commit())
.then(transactionSpy)
));
.then(transactionSpy)]));
});
});
});
......@@ -612,8 +610,7 @@ if (current.dialect.supports.transactions) {
return this.sequelize.transaction({
isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED
}).then(t2 => {
return Promise.join(
User.findOne({
return Promise.all([User.findOne({
where: {
username: 'jan'
},
......@@ -624,9 +621,7 @@ if (current.dialect.supports.transactions) {
return t2.commit().then(() => {
expect(t2Spy).to.have.been.calledAfter(t1Spy); // Find should not succeed before t1 has committed
});
}),
t1Jan.update({
}), t1Jan.update({
awesome: true
}, {
transaction: t1
......@@ -635,8 +630,7 @@ if (current.dialect.supports.transactions) {
return delay(2000).then(() => {
return t1.commit();
});
})
);
})]);
});
});
});
......@@ -695,10 +689,10 @@ if (current.dialect.supports.transactions) {
Task.belongsToMany(User, { through: 'UserTasks' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
User.create({ username: 'John' }),
Task.create({ title: 'Get rich', active: false }),
(john, task1) => {
Task.create({ title: 'Get rich', active: false })
]).then(([john, task1]) => {
return john.setTasks([task1]);
})
.then(() => {
......@@ -738,11 +732,11 @@ if (current.dialect.supports.transactions) {
Task.belongsToMany(User, { through: 'UserTasks' });
return this.sequelize.sync({ force: true }).then(() => {
return Promise.join(
return Promise.all([
User.create({ username: 'John' }),
Task.create({ title: 'Get rich', active: false }),
Task.create({ title: 'Die trying', active: false }),
(john, task1) => {
Task.create({ title: 'Die trying', active: false })
]).then(([john, task1]) => {
return john.setTasks([task1]);
})
.then(() => {
......@@ -801,8 +795,7 @@ if (current.dialect.supports.transactions) {
transaction: t1
}).then(t1Jan => {
return this.sequelize.transaction().then(t2 => {
return Promise.join(
User.findOne({
return Promise.all([User.findOne({
where: {
username: 'jan'
},
......@@ -811,8 +804,7 @@ if (current.dialect.supports.transactions) {
}).then(() => {
t2Spy();
return t2.commit();
}),
t1Jan.update({
}), t1Jan.update({
awesome: true
}, {
transaction: t1
......@@ -822,8 +814,7 @@ if (current.dialect.supports.transactions) {
expect(t1Spy).to.have.been.calledAfter(t2Spy);
return t1.commit();
});
})
);
})]);
});
});
});
......@@ -854,8 +845,7 @@ if (current.dialect.supports.transactions) {
return this.sequelize.transaction({
isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED
}).then(t2 => {
return Promise.join(
User.findOne({
return Promise.all([User.findOne({
where: {
username: 'jan'
},
......@@ -873,9 +863,7 @@ if (current.dialect.supports.transactions) {
expect(t2UpdateSpy).to.have.been.calledAfter(t1Spy); // But the update call should not happen before the first transaction has committed
});
});
}),
t1Jan.update({
}), t1Jan.update({
awesome: true
}, {
transaction: t1
......@@ -884,8 +872,7 @@ if (current.dialect.supports.transactions) {
t1Spy();
return t1.commit();
});
})
);
})]);
});
});
});
......
......@@ -309,17 +309,13 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
});
it('should allow decimal as scientific notation', () => {
return Promise.join(
expect(User.create({
return Promise.all([expect(User.create({
number: '2321312301230128391820e219'
})).not.to.be.rejected,
expect(User.create({
})).not.to.be.rejected, expect(User.create({
number: '2321312301230128391820e+219'
})).not.to.be.rejected,
expect(User.create({
})).not.to.be.rejected, expect(User.create({
number: '2321312301230128391820f219'
})).to.be.rejected
);
})).to.be.rejected]);
});
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!