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

Commit a1ec8a18 by Andy Edwards Committed by GitHub

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

1 parent 39a1f11f
...@@ -257,10 +257,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -257,10 +257,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(User, { as: 'users', through: User_has_Group, foreignKey: 'id_group' }); Group.belongsToMany(User, { as: 'users', through: User_has_Group, foreignKey: 'id_group' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), Group.create()]).then(([user, group]) => {
User.create(),
Group.create()
).then(([user, group]) => {
return user.addGroup(group); return user.addGroup(group);
}).then(() => { }).then(() => {
return User.findOne({ return User.findOne({
...@@ -307,21 +304,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -307,21 +304,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(User, { through: User_has_Group }); Group.belongsToMany(User, { through: User_has_Group });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), Group.create()]).then(([user, group]) => {
User.create(),
Group.create()
).then(([user, group]) => {
return user.addGroup(group); return user.addGroup(group);
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findOne({
User.findOne({
where: {}, where: {},
include: [Group] include: [Group]
}), }), User.findAll({
User.findAll({
include: [Group] include: [Group]
}) })]);
);
}).then(([user, users]) => { }).then(([user, users]) => {
expect(user.Groups.length).to.be.equal(1); expect(user.Groups.length).to.be.equal(1);
expect(user.Groups[0].User_has_Group.UserUserSecondId).to.be.ok; expect(user.Groups[0].User_has_Group.UserUserSecondId).to.be.ok;
...@@ -387,23 +378,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -387,23 +378,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(User, { through: 'usergroups', sourceKey: 'groupSecondId' }); Group.belongsToMany(User, { through: 'usergroups', sourceKey: 'groupSecondId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), User.create(), Group.create(), Group.create()]).then(([user1, user2, group1, group2]) => {
User.create(), return Promise.all([user1.addGroup(group1), user2.addGroup(group2)]);
User.create(),
Group.create(),
Group.create()
).then(([user1, user2, group1, group2]) => {
return Promise.join(user1.addGroup(group1), user2.addGroup(group2));
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findAll({
User.findAll({
where: {}, where: {},
include: [Group] include: [Group]
}), }), Group.findAll({
Group.findAll({
include: [User] include: [User]
}) })]);
);
}).then(([users, groups]) => { }).then(([users, groups]) => {
expect(users.length).to.be.equal(2); expect(users.length).to.be.equal(2);
expect(users[0].Groups.length).to.be.equal(1); expect(users[0].Groups.length).to.be.equal(1);
...@@ -479,23 +462,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -479,23 +462,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(User, { through: 'usergroups', targetKey: 'userSecondId' }); Group.belongsToMany(User, { through: 'usergroups', targetKey: 'userSecondId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), User.create(), Group.create(), Group.create()]).then(([user1, user2, group1, group2]) => {
User.create(), return Promise.all([user1.addGroup(group1), user2.addGroup(group2)]);
User.create(),
Group.create(),
Group.create()
).then(([user1, user2, group1, group2]) => {
return Promise.join(user1.addGroup(group1), user2.addGroup(group2));
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findAll({
User.findAll({
where: {}, where: {},
include: [Group] include: [Group]
}), }), Group.findAll({
Group.findAll({
include: [User] include: [User]
}) })]);
);
}).then(([users, groups]) => { }).then(([users, groups]) => {
expect(users.length).to.be.equal(2); expect(users.length).to.be.equal(2);
expect(users[0].Groups.length).to.be.equal(1); expect(users[0].Groups.length).to.be.equal(1);
...@@ -577,23 +552,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -577,23 +552,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(User, { through: 'usergroups', sourceKey: 'groupSecondId', targetKey: 'userSecondId' }); Group.belongsToMany(User, { through: 'usergroups', sourceKey: 'groupSecondId', targetKey: 'userSecondId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), User.create(), Group.create(), Group.create()]).then(([user1, user2, group1, group2]) => {
User.create(), return Promise.all([user1.addGroup(group1), user2.addGroup(group2)]);
User.create(),
Group.create(),
Group.create()
).then(([user1, user2, group1, group2]) => {
return Promise.join(user1.addGroup(group1), user2.addGroup(group2));
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findAll({
User.findAll({
where: {}, where: {},
include: [Group] include: [Group]
}), }), Group.findAll({
Group.findAll({
include: [User] include: [User]
}) })]);
);
}).then(([users, groups]) => { }).then(([users, groups]) => {
expect(users.length).to.be.equal(2); expect(users.length).to.be.equal(2);
expect(users[0].Groups.length).to.be.equal(1); expect(users[0].Groups.length).to.be.equal(1);
...@@ -686,23 +653,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -686,23 +653,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(User, { through: User_has_Group, sourceKey: 'groupSecondId' }); Group.belongsToMany(User, { through: User_has_Group, sourceKey: 'groupSecondId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), User.create(), Group.create(), Group.create()]).then(([user1, user2, group1, group2]) => {
User.create(), return Promise.all([user1.addGroup(group1), user2.addGroup(group2)]);
User.create(),
Group.create(),
Group.create()
).then(([user1, user2, group1, group2]) => {
return Promise.join(user1.addGroup(group1), user2.addGroup(group2));
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findAll({
User.findAll({
where: {}, where: {},
include: [Group] include: [Group]
}), }), Group.findAll({
Group.findAll({
include: [User] include: [User]
}) })]);
);
}).then(([users, groups]) => { }).then(([users, groups]) => {
expect(users.length).to.be.equal(2); expect(users.length).to.be.equal(2);
expect(users[0].Groups.length).to.be.equal(1); expect(users[0].Groups.length).to.be.equal(1);
...@@ -782,19 +741,11 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -782,19 +741,11 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(User, { through: 'usergroups', sourceKey: 'groupSecondId', targetKey: 'userSecondId' }); Group.belongsToMany(User, { through: 'usergroups', sourceKey: 'groupSecondId', targetKey: 'userSecondId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), User.create(), Group.create(), Group.create()]).then(([user1, user2, group1, group2]) => {
User.create(), return Promise.all([user1.addGroup(group1), user2.addGroup(group2)])
User.create(),
Group.create(),
Group.create()
).then(([user1, user2, group1, group2]) => {
return Promise.join(user1.addGroup(group1), user2.addGroup(group2))
.then(() => { .then(() => {
return Promise.join( return Promise.all(
user1.getGroups(), [user1.getGroups(), user2.getGroups(), group1.getUsers(), group2.getUsers()]
user2.getGroups(),
group1.getUsers(),
group2.getUsers()
); );
}).then(([groups1, groups2, users1, users2]) => { }).then(([groups1, groups2, users1, users2]) => {
expect(groups1.length).to.be.equal(1); expect(groups1.length).to.be.equal(1);
...@@ -863,23 +814,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -863,23 +814,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(User, { through: 'usergroups', foreignKey: 'groupId2', sourceKey: 'groupSecondId' }); Group.belongsToMany(User, { through: 'usergroups', foreignKey: 'groupId2', sourceKey: 'groupSecondId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), User.create(), Group.create(), Group.create()]).then(([user1, user2, group1, group2]) => {
User.create(), return Promise.all([user1.addGroup(group1), user2.addGroup(group2)]);
User.create(),
Group.create(),
Group.create()
).then(([user1, user2, group1, group2]) => {
return Promise.join(user1.addGroup(group1), user2.addGroup(group2));
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findAll({
User.findAll({
where: {}, where: {},
include: [Group] include: [Group]
}), }), Group.findAll({
Group.findAll({
include: [User] include: [User]
}) })]);
);
}).then(([users, groups]) => { }).then(([users, groups]) => {
expect(users.length).to.be.equal(2); expect(users.length).to.be.equal(2);
expect(users[0].Groups.length).to.be.equal(1); expect(users[0].Groups.length).to.be.equal(1);
...@@ -982,23 +925,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -982,23 +925,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(User, { through: User_has_Group, foreignKey: 'groupId2', sourceKey: 'groupSecondId' }); Group.belongsToMany(User, { through: User_has_Group, foreignKey: 'groupId2', sourceKey: 'groupSecondId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), User.create(), Group.create(), Group.create()]).then(([user1, user2, group1, group2]) => {
User.create(), return Promise.all([user1.addGroup(group1), user2.addGroup(group2)]);
User.create(),
Group.create(),
Group.create()
).then(([user1, user2, group1, group2]) => {
return Promise.join(user1.addGroup(group1), user2.addGroup(group2));
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findAll({
User.findAll({
where: {}, where: {},
include: [Group] include: [Group]
}), }), Group.findAll({
Group.findAll({
include: [User] include: [User]
}) })]);
);
}).then(([users, groups]) => { }).then(([users, groups]) => {
expect(users.length).to.be.equal(2); expect(users.length).to.be.equal(2);
expect(users[0].Groups.length).to.be.equal(1); expect(users[0].Groups.length).to.be.equal(1);
...@@ -1076,40 +1011,28 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -1076,40 +1011,28 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Group.belongsToMany(Company, { through: Company_has_Group }); Group.belongsToMany(Company, { through: Company_has_Group });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create(), Group.create(), Company.create()]).then(([user, group, company]) => {
User.create(), return Promise.all([user.setCompany(company), company.addGroup(group)]);
Group.create(),
Company.create()
).then(([user, group, company]) => {
return Promise.join(
user.setCompany(company),
company.addGroup(group)
);
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findOne({
User.findOne({
where: {}, where: {},
include: [ include: [
{ model: Company, include: [Group] } { model: Company, include: [Group] }
] ]
}), }), User.findAll({
User.findAll({
include: [ include: [
{ model: Company, include: [Group] } { model: Company, include: [Group] }
] ]
}), }), User.findOne({
User.findOne({
where: {}, where: {},
include: [ include: [
{ model: Company, required: true, include: [Group] } { model: Company, required: true, include: [Group] }
] ]
}), }), User.findAll({
User.findAll({
include: [ include: [
{ model: Company, required: true, include: [Group] } { model: Company, required: true, include: [Group] }
] ]
}) })]);
);
}); });
}); });
}); });
...@@ -1808,13 +1731,12 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -1808,13 +1731,12 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Group.create({}); return Group.create({});
}).then(group => { }).then(group => {
return Promise.join( return Promise.all([
group.createUser({ id: 1 }, { through: { isAdmin: true } }), group.createUser({ id: 1 }, { through: { isAdmin: true } }),
group.createUser({ id: 2 }, { through: { isAdmin: false } }), group.createUser({ id: 2 }, { through: { isAdmin: false } })
() => { ]).then(() => {
return UserGroups.findAll(); return UserGroups.findAll();
} });
);
}).then(userGroups => { }).then(userGroups => {
userGroups.sort((a, b) => { userGroups.sort((a, b) => {
return a.userId < b.userId ? - 1 : 1; return a.userId < b.userId ? - 1 : 1;
...@@ -2413,11 +2335,11 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2413,11 +2335,11 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
const spy = sinon.spy(); const spy = sinon.spy();
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.User.create({ name: 'Matt' }), this.User.create({ name: 'Matt' }),
this.Project.create({ name: 'Good Will Hunting' }), this.Project.create({ name: 'Good Will Hunting' }),
this.Project.create({ name: 'The Departed' }) this.Project.create({ name: 'The Departed' })
); ]);
}).then(([user, project1, project2]) => { }).then(([user, project1, project2]) => {
return user.addProjects([project1, project2], { return user.addProjects([project1, project2], {
logging: spy logging: spy
...@@ -2425,12 +2347,9 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2425,12 +2347,9 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}).then(user => { }).then(user => {
expect(spy).to.have.been.calledTwice; expect(spy).to.have.been.calledTwice;
spy.resetHistory(); spy.resetHistory();
return Promise.join( return Promise.all([user, user.getProjects({
user,
user.getProjects({
logging: spy logging: spy
}) })]);
);
}).then(([user, projects]) => { }).then(([user, projects]) => {
expect(spy.calledOnce).to.be.ok; expect(spy.calledOnce).to.be.ok;
const project = projects[0]; const project = projects[0];
...@@ -2509,11 +2428,11 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2509,11 +2428,11 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}); });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Group.create({ groupName: 'The Illuminati' }), this.Group.create({ groupName: 'The Illuminati' }),
this.User.create({ name: 'Matt' }), this.User.create({ name: 'Matt' }),
this.Project.create({ name: 'Good Will Hunting' }) this.Project.create({ name: 'Good Will Hunting' })
); ]);
}).then(([group, user, project]) => { }).then(([group, user, project]) => {
return user.addProject(project).then(() => { return user.addProject(project).then(() => {
return group.addUser(user).then(() => group); return group.addUser(user).then(() => group);
...@@ -3479,9 +3398,10 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -3479,9 +3398,10 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
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.addPersonwearinghat(hat); return individual.addPersonwearinghat(hat);
}).then(() => { }).then(() => {
...@@ -3507,9 +3427,10 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -3507,9 +3427,10 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
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.addPersonwearinghat(hat); return individual.addPersonwearinghat(hat);
}).then(() => { }).then(() => {
......
...@@ -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({
Task.create({
id: 2, id: 2,
user: { id: 2 } user: { id: 2 }
}, { }, {
include: [Task.User] include: [Task.User]
}), }), Task.create({
Task.create({
id: 3 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(() => {
......
...@@ -45,10 +45,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -45,10 +45,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
include: [Task] include: [Task]
}); });
}).then(user => { }).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: 'Make a startup', active: false }),
user.get('Tasks')[0].createSubtask({ title: 'Engage rock stars', active: true }) user.get('Tasks')[0].createSubtask({ title: 'Engage rock stars', active: true })
).then(() => user); ]).then(() => user);
}).then(user => { }).then(user => {
return expect(user.countTasks({ return expect(user.countTasks({
attributes: [Task.primaryKeyField, 'title'], attributes: [Task.primaryKeyField, 'title'],
...@@ -75,8 +75,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -75,8 +75,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
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: [
{}, {},
...@@ -85,19 +84,16 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -85,19 +84,16 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
}), }), User.create({
User.create({
id: 2, id: 2,
tasks: [ tasks: [
{} {}
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
}), }), User.create({
User.create({
id: 3 id: 3
}) })]);
);
}).then(users => { }).then(users => {
return User.Tasks.get(users).then(result => { return User.Tasks.get(users).then(result => {
expect(result[users[0].id].length).to.equal(3); expect(result[users[0].id].length).to.equal(3);
...@@ -116,8 +112,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -116,8 +112,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
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({
tasks: [ tasks: [
{ title: 'b' }, { title: 'b' },
{ title: 'd' }, { title: 'd' },
...@@ -126,8 +121,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -126,8 +121,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
}), }), User.create({
User.create({
tasks: [ tasks: [
{ title: 'a' }, { title: 'a' },
{ title: 'c' }, { title: 'c' },
...@@ -135,8 +129,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -135,8 +129,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
}) })]);
);
}).then(users => { }).then(users => {
return User.Tasks.get(users, { return User.Tasks.get(users, {
limit: 2, limit: 2,
...@@ -168,8 +161,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -168,8 +161,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
Task.SubTasks = Task.hasMany(SubTask, { as: 'subtasks' }); Task.SubTasks = Task.hasMany(SubTask, { as: 'subtasks' });
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: [
{ title: 'b', subtasks: [ { title: 'b', subtasks: [
...@@ -190,8 +182,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -190,8 +182,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
] ]
}, { }, {
include: [{ association: User.Tasks, include: [Task.SubTasks] }] include: [{ association: User.Tasks, include: [Task.SubTasks] }]
}), }), User.create({
User.create({
id: 2, id: 2,
tasks: [ tasks: [
{ title: 'a', subtasks: [ { title: 'a', subtasks: [
...@@ -209,8 +200,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -209,8 +200,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
] ]
}, { }, {
include: [{ association: User.Tasks, include: [Task.SubTasks] }] include: [{ association: User.Tasks, include: [Task.SubTasks] }]
}) })]);
);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [{ include: [{
...@@ -275,8 +265,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -275,8 +265,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
Task.Category = Task.belongsTo(Category, { as: 'category', foreignKey: 'categoryId' }); Task.Category = Task.belongsTo(Category, { as: 'category', foreignKey: 'categoryId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({
tasks: [ tasks: [
{ title: 'b', category: {} }, { title: 'b', category: {} },
{ title: 'd', category: {} }, { title: 'd', category: {} },
...@@ -285,8 +274,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -285,8 +274,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
] ]
}, { }, {
include: [{ association: User.Tasks, include: [Task.Category] }] include: [{ association: User.Tasks, include: [Task.Category] }]
}), }), User.create({
User.create({
tasks: [ tasks: [
{ title: 'a', category: {} }, { title: 'a', category: {} },
{ title: 'c', category: {} }, { title: 'c', category: {} },
...@@ -294,8 +282,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -294,8 +282,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
] ]
}, { }, {
include: [{ association: User.Tasks, include: [Task.Category] }] include: [{ association: User.Tasks, include: [Task.Category] }]
}) })]);
);
}).then(users => { }).then(users => {
return User.Tasks.get(users, { return User.Tasks.get(users, {
limit: 2, limit: 2,
...@@ -340,8 +327,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -340,8 +327,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
}).then(() => { }).then(() => {
return SubTask.sync({ force: true }); return SubTask.sync({ force: true });
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({
id: 1, id: 1,
tasks: [ tasks: [
{ title: 'b', subtasks: [ { title: 'b', subtasks: [
...@@ -362,8 +348,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -362,8 +348,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
] ]
}, { }, {
include: [{ association: User.Tasks, include: [Task.SubTasks] }] include: [{ association: User.Tasks, include: [Task.SubTasks] }]
}), }), User.create({
User.create({
id: 2, id: 2,
tasks: [ tasks: [
{ title: 'a', subtasks: [ { title: 'a', subtasks: [
...@@ -381,8 +366,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -381,8 +366,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
] ]
}, { }, {
include: [{ association: User.Tasks, include: [Task.SubTasks] }] include: [{ association: User.Tasks, include: [Task.SubTasks] }]
}) })]);
);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [{ include: [{
...@@ -1719,9 +1703,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -1719,9 +1703,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
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.addPersonwearinghat(hat); return individual.addPersonwearinghat(hat);
}).then(() => { }).then(() => {
...@@ -1738,9 +1723,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -1738,9 +1723,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
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.addPersonwearinghat(hat); return individual.addPersonwearinghat(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({
Player.create({
id: 2, id: 2,
user: {} user: {}
}, { }, {
include: [Player.User] include: [Player.User]
}), }), Player.create({
Player.create({
id: 3 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(() => {
......
...@@ -99,16 +99,12 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -99,16 +99,12 @@ describe(Support.getTestDialectTeaser('associations'), () => {
describe('1:1', () => { describe('1:1', () => {
it('should create, find and include associations with scope values', function() { it('should create, find and include associations with scope values', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([this.Post.create(), this.Comment.create({
this.Post.create(),
this.Comment.create({
title: 'I am a comment' title: 'I am a comment'
}), }), this.Comment.create({
this.Comment.create({
title: 'I am a main comment', title: 'I am a main comment',
isMain: true isMain: true
}) })]);
);
}).then(([post]) => { }).then(([post]) => {
this.post = post; this.post = post;
return post.createComment({ return post.createComment({
...@@ -170,7 +166,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -170,7 +166,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
describe('1:M', () => { describe('1:M', () => {
it('should create, find and include associations with scope values', function() { it('should create, find and include associations with scope values', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Post.create(), this.Post.create(),
this.Image.create(), this.Image.create(),
this.Question.create(), this.Question.create(),
...@@ -180,18 +176,14 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -180,18 +176,14 @@ describe(Support.getTestDialectTeaser('associations'), () => {
this.Comment.create({ this.Comment.create({
title: 'I am a question comment' title: 'I am a question comment'
}) })
); ]);
}).then(([post, image, question, commentA, commentB]) => { }).then(([post, image, question, commentA, commentB]) => {
this.post = post; this.post = post;
this.image = image; this.image = image;
this.question = question; this.question = question;
return Promise.join( return Promise.all([post.createComment({
post.createComment({
title: 'I am a post comment' title: 'I am a post comment'
}), }), image.addComment(commentA), question.setComments([commentB])]);
image.addComment(commentA),
question.setComments([commentB])
);
}).then(() => { }).then(() => {
return this.Comment.findAll(); return this.Comment.findAll();
}).then(comments => { }).then(comments => {
...@@ -202,11 +194,11 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -202,11 +194,11 @@ describe(Support.getTestDialectTeaser('associations'), () => {
return comment.get('commentable'); return comment.get('commentable');
}).sort()).to.deep.equal(['image', 'post', 'question']); }).sort()).to.deep.equal(['image', 'post', 'question']);
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([
this.post.getComments(), this.post.getComments(),
this.image.getComments(), this.image.getComments(),
this.question.getComments() this.question.getComments()
); ]);
}).then(([postComments, imageComments, questionComments]) => { }).then(([postComments, imageComments, questionComments]) => {
expect(postComments.length).to.equal(1); expect(postComments.length).to.equal(1);
expect(postComments[0].get('title')).to.equal('I am a post comment'); expect(postComments[0].get('title')).to.equal('I am a post comment');
...@@ -217,27 +209,19 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -217,27 +209,19 @@ describe(Support.getTestDialectTeaser('associations'), () => {
return [postComments[0], imageComments[0], questionComments[0]]; return [postComments[0], imageComments[0], questionComments[0]];
}).then(([postComment, imageComment, questionComment]) => { }).then(([postComment, imageComment, questionComment]) => {
return Promise.join( return Promise.all([postComment.getItem(), imageComment.getItem(), questionComment.getItem()]);
postComment.getItem(),
imageComment.getItem(),
questionComment.getItem()
);
}).then(([post, image, question]) => { }).then(([post, image, question]) => {
expect(post).to.be.instanceof(this.Post); expect(post).to.be.instanceof(this.Post);
expect(image).to.be.instanceof(this.Image); expect(image).to.be.instanceof(this.Image);
expect(question).to.be.instanceof(this.Question); expect(question).to.be.instanceof(this.Question);
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([this.Post.findOne({
this.Post.findOne({
include: [this.Comment] include: [this.Comment]
}), }), this.Image.findOne({
this.Image.findOne({
include: [this.Comment] include: [this.Comment]
}), }), this.Question.findOne({
this.Question.findOne({
include: [this.Comment] include: [this.Comment]
}) })]);
);
}).then(([post, image, question]) => { }).then(([post, image, question]) => {
expect(post.comments.length).to.equal(1); expect(post.comments.length).to.equal(1);
expect(post.comments[0].get('title')).to.equal('I am a post comment'); expect(post.comments[0].get('title')).to.equal('I am a post comment');
...@@ -294,21 +278,16 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -294,21 +278,16 @@ describe(Support.getTestDialectTeaser('associations'), () => {
}); });
it('should include associations with operator scope values', function() { it('should include associations with operator scope values', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([this.Post.create(), this.Comment.create({
this.Post.create(),
this.Comment.create({
title: 'I am a blue comment', title: 'I am a blue comment',
type: 'blue' type: 'blue'
}), }), this.Comment.create({
this.Comment.create({
title: 'I am a red comment', title: 'I am a red comment',
type: 'red' type: 'red'
}), }), this.Comment.create({
this.Comment.create({
title: 'I am a green comment', title: 'I am a green comment',
type: 'green' type: 'green'
}) })]);
);
}).then(([post, commentA, commentB, commentC]) => { }).then(([post, commentA, commentB, commentC]) => {
this.post = post; this.post = post;
return post.addComments([commentA, commentB, commentC]); return post.addComments([commentA, commentB, commentC]);
...@@ -344,13 +323,10 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -344,13 +323,10 @@ describe(Support.getTestDialectTeaser('associations'), () => {
}); });
it('should create, find and include associations with scope values', function() { it('should create, find and include associations with scope values', function() {
return Promise.join( return Promise.all([this.Post.sync({ force: true }), this.Tag.sync({ force: true })]).then(() => {
this.Post.sync({ force: true }),
this.Tag.sync({ force: true })
).then(() => {
return this.PostTag.sync({ force: true }); return this.PostTag.sync({ force: true });
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([
this.Post.create(), this.Post.create(),
this.Post.create(), this.Post.create(),
this.Post.create(), this.Post.create(),
...@@ -358,29 +334,29 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -358,29 +334,29 @@ describe(Support.getTestDialectTeaser('associations'), () => {
this.Tag.create({ type: 'category' }), this.Tag.create({ type: 'category' }),
this.Tag.create({ type: 'tag' }), this.Tag.create({ type: 'tag' }),
this.Tag.create({ type: 'tag' }) this.Tag.create({ type: 'tag' })
); ]);
}).then(([postA, postB, postC, categoryA, categoryB, tagA, tagB]) => { }).then(([postA, postB, postC, categoryA, categoryB, tagA, tagB]) => {
this.postA = postA; this.postA = postA;
this.postB = postB; this.postB = postB;
this.postC = postC; this.postC = postC;
return Promise.join( return Promise.all([
postA.addCategory(categoryA), postA.addCategory(categoryA),
postB.setCategories([categoryB]), postB.setCategories([categoryB]),
postC.createCategory(), postC.createCategory(),
postA.createTag(), postA.createTag(),
postB.addTag(tagA), postB.addTag(tagA),
postC.setTags([tagB]) postC.setTags([tagB])
); ]);
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([
this.postA.getCategories(), this.postA.getCategories(),
this.postA.getTags(), this.postA.getTags(),
this.postB.getCategories(), this.postB.getCategories(),
this.postB.getTags(), this.postB.getTags(),
this.postC.getCategories(), this.postC.getCategories(),
this.postC.getTags() this.postC.getTags()
); ]);
}).then(([postACategories, postATags, postBCategories, postBTags, postCCategories, postCTags]) => { }).then(([postACategories, postATags, postBCategories, postBTags, postCCategories, postCTags]) => {
expect(postACategories.length).to.equal(1); expect(postACategories.length).to.equal(1);
expect(postATags.length).to.equal(1); expect(postATags.length).to.equal(1);
...@@ -396,8 +372,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -396,8 +372,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
expect(postCCategories[0].get('type')).to.equal('category'); expect(postCCategories[0].get('type')).to.equal('category');
expect(postCTags[0].get('type')).to.equal('tag'); expect(postCTags[0].get('type')).to.equal('tag');
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([this.Post.findOne({
this.Post.findOne({
where: { where: {
id: this.postA.get('id') id: this.postA.get('id')
}, },
...@@ -405,8 +380,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -405,8 +380,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
{ model: this.Tag, as: 'tags' }, { model: this.Tag, as: 'tags' },
{ model: this.Tag, as: 'categories' } { model: this.Tag, as: 'categories' }
] ]
}), }), this.Post.findOne({
this.Post.findOne({
where: { where: {
id: this.postB.get('id') id: this.postB.get('id')
}, },
...@@ -414,8 +388,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -414,8 +388,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
{ model: this.Tag, as: 'tags' }, { model: this.Tag, as: 'tags' },
{ model: this.Tag, as: 'categories' } { model: this.Tag, as: 'categories' }
] ]
}), }), this.Post.findOne({
this.Post.findOne({
where: { where: {
id: this.postC.get('id') id: this.postC.get('id')
}, },
...@@ -423,8 +396,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -423,8 +396,7 @@ describe(Support.getTestDialectTeaser('associations'), () => {
{ model: this.Tag, as: 'tags' }, { model: this.Tag, as: 'tags' },
{ model: this.Tag, as: 'categories' } { model: this.Tag, as: 'categories' }
] ]
}) })]);
);
}).then(([postA, postB, postC]) => { }).then(([postA, postB, postC]) => {
expect(postA.get('categories').length).to.equal(1); expect(postA.get('categories').length).to.equal(1);
expect(postA.get('tags').length).to.equal(1); expect(postA.get('tags').length).to.equal(1);
...@@ -532,52 +504,35 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -532,52 +504,35 @@ describe(Support.getTestDialectTeaser('associations'), () => {
}); });
it('should create, find and include associations with scope values', function() { it('should create, find and include associations with scope values', function() {
return Promise.join( return Promise.all([
this.Post.sync({ force: true }), this.Post.sync({ force: true }),
this.Image.sync({ force: true }), this.Image.sync({ force: true }),
this.Question.sync({ force: true }), this.Question.sync({ force: true }),
this.Tag.sync({ force: true }) this.Tag.sync({ force: true })
).then(() => { ]).then(() => {
return this.ItemTag.sync({ force: true }); return this.ItemTag.sync({ force: true });
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([
this.Post.create(), this.Post.create(),
this.Image.create(), this.Image.create(),
this.Question.create(), this.Question.create(),
this.Tag.create({ name: 'tagA' }), this.Tag.create({ name: 'tagA' }),
this.Tag.create({ name: 'tagB' }), this.Tag.create({ name: 'tagB' }),
this.Tag.create({ name: 'tagC' }) this.Tag.create({ name: 'tagC' })
); ]);
}).then(([post, image, question, tagA, tagB, tagC]) => { }).then(([post, image, question, tagA, tagB, tagC]) => {
this.post = post; this.post = post;
this.image = image; this.image = image;
this.question = question; this.question = question;
return Promise.join( return Promise.all([post.setTags([tagA]).then(() => {
post.setTags([tagA]).then(() => { return Promise.all([post.createTag({ name: 'postTag' }), post.addTag(tagB)]);
return Promise.join( }), image.setTags([tagB]).then(() => {
post.createTag({ name: 'postTag' }), return Promise.all([image.createTag({ name: 'imageTag' }), image.addTag(tagC)]);
post.addTag(tagB) }), question.setTags([tagC]).then(() => {
); return Promise.all([question.createTag({ name: 'questionTag' }), question.addTag(tagA)]);
}), })]);
image.setTags([tagB]).then(() => {
return Promise.join(
image.createTag({ name: 'imageTag' }),
image.addTag(tagC)
);
}),
question.setTags([tagC]).then(() => {
return Promise.join(
question.createTag({ name: 'questionTag' }),
question.addTag(tagA)
);
})
);
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([this.post.getTags(), this.image.getTags(), this.question.getTags()]).then(([postTags, imageTags, questionTags]) => {
this.post.getTags(),
this.image.getTags(),
this.question.getTags()
).then(([postTags, imageTags, questionTags]) => {
expect(postTags.length).to.equal(3); expect(postTags.length).to.equal(3);
expect(imageTags.length).to.equal(3); expect(imageTags.length).to.equal(3);
expect(questionTags.length).to.equal(3); expect(questionTags.length).to.equal(3);
...@@ -594,20 +549,16 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -594,20 +549,16 @@ describe(Support.getTestDialectTeaser('associations'), () => {
return tag.name; return tag.name;
}).sort()).to.deep.equal(['questionTag', 'tagA', 'tagC']); }).sort()).to.deep.equal(['questionTag', 'tagA', 'tagC']);
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([this.Post.findOne({
this.Post.findOne({
where: {}, where: {},
include: [this.Tag] include: [this.Tag]
}), }), this.Image.findOne({
this.Image.findOne({
where: {}, where: {},
include: [this.Tag] include: [this.Tag]
}), }), this.Question.findOne({
this.Question.findOne({
where: {}, where: {},
include: [this.Tag] include: [this.Tag]
}) })]).then(([post, image, question]) => {
).then(([post, image, question]) => {
expect(post.tags.length).to.equal(3); expect(post.tags.length).to.equal(3);
expect(image.tags.length).to.equal(3); expect(image.tags.length).to.equal(3);
expect(question.tags.length).to.equal(3); expect(question.tags.length).to.equal(3);
......
...@@ -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({
user.createTask({
title: 'pursuit' 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: {
......
...@@ -250,28 +250,20 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -250,28 +250,20 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Tag.belongsToMany(Product, { through: ProductTag }); Tag.belongsToMany(Product, { through: ProductTag });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Set.bulkCreate([
Set.bulkCreate([
{ title: 'office' } { title: 'office' }
]), ]), Product.bulkCreate([
Product.bulkCreate([
{ title: 'Chair' }, { title: 'Chair' },
{ title: 'Desk' }, { title: 'Desk' },
{ title: 'Dress' } { title: 'Dress' }
]), ]), Tag.bulkCreate([
Tag.bulkCreate([
{ name: 'A' }, { name: 'A' },
{ name: 'B' }, { name: 'B' },
{ name: 'C' } { name: 'C' }
]) ])]).then(() => {
).then(() => { return Promise.all([Set.findAll(), Product.findAll(), Tag.findAll()]);
return Promise.join(
Set.findAll(),
Product.findAll(),
Tag.findAll()
);
}).then(([sets, products, tags]) => { }).then(([sets, products, tags]) => {
return Promise.join( return Promise.all([
sets[0].addProducts([products[0], products[1]]), sets[0].addProducts([products[0], products[1]]),
products[0].addTag(tags[0], { priority: 1 }).then(() => { products[0].addTag(tags[0], { priority: 1 }).then(() => {
return products[0].addTag(tags[1], { priority: 2 }); return products[0].addTag(tags[1], { priority: 2 });
...@@ -283,7 +275,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -283,7 +275,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
}).then(() => { }).then(() => {
return products[2].addTag(tags[2], { priority: 0 }); return products[2].addTag(tags[2], { priority: 0 });
}) })
); ]);
}).then(() => { }).then(() => {
return Set.findAll({ return Set.findAll({
include: [{ include: [{
...@@ -453,8 +445,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -453,8 +445,7 @@ 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.bulkCreate([
A.bulkCreate([
{}, {},
{}, {},
{}, {},
...@@ -465,8 +456,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -465,8 +456,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{} {}
]).then(() => { ]).then(() => {
return A.findAll(); return A.findAll();
}), }), (function(singles) {
(function(singles) {
let promise = Promise.resolve(), let promise = Promise.resolve(),
previousInstance, previousInstance,
b; b;
...@@ -489,8 +479,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -489,8 +479,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
}); });
return promise; return promise;
})([B, C, D, E, F, G, H]) })([B, C, D, E, F, G, H])]).then(([as, b]) => {
).then(([as, b]) => {
return Promise.all(as.map(a => { return Promise.all(as.map(a => {
return a.setB(b); return a.setB(b);
})); }));
...@@ -545,8 +534,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -545,8 +534,7 @@ 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.bulkCreate([
A.bulkCreate([
{}, {},
{}, {},
{}, {},
...@@ -557,8 +545,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -557,8 +545,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{} {}
]).then(() => { ]).then(() => {
return A.findAll(); return A.findAll();
}), }), (function(singles) {
(function(singles) {
let promise = Promise.resolve(), let promise = Promise.resolve(),
previousInstance, previousInstance,
b; b;
...@@ -587,8 +574,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -587,8 +574,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
}); });
return promise; return promise;
})([B, C, D, E, F, G, H]) })([B, C, D, E, F, G, H])]).then(([as, b]) => {
).then(([as, b]) => {
return Promise.all(as.map(a => { return Promise.all(as.map(a => {
return a.setB(b); return a.setB(b);
})); }));
...@@ -665,7 +651,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -665,7 +651,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
const order2 = results.orders[1]; const order2 = results.orders[1];
const order3 = results.orders[2]; const order3 = results.orders[2];
return Promise.join( return Promise.all([
user1.setItemA(item1), user1.setItemA(item1),
user1.setItemB(item2), user1.setItemB(item2),
user1.setOrder(order3), user1.setOrder(order3),
...@@ -675,7 +661,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -675,7 +661,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
user3.setItemA(item1), user3.setItemA(item1),
user3.setItemB(item4), user3.setItemB(item4),
user3.setOrder(order1) user3.setOrder(order1)
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
'include': [ 'include': [
...@@ -729,14 +715,14 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -729,14 +715,14 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Tag.findAll(); return Tag.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.products[0].addTag(results.tags[0], { through: { priority: 1 } }), results.products[0].addTag(results.tags[0], { through: { priority: 1 } }),
results.products[0].addTag(results.tags[1], { through: { priority: 2 } }), results.products[0].addTag(results.tags[1], { through: { priority: 2 } }),
results.products[1].addTag(results.tags[1], { through: { priority: 1 } }), 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[0], { through: { priority: 3 } }),
results.products[2].addTag(results.tags[1], { through: { priority: 1 } }), results.products[2].addTag(results.tags[1], { through: { priority: 1 } }),
results.products[2].addTag(results.tags[2], { through: { priority: 2 } }) results.products[2].addTag(results.tags[2], { through: { priority: 2 } })
); ]);
}).then(() => { }).then(() => {
return Product.findAll({ return Product.findAll({
include: [ include: [
...@@ -809,10 +795,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -809,10 +795,10 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.findAll(); return User.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.users[0].setGroup(results.groups[1]), results.users[0].setGroup(results.groups[1]),
results.users[1].setGroup(results.groups[0]) results.users[1].setGroup(results.groups[0])
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
...@@ -847,10 +833,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -847,10 +833,10 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.findAll(); return User.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.users[0].setGroup(results.groups[1]), results.users[0].setGroup(results.groups[1]),
results.users[1].setGroup(results.groups[0]) results.users[1].setGroup(results.groups[0])
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
...@@ -931,13 +917,13 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -931,13 +917,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Category.findAll(); return Category.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.users[0].setGroup(results.groups[1]), results.users[0].setGroup(results.groups[1]),
results.users[1].setGroup(results.groups[0]), results.users[1].setGroup(results.groups[0]),
Promise.all(results.groups.map(group => { Promise.all(results.groups.map(group => {
return group.setCategories(results.categories); return group.setCategories(results.categories);
})) }))
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
...@@ -984,13 +970,13 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -984,13 +970,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Category.findAll(); return Category.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.users[0].setTeam(results.groups[1]), results.users[0].setTeam(results.groups[1]),
results.users[1].setTeam(results.groups[0]), results.users[1].setTeam(results.groups[0]),
Promise.all(results.groups.map(group => { Promise.all(results.groups.map(group => {
return group.setTags(results.categories); return group.setTags(results.categories);
})) }))
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
...@@ -1037,13 +1023,13 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1037,13 +1023,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Category.findAll(); return Category.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.users[0].setGroup(results.groups[1]), results.users[0].setGroup(results.groups[1]),
results.users[1].setGroup(results.groups[0]), results.users[1].setGroup(results.groups[0]),
Promise.all(results.groups.map(group => { Promise.all(results.groups.map(group => {
return group.setCategories(results.categories); return group.setCategories(results.categories);
})) }))
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
...@@ -1083,10 +1069,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1083,10 +1069,10 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.findAll(); return User.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.users[1].setLeaderOf(results.projects[1]), results.users[1].setLeaderOf(results.projects[1]),
results.users[0].setLeaderOf(results.projects[0]) results.users[0].setLeaderOf(results.projects[0])
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
...@@ -1132,14 +1118,14 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1132,14 +1118,14 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Tag.findAll(); return Tag.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.products[0].addTag(results.tags[0], { priority: 1 }), results.products[0].addTag(results.tags[0], { priority: 1 }),
results.products[0].addTag(results.tags[1], { priority: 2 }), results.products[0].addTag(results.tags[1], { priority: 2 }),
results.products[1].addTag(results.tags[1], { priority: 1 }), results.products[1].addTag(results.tags[1], { priority: 1 }),
results.products[2].addTag(results.tags[0], { priority: 3 }), results.products[2].addTag(results.tags[0], { priority: 3 }),
results.products[2].addTag(results.tags[1], { priority: 1 }), results.products[2].addTag(results.tags[1], { priority: 1 }),
results.products[2].addTag(results.tags[2], { priority: 2 }) results.products[2].addTag(results.tags[2], { priority: 2 })
); ]);
}).then(() => { }).then(() => {
return Product.findAll({ return Product.findAll({
include: [ include: [
...@@ -1297,12 +1283,12 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1297,12 +1283,12 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return User.findAll(); return User.findAll();
}) })
}).then(results => { }).then(results => {
return Promise.join( return Promise.all([
results.users[0].setGroup(results.groups[0]), results.users[0].setGroup(results.groups[0]),
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])
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
...@@ -1639,12 +1625,12 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1639,12 +1625,12 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Category.belongsTo(Post); Category.belongsTo(Post);
return this.sequelize.sync({ force: true }).then(() => { 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 }),
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 Promise.all(posts.slice(1, 3).map(post => {
return post.createCategory({ slug: 'food' }); return post.createCategory({ slug: 'food' });
})); }));
...@@ -1779,18 +1765,18 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1779,18 +1765,18 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Company.hasMany(User); Company.hasMany(User);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
User.create({ lastName: 'Albertsen' }), User.create({ lastName: 'Albertsen' }),
User.create({ lastName: 'Zenith' }), User.create({ lastName: 'Zenith' }),
User.create({ lastName: 'Hansen' }), User.create({ lastName: 'Hansen' }),
Company.create({ rank: 1 }), Company.create({ rank: 1 }),
Company.create({ rank: 2 }) Company.create({ rank: 2 })
).then(([albertsen, zenith, hansen, company1, company2]) => { ]).then(([albertsen, zenith, hansen, company1, company2]) => {
return Promise.join( return Promise.all([
albertsen.setCompany(company1), albertsen.setCompany(company1),
zenith.setCompany(company2), zenith.setCompany(company2),
hansen.setCompany(company2) hansen.setCompany(company2)
); ]);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
......
...@@ -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([
Task.bulkCreate([
{ name: 'Important task', fk: 3 }, { name: 'Important task', fk: 3 },
{ name: 'Important task', fk: 4 }, { name: 'Important task', fk: 4 },
{ name: 'Important task', fk: 5 }, { name: 'Important task', fk: 5 },
{ name: 'Important task', fk: 6 } { name: 'Important task', fk: 6 }
]), ]), Employee.bulkCreate([
Employee.bulkCreate([
{ name: 'Jane Doe', fk: 1 }, { name: 'Jane Doe', fk: 1 },
{ name: 'John Doe', fk: 4 }, { name: 'John Doe', fk: 4 },
{ name: 'Jane John Doe', fk: 5 }, { name: 'Jane John Doe', fk: 5 },
{ name: 'John Jane Doe', fk: 6 } { name: 'John Jane Doe', fk: 6 }
]) ])]).then(() =>{
).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,15 +97,13 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -101,15 +97,13 @@ 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
SomeConnection.bulkCreate([ // Lets count, m: A and u: 1
{ u: 1, m: 'A', fk: 1 }, // 1 // Will be deleted { u: 1, m: 'A', fk: 1 }, // 1 // Will be deleted
{ u: 2, m: 'A', fk: 1 }, { u: 2, m: 'A', fk: 1 },
{ u: 3, m: 'A', fk: 1 }, { u: 3, m: 'A', fk: 1 },
...@@ -134,22 +128,18 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -134,22 +128,18 @@ describe(Support.getTestDialectTeaser('Include'), () => {
{ u: 2, m: 'B', fk: 2 }, { u: 2, m: 'B', fk: 2 },
{ u: 1, m: 'A', fk: 4 }, // 4 { u: 1, m: 'A', fk: 4 }, // 4
{ u: 4, m: 'A', fk: 2 } { u: 4, m: 'A', fk: 2 }
]), ]), A.bulkCreate([
A.bulkCreate([
{ name: 'Just' }, { name: 'Just' },
{ name: 'for' }, { name: 'for' },
{ name: 'testing' }, { name: 'testing' },
{ name: 'proposes' }, { name: 'proposes' },
{ name: 'only' } { name: 'only' }
]), ]), B.bulkCreate([
B.bulkCreate([
{ name: 'this should not' }, { name: 'this should not' },
{ name: 'be loaded' } { name: 'be loaded' }
]), ]), C.bulkCreate([
C.bulkCreate([
{ name: 'because we only want A' } { name: 'because we only want A' }
]) ])]).then(() => {
).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,9 +290,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -293,9 +290,7 @@ 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({}),
(function(singles) {
let promise = Promise.resolve(), let promise = Promise.resolve(),
previousInstance, previousInstance,
b; b;
...@@ -324,8 +319,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -324,8 +319,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
}); });
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({
......
...@@ -128,15 +128,15 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -128,15 +128,15 @@ describe(Support.getTestDialectTeaser('Include'), () => {
*/ */
it('supports many-to-many association with where clause', function() { it('supports many-to-many association with where clause', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.User.bulkCreate(build('Alice', 'Bob')) this.User.bulkCreate(build('Alice', 'Bob'))
)) ]))
.then(([projects, users]) => Promise.join( .then(([projects, users]) => Promise.all([
projects[0].addUser(users[0]), projects[0].addUser(users[0]),
projects[1].addUser(users[1]), projects[1].addUser(users[1]),
projects[2].addUser(users[0]) projects[2].addUser(users[0])
)) ]))
.then(() => this.Project.findAll({ .then(() => this.Project.findAll({
include: [{ include: [{
model: this.User, model: this.User,
...@@ -156,17 +156,17 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -156,17 +156,17 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports 2 levels of required many-to-many associations', function() { it('supports 2 levels of required many-to-many associations', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.User.bulkCreate(build('Alice', 'Bob')), this.User.bulkCreate(build('Alice', 'Bob')),
this.Hobby.bulkCreate(build('archery', 'badminton')) this.Hobby.bulkCreate(build('archery', 'badminton'))
)) ]))
.then(([projects, users, hobbies]) => Promise.join( .then(([projects, users, hobbies]) => Promise.all([
projects[0].addUser(users[0]), projects[0].addUser(users[0]),
projects[1].addUser(users[1]), projects[1].addUser(users[1]),
projects[2].addUser(users[0]), projects[2].addUser(users[0]),
users[0].addHobby(hobbies[0]) users[0].addHobby(hobbies[0])
)) ]))
.then(() => this.Project.findAll({ .then(() => this.Project.findAll({
include: [{ include: [{
model: this.User, model: this.User,
...@@ -188,18 +188,18 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -188,18 +188,18 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports 2 levels of required many-to-many associations with where clause', function() { it('supports 2 levels of required many-to-many associations with where clause', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.User.bulkCreate(build('Alice', 'Bob')), this.User.bulkCreate(build('Alice', 'Bob')),
this.Hobby.bulkCreate(build('archery', 'badminton')) this.Hobby.bulkCreate(build('archery', 'badminton'))
)) ]))
.then(([projects, users, hobbies]) => Promise.join( .then(([projects, users, hobbies]) => Promise.all([
projects[0].addUser(users[0]), projects[0].addUser(users[0]),
projects[1].addUser(users[1]), projects[1].addUser(users[1]),
projects[2].addUser(users[0]), projects[2].addUser(users[0]),
users[0].addHobby(hobbies[0]), users[0].addHobby(hobbies[0]),
users[1].addHobby(hobbies[1]) users[1].addHobby(hobbies[1])
)) ]))
.then(() => this.Project.findAll({ .then(() => this.Project.findAll({
include: [{ include: [{
model: this.User, model: this.User,
...@@ -223,18 +223,18 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -223,18 +223,18 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports 2 levels of required many-to-many associations with through.where clause', function() { it('supports 2 levels of required many-to-many associations with through.where clause', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.User.bulkCreate(build('Alice', 'Bob')), this.User.bulkCreate(build('Alice', 'Bob')),
this.Hobby.bulkCreate(build('archery', 'badminton')) this.Hobby.bulkCreate(build('archery', 'badminton'))
)) ]))
.then(([projects, users, hobbies]) => Promise.join( .then(([projects, users, hobbies]) => Promise.all([
projects[0].addUser(users[0]), projects[0].addUser(users[0]),
projects[1].addUser(users[1]), projects[1].addUser(users[1]),
projects[2].addUser(users[0]), projects[2].addUser(users[0]),
users[0].addHobby(hobbies[0]), users[0].addHobby(hobbies[0]),
users[1].addHobby(hobbies[1]) users[1].addHobby(hobbies[1])
)) ]))
.then(() => this.Project.findAll({ .then(() => this.Project.findAll({
include: [{ include: [{
model: this.User, model: this.User,
...@@ -261,13 +261,13 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -261,13 +261,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports 3 levels of required many-to-many associations with where clause', function() { it('supports 3 levels of required many-to-many associations with where clause', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Task.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Task.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte')), this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte')),
this.Hobby.bulkCreate(build('archery', 'badminton')) this.Hobby.bulkCreate(build('archery', 'badminton'))
)) ]))
.then(([tasks, projects, users, hobbies]) => Promise.join( .then(([tasks, projects, users, hobbies]) => Promise.all([
tasks[0].addProject(projects[0]), tasks[0].addProject(projects[0]),
tasks[1].addProject(projects[1]), tasks[1].addProject(projects[1]),
tasks[2].addProject(projects[2]), tasks[2].addProject(projects[2]),
...@@ -276,7 +276,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -276,7 +276,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
projects[2].addUser(users[0]), projects[2].addUser(users[0]),
users[0].addHobby(hobbies[0]), users[0].addHobby(hobbies[0]),
users[1].addHobby(hobbies[1]) users[1].addHobby(hobbies[1])
)) ]))
.then(() => this.Task.findAll({ .then(() => this.Task.findAll({
include: [{ include: [{
model: this.Project, model: this.Project,
...@@ -304,14 +304,13 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -304,14 +304,13 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports required many-to-many association', function() { it('supports required many-to-many association', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Project.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.User.bulkCreate(build('Alice', 'Bob')) this.User.bulkCreate(build('Alice', 'Bob'))
)) ]))
.then(([projects, users]) => Promise.join( .then(([projects, users]) => Promise.all([// alpha
projects[0].addUser(users[0]), // alpha projects[0].addUser(users[0]), // charlie
projects[2].addUser(users[0]) // charlie projects[2].addUser(users[0])]))
))
.then(() => this.Project.findAll({ .then(() => this.Project.findAll({
include: [{ include: [{
model: this.User, model: this.User,
...@@ -329,19 +328,19 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -329,19 +328,19 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports 2 required many-to-many association', function() { it('supports 2 required many-to-many association', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Project.bulkCreate(build('alpha', 'bravo', 'charlie', 'delta')), this.Project.bulkCreate(build('alpha', 'bravo', 'charlie', 'delta')),
this.User.bulkCreate(build('Alice', 'Bob', 'David')), this.User.bulkCreate(build('Alice', 'Bob', 'David')),
this.Task.bulkCreate(build('a', 'c', 'd')) this.Task.bulkCreate(build('a', 'c', 'd'))
)) ]))
.then(([projects, users, tasks]) => Promise.join( .then(([projects, users, tasks]) => Promise.all([
projects[0].addUser(users[0]), projects[0].addUser(users[0]),
projects[0].addTask(tasks[0]), projects[0].addTask(tasks[0]),
projects[1].addUser(users[1]), projects[1].addUser(users[1]),
projects[2].addTask(tasks[1]), projects[2].addTask(tasks[1]),
projects[3].addUser(users[2]), projects[3].addUser(users[2]),
projects[3].addTask(tasks[2]) projects[3].addTask(tasks[2])
)) ]))
.then(() => this.Project.findAll({ .then(() => this.Project.findAll({
include: [{ include: [{
model: this.User, model: this.User,
...@@ -365,14 +364,11 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -365,14 +364,11 @@ describe(Support.getTestDialectTeaser('Include'), () => {
*/ */
it('supports required one-to-many association', function() { it('supports required one-to-many association', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Post.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Post.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.Comment.bulkCreate(build('comment0', 'comment1')) this.Comment.bulkCreate(build('comment0', 'comment1'))
)) ]))
.then(([posts, comments]) => Promise.join( .then(([posts, comments]) => Promise.all([posts[0].addComment(comments[0]), posts[2].addComment(comments[1])]))
posts[0].addComment(comments[0]),
posts[2].addComment(comments[1])
))
.then(() => this.Post.findAll({ .then(() => this.Post.findAll({
include: [{ include: [{
model: this.Comment, model: this.Comment,
...@@ -390,15 +386,15 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -390,15 +386,15 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports required one-to-many association with where clause', function() { it('supports required one-to-many association with where clause', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Post.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Post.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2')) this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2'))
)) ]))
.then(([posts, comments]) => Promise.join( .then(([posts, comments]) => Promise.all([
posts[0].addComment(comments[0]), posts[0].addComment(comments[0]),
posts[1].addComment(comments[1]), posts[1].addComment(comments[1]),
posts[2].addComment(comments[2]) posts[2].addComment(comments[2])
)) ]))
.then(() => this.Post.findAll({ .then(() => this.Post.findAll({
include: [{ include: [{
model: this.Comment, model: this.Comment,
...@@ -423,15 +419,15 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -423,15 +419,15 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports required one-to-many association with where clause (findOne)', function() { it('supports required one-to-many association with where clause (findOne)', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Post.bulkCreate(build('alpha', 'bravo', 'charlie')), this.Post.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2')) this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2'))
)) ]))
.then(([posts, comments]) => Promise.join( .then(([posts, comments]) => Promise.all([
posts[0].addComment(comments[0]), posts[0].addComment(comments[0]),
posts[1].addComment(comments[1]), posts[1].addComment(comments[1]),
posts[2].addComment(comments[2]) posts[2].addComment(comments[2])
)) ]))
.then(() => this.Post.findOne({ .then(() => this.Post.findOne({
include: [{ include: [{
model: this.Comment, model: this.Comment,
...@@ -448,18 +444,18 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -448,18 +444,18 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports 2 levels of required one-to-many associations', function() { it('supports 2 levels of required one-to-many associations', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte', 'David')), this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte', 'David')),
this.Post.bulkCreate(build('post0', 'post1', 'post2')), this.Post.bulkCreate(build('post0', 'post1', 'post2')),
this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2')) this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2'))
)) ]))
.then(([users, posts, comments]) => Promise.join( .then(([users, posts, comments]) => Promise.all([
users[0].addPost(posts[0]), users[0].addPost(posts[0]),
users[1].addPost(posts[1]), users[1].addPost(posts[1]),
users[3].addPost(posts[2]), users[3].addPost(posts[2]),
posts[0].addComment(comments[0]), posts[0].addComment(comments[0]),
posts[2].addComment(comments[2]) posts[2].addComment(comments[2])
)) ]))
.then(() => this.User.findAll({ .then(() => this.User.findAll({
include: [{ include: [{
model: this.Post, model: this.Post,
...@@ -484,19 +480,18 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -484,19 +480,18 @@ describe(Support.getTestDialectTeaser('Include'), () => {
*/ */
it('supports required one-to-many association with nested required many-to-many association', function() { it('supports required one-to-many association with nested required many-to-many association', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte', 'David')), this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte', 'David')),
this.Post.bulkCreate(build('alpha', 'charlie', 'delta')), this.Post.bulkCreate(build('alpha', 'charlie', 'delta')),
this.Tag.bulkCreate(build('atag', 'btag', 'dtag')) this.Tag.bulkCreate(build('atag', 'btag', 'dtag'))
)) ]))
.then(([users, posts, tags]) => Promise.join( .then(([users, posts, tags]) => Promise.all([
users[0].addPost(posts[0]), users[0].addPost(posts[0]),
users[2].addPost(posts[1]), users[2].addPost(posts[1]),
users[3].addPost(posts[2]), users[3].addPost(posts[2]),
posts[0].addTag([tags[0]]), posts[0].addTag([tags[0]]),
posts[2].addTag([tags[2]]) posts[2].addTag([tags[2]])
)) ]))
.then(() => this.User.findAll({ .then(() => this.User.findAll({
include: [{ include: [{
model: this.Post, model: this.Post,
...@@ -518,19 +513,18 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -518,19 +513,18 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports required many-to-many association with nested required one-to-many association', function() { it('supports required many-to-many association with nested required one-to-many association', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Project.bulkCreate(build('alpha', 'bravo', 'charlie', 'delta')), this.Project.bulkCreate(build('alpha', 'bravo', 'charlie', 'delta')),
this.User.bulkCreate(build('Alice', 'Bob', 'David')), this.User.bulkCreate(build('Alice', 'Bob', 'David')),
this.Post.bulkCreate(build('post0', 'post1', 'post2')) this.Post.bulkCreate(build('post0', 'post1', 'post2'))
)) ]))
.then(([projects, users, posts]) => Promise.join( .then(([projects, users, posts]) => Promise.all([
projects[0].addUser(users[0]), projects[0].addUser(users[0]),
projects[1].addUser(users[1]), projects[1].addUser(users[1]),
projects[3].addUser(users[2]), projects[3].addUser(users[2]),
users[0].addPost([posts[0]]), users[0].addPost([posts[0]]),
users[2].addPost([posts[2]]) users[2].addPost([posts[2]])
)) ]))
.then(() => this.Project.findAll({ .then(() => this.Project.findAll({
include: [{ include: [{
model: this.User, model: this.User,
...@@ -553,20 +547,19 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -553,20 +547,19 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports required many-to-one association with nested many-to-many association with where clause', function() { it('supports required many-to-one association with nested many-to-many association with where clause', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Post.bulkCreate(build('post0', 'post1', 'post2', 'post3')), this.Post.bulkCreate(build('post0', 'post1', 'post2', 'post3')),
this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte', 'David')), this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte', 'David')),
this.Hobby.bulkCreate(build('archery', 'badminton')) this.Hobby.bulkCreate(build('archery', 'badminton'))
)) ]))
.then(([posts, users, hobbies]) => Promise.join( .then(([posts, users, hobbies]) => Promise.all([
posts[0].setUser(users[0]), posts[0].setUser(users[0]),
posts[1].setUser(users[1]), posts[1].setUser(users[1]),
posts[3].setUser(users[3]), posts[3].setUser(users[3]),
users[0].addHobby(hobbies[0]), users[0].addHobby(hobbies[0]),
users[1].addHobby(hobbies[1]), users[1].addHobby(hobbies[1]),
users[3].addHobby(hobbies[0]) users[3].addHobby(hobbies[0])
)) ]))
.then(() => this.Post.findAll({ .then(() => this.Post.findAll({
include: [{ include: [{
model: this.User, model: this.User,
...@@ -590,20 +583,19 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -590,20 +583,19 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports required many-to-one association with nested many-to-many association with through.where clause', function() { it('supports required many-to-one association with nested many-to-many association with through.where clause', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Post.bulkCreate(build('post0', 'post1', 'post2', 'post3')), this.Post.bulkCreate(build('post0', 'post1', 'post2', 'post3')),
this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte', 'David')), this.User.bulkCreate(build('Alice', 'Bob', 'Charlotte', 'David')),
this.Hobby.bulkCreate(build('archery', 'badminton')) this.Hobby.bulkCreate(build('archery', 'badminton'))
)) ]))
.then(([posts, users, hobbies]) => Promise.join( .then(([posts, users, hobbies]) => Promise.all([
posts[0].setUser(users[0]), posts[0].setUser(users[0]),
posts[1].setUser(users[1]), posts[1].setUser(users[1]),
posts[3].setUser(users[3]), posts[3].setUser(users[3]),
users[0].addHobby(hobbies[0]), users[0].addHobby(hobbies[0]),
users[1].addHobby(hobbies[1]), users[1].addHobby(hobbies[1]),
users[3].addHobby(hobbies[0]) users[3].addHobby(hobbies[0])
)) ]))
.then(() => this.Post.findAll({ .then(() => this.Post.findAll({
include: [{ include: [{
model: this.User, model: this.User,
...@@ -630,30 +622,27 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -630,30 +622,27 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports required many-to-one association with multiple nested associations with where clause', function() { it('supports required many-to-one association with multiple nested associations with where clause', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2', 'comment3', 'comment4', 'comment5')), this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2', 'comment3', 'comment4', 'comment5')),
this.Post.bulkCreate(build('post0', 'post1', 'post2', 'post3', 'post4')), this.Post.bulkCreate(build('post0', 'post1', 'post2', 'post3', 'post4')),
this.User.bulkCreate(build('Alice', 'Bob')), this.User.bulkCreate(build('Alice', 'Bob')),
this.Tag.bulkCreate(build('tag0', 'tag1')) this.Tag.bulkCreate(build('tag0', 'tag1'))
)) ]))
.then(([comments, posts, users, tags]) => Promise.join( .then(([comments, posts, users, tags]) => Promise.all([
comments[0].setPost(posts[0]), comments[0].setPost(posts[0]),
comments[1].setPost(posts[1]), comments[1].setPost(posts[1]),
comments[3].setPost(posts[2]), comments[3].setPost(posts[2]),
comments[4].setPost(posts[3]), comments[4].setPost(posts[3]),
comments[5].setPost(posts[4]), comments[5].setPost(posts[4]),
posts[0].addTag(tags[0]), posts[0].addTag(tags[0]),
posts[3].addTag(tags[0]), posts[3].addTag(tags[0]),
posts[4].addTag(tags[0]), posts[4].addTag(tags[0]),
posts[1].addTag(tags[1]), posts[1].addTag(tags[1]),
posts[0].setUser(users[0]), posts[0].setUser(users[0]),
posts[2].setUser(users[0]), posts[2].setUser(users[0]),
posts[4].setUser(users[0]), posts[4].setUser(users[0]),
posts[1].setUser(users[1]) posts[1].setUser(users[1])
)) ]))
.then(() => this.Comment.findAll({ .then(() => this.Comment.findAll({
include: [{ include: [{
model: this.Post, model: this.Post,
...@@ -682,20 +671,19 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -682,20 +671,19 @@ describe(Support.getTestDialectTeaser('Include'), () => {
it('supports required many-to-one association with nested one-to-many association with where clause', function() { it('supports required many-to-one association with nested one-to-many association with where clause', function() {
return this.sequelize.sync({ force: true }) return this.sequelize.sync({ force: true })
.then(() => Promise.join( .then(() => Promise.all([
this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2')), this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2')),
this.Post.bulkCreate(build('post0', 'post1', 'post2')), this.Post.bulkCreate(build('post0', 'post1', 'post2')),
this.Footnote.bulkCreate(build('footnote0', 'footnote1', 'footnote2')) this.Footnote.bulkCreate(build('footnote0', 'footnote1', 'footnote2'))
)) ]))
.then(([comments, posts, footnotes]) => Promise.join( .then(([comments, posts, footnotes]) => Promise.all([
comments[0].setPost(posts[0]), comments[0].setPost(posts[0]),
comments[1].setPost(posts[1]), comments[1].setPost(posts[1]),
comments[2].setPost(posts[2]), comments[2].setPost(posts[2]),
posts[0].addFootnote(footnotes[0]), posts[0].addFootnote(footnotes[0]),
posts[1].addFootnote(footnotes[1]), posts[1].addFootnote(footnotes[1]),
posts[2].addFootnote(footnotes[2]) posts[2].addFootnote(footnotes[2])
)) ]))
.then(() => this.Comment.findAll({ .then(() => this.Comment.findAll({
include: [{ include: [{
model: this.Post, model: this.Post,
......
...@@ -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,8 +21,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -21,8 +21,7 @@ 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: [
{}, {},
...@@ -31,16 +30,14 @@ if (current.dialect.supports.groupedLimit) { ...@@ -31,16 +30,14 @@ if (current.dialect.supports.groupedLimit) {
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
}), }), User.create({
User.create({
id: 2, id: 2,
tasks: [ tasks: [
{} {}
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
}) })]).then(() => {
).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Tasks, separate: true } { association: User.Tasks, separate: true }
...@@ -193,8 +190,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -193,8 +190,7 @@ 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: [
{}, {},
...@@ -203,8 +199,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -203,8 +199,7 @@ if (current.dialect.supports.groupedLimit) {
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
}), }), User.create({
User.create({
id: 2, id: 2,
tasks: [ tasks: [
{}, {},
...@@ -214,8 +209,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -214,8 +209,7 @@ if (current.dialect.supports.groupedLimit) {
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
}) })]).then(() => {
).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Tasks, limit: 2 } { association: User.Tasks, limit: 2 }
...@@ -245,8 +239,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -245,8 +239,7 @@ 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: [
...@@ -259,8 +252,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -259,8 +252,7 @@ if (current.dialect.supports.groupedLimit) {
include: [ include: [
{ association: User.Company, include: [Company.Tasks] } { association: User.Company, include: [Company.Tasks] }
] ]
}), }), User.create({
User.create({
id: 2, id: 2,
company: { company: {
tasks: [ tasks: [
...@@ -271,8 +263,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -271,8 +263,7 @@ if (current.dialect.supports.groupedLimit) {
include: [ include: [
{ association: User.Company, include: [Company.Tasks] } { association: User.Company, include: [Company.Tasks] }
] ]
}) })]).then(() => {
).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Company, include: [ { association: User.Company, include: [
...@@ -306,8 +297,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -306,8 +297,7 @@ 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: [
{ {
...@@ -326,8 +316,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -326,8 +316,7 @@ if (current.dialect.supports.groupedLimit) {
] } ] }
] } ] }
] ]
}) })]).then(() => {
).then(() => {
return Company.findAll({ return Company.findAll({
include: [ include: [
{ association: Company.Users, include: [ { association: Company.Users, include: [
...@@ -359,8 +348,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -359,8 +348,7 @@ 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: [
{ {
...@@ -382,8 +370,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -382,8 +370,7 @@ if (current.dialect.supports.groupedLimit) {
include: [ include: [
{ association: User.Projects, include: [Project.Tasks] } { association: User.Projects, include: [Project.Tasks] }
] ]
}), }), User.create({
User.create({
id: 2, id: 2,
projects: [ projects: [
{ {
...@@ -398,8 +385,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -398,8 +385,7 @@ if (current.dialect.supports.groupedLimit) {
include: [ include: [
{ association: User.Projects, include: [Project.Tasks] } { 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,8 +431,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -445,8 +431,7 @@ 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' },
...@@ -456,8 +441,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -456,8 +441,7 @@ if (current.dialect.supports.groupedLimit) {
] ]
}, { }, {
include: [User.Tasks] include: [User.Tasks]
}), }), User.create({
User.create({
id: 2, id: 2,
tasks: [ tasks: [
{ id: 5, title: 'a' }, { id: 5, title: 'a' },
...@@ -466,8 +450,7 @@ if (current.dialect.supports.groupedLimit) { ...@@ -466,8 +450,7 @@ if (current.dialect.supports.groupedLimit) {
] ]
}, { }, {
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({
this.Task.create({
user_id: userId user_id: userId
}) })]).then(([user, task]) => {
).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,10 +432,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -432,10 +432,10 @@ 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 }),
(first, second) => { this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction })
]).then(([first, second]) => {
const firstInstance = first[0], const firstInstance = first[0],
firstCreated = first[1], firstCreated = first[1],
secondInstance = second[0], secondInstance = second[0],
...@@ -450,8 +450,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -450,8 +450,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(firstInstance.id).to.equal(secondInstance.id); expect(firstInstance.id).to.equal(secondInstance.id);
return transaction.commit(); return transaction.commit();
} });
);
}); });
}); });
} }
...@@ -512,8 +511,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -512,8 +511,7 @@ 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'
}, },
...@@ -525,8 +523,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -525,8 +523,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}).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({
User.findOrCreate({
where: { where: {
objectId: 'asdasdasd' objectId: 'asdasdasd'
}, },
...@@ -538,17 +535,16 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -538,17 +535,16 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}).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;
}) })]);
);
}); });
}); });
// 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' } }),
(first, second) => { this.User.findOrCreate({ where: { uniqueName: 'winner' } })
]).then(([first, second]) => {
const firstInstance = first[0], const firstInstance = first[0],
firstCreated = first[1], firstCreated = first[1],
secondInstance = second[0], secondInstance = second[0],
...@@ -561,19 +557,18 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -561,19 +557,18 @@ describe(Support.getTestDialectTeaser('Model'), () => {
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' } }),
(first, second, third) => { this.User.findOrCreate({ where: { uniqueName: 'winner' } })
]).then(([first, second, third]) => {
const firstInstance = first[0], const firstInstance = first[0],
firstCreated = first[1], firstCreated = first[1],
secondInstance = second[0], secondInstance = second[0],
...@@ -591,8 +586,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -591,8 +586,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
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' }),
Log.bulkCreate([
{ level: 'error' }, { level: 'error' },
{ level: 'debug' } { 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))
); ]);
}); });
}); });
......
...@@ -210,8 +210,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -210,8 +210,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
describe('find', () => { describe('find', () => {
it('should be possible to query a nested value', function() { it('should be possible to query a nested value', function() {
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Homer', first: 'Homer',
...@@ -219,8 +218,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -219,8 +218,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'Nuclear Safety Inspector' employment: 'Nuclear Safety Inspector'
} }
}), }), this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Marge', first: 'Marge',
...@@ -228,8 +226,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -228,8 +226,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'Housewife' employment: 'Housewife'
} }
}) })]).then(() => {
).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
data: { data: {
...@@ -255,14 +252,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -255,14 +252,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const now = moment().milliseconds(0).toDate(); const now = moment().milliseconds(0).toDate();
const before = moment().milliseconds(0).subtract(1, 'day').toDate(); const before = moment().milliseconds(0).subtract(1, 'day').toDate();
const after = moment().milliseconds(0).add(1, 'day').toDate(); const after = moment().milliseconds(0).add(1, 'day').toDate();
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
json: { json: {
user: 'Homer', user: 'Homer',
lastLogin: now lastLogin: now
} }
}) })]).then(() => {
).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
json: { json: {
...@@ -298,14 +293,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -298,14 +293,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be possible to query a boolean with array operators', function() { it('should be possible to query a boolean with array operators', function() {
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
json: { json: {
user: 'Homer', user: 'Homer',
active: true active: true
} }
}) })]).then(() => {
).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
json: { json: {
...@@ -341,8 +334,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -341,8 +334,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be possible to query a nested integer value', function() { it('should be possible to query a nested integer value', function() {
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Homer', first: 'Homer',
...@@ -350,8 +342,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -350,8 +342,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
age: 40 age: 40
} }
}), }), this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Marge', first: 'Marge',
...@@ -359,8 +350,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -359,8 +350,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
age: 37 age: 37
} }
}) })]).then(() => {
).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
data: { data: {
...@@ -385,8 +375,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -385,8 +375,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be possible to query a nested null value', function() { it('should be possible to query a nested null value', function() {
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Homer', first: 'Homer',
...@@ -394,8 +383,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -394,8 +383,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'Nuclear Safety Inspector' employment: 'Nuclear Safety Inspector'
} }
}), }), this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Marge', first: 'Marge',
...@@ -403,8 +391,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -403,8 +391,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: null employment: null
} }
}) })]).then(() => {
).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
data: { data: {
...@@ -425,8 +412,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -425,8 +412,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
it('should be possible to query for nested fields with hyphens/dashes, #8718', function() { it('should be possible to query for nested fields with hyphens/dashes, #8718', function() {
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Homer', first: 'Homer',
...@@ -439,8 +425,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -439,8 +425,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'Nuclear Safety Inspector' employment: 'Nuclear Safety Inspector'
} }
}), }), this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Marge', first: 'Marge',
...@@ -448,8 +433,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -448,8 +433,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: null employment: null
} }
}) })]).then(() => {
).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
data: { data: {
...@@ -488,8 +472,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -488,8 +472,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
employment: 'Nuclear Safety Inspector' employment: 'Nuclear Safety Inspector'
} }
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Marge', first: 'Marge',
...@@ -497,8 +480,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -497,8 +480,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'Housewife' employment: 'Housewife'
} }
}), }), this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Bart', first: 'Bart',
...@@ -506,8 +488,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -506,8 +488,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'None' employment: 'None'
} }
}) })]);
);
}).then(() => { }).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
...@@ -555,8 +536,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -555,8 +536,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
employment: 'Nuclear Safety Inspector' employment: 'Nuclear Safety Inspector'
} }
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Marge', first: 'Marge',
...@@ -564,8 +544,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -564,8 +544,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'Housewife' employment: 'Housewife'
} }
}), }), this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Bart', first: 'Bart',
...@@ -573,8 +552,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -573,8 +552,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'None' employment: 'None'
} }
}) })]);
);
}).then(() => { }).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
...@@ -628,8 +606,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -628,8 +606,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
} }
}; };
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Elliot', first: 'Elliot',
...@@ -637,8 +614,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -637,8 +614,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'Hacker' employment: 'Hacker'
} }
}), }), this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Christian', first: 'Christian',
...@@ -646,8 +622,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -646,8 +622,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'Hacker' employment: 'Hacker'
} }
}), }), this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: ' Tyrell', first: ' Tyrell',
...@@ -655,8 +630,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -655,8 +630,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'CTO' employment: 'CTO'
} }
}) })]).then(() => {
).then(() => {
return expect(this.Event.findAll(conditionSearch)).to.eventually.have.length(2); return expect(this.Event.findAll(conditionSearch)).to.eventually.have.length(2);
}).then(() => { }).then(() => {
return this.Event.destroy(conditionSearch); return this.Event.destroy(conditionSearch);
...@@ -753,8 +727,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -753,8 +727,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
employment: 'Nuclear Safety Inspector' employment: 'Nuclear Safety Inspector'
} }
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Marge', first: 'Marge',
...@@ -762,8 +735,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -762,8 +735,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'Housewife' employment: 'Housewife'
} }
}), }), this.Event.create({
this.Event.create({
data: { data: {
name: { name: {
first: 'Bart', first: 'Bart',
...@@ -771,8 +743,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -771,8 +743,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
employment: 'None' employment: 'None'
} }
}) })]);
);
}).then(() => { }).then(() => {
if (current.options.dialect === 'sqlite') { if (current.options.dialect === 'sqlite') {
return this.Event.findAll({ return this.Event.findAll({
......
...@@ -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,8 +610,7 @@ if (current.dialect.supports.transactions) { ...@@ -612,8 +610,7 @@ 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'
}, },
...@@ -624,9 +621,7 @@ if (current.dialect.supports.transactions) { ...@@ -624,9 +621,7 @@ if (current.dialect.supports.transactions) {
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({
t1Jan.update({
awesome: true awesome: true
}, { }, {
transaction: t1 transaction: t1
...@@ -635,8 +630,7 @@ if (current.dialect.supports.transactions) { ...@@ -635,8 +630,7 @@ if (current.dialect.supports.transactions) {
return delay(2000).then(() => { return delay(2000).then(() => {
return t1.commit(); return t1.commit();
}); });
}) })]);
);
}); });
}); });
}); });
...@@ -695,10 +689,10 @@ if (current.dialect.supports.transactions) { ...@@ -695,10 +689,10 @@ 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(() => {
...@@ -738,11 +732,11 @@ if (current.dialect.supports.transactions) { ...@@ -738,11 +732,11 @@ 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(() => {
...@@ -801,8 +795,7 @@ if (current.dialect.supports.transactions) { ...@@ -801,8 +795,7 @@ 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'
}, },
...@@ -811,8 +804,7 @@ if (current.dialect.supports.transactions) { ...@@ -811,8 +804,7 @@ if (current.dialect.supports.transactions) {
}).then(() => { }).then(() => {
t2Spy(); t2Spy();
return t2.commit(); return t2.commit();
}), }), t1Jan.update({
t1Jan.update({
awesome: true awesome: true
}, { }, {
transaction: t1 transaction: t1
...@@ -822,8 +814,7 @@ if (current.dialect.supports.transactions) { ...@@ -822,8 +814,7 @@ if (current.dialect.supports.transactions) {
expect(t1Spy).to.have.been.calledAfter(t2Spy); expect(t1Spy).to.have.been.calledAfter(t2Spy);
return t1.commit(); return t1.commit();
}); });
}) })]);
);
}); });
}); });
}); });
...@@ -854,8 +845,7 @@ if (current.dialect.supports.transactions) { ...@@ -854,8 +845,7 @@ 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'
}, },
...@@ -873,9 +863,7 @@ if (current.dialect.supports.transactions) { ...@@ -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 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 awesome: true
}, { }, {
transaction: t1 transaction: t1
...@@ -884,8 +872,7 @@ if (current.dialect.supports.transactions) { ...@@ -884,8 +872,7 @@ if (current.dialect.supports.transactions) {
t1Spy(); t1Spy();
return t1.commit(); 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, })).not.to.be.rejected, expect(User.create({
expect(User.create({
number: '2321312301230128391820e+219' number: '2321312301230128391820e+219'
})).not.to.be.rejected, })).not.to.be.rejected, expect(User.create({
expect(User.create({
number: '2321312301230128391820f219' number: '2321312301230128391820f219'
})).to.be.rejected })).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!