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

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({
}), include: [Group]
User.findAll({ })]);
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({
}), include: [User]
Group.findAll({ })]);
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({
}), include: [User]
Group.findAll({ })]);
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({
}), include: [User]
Group.findAll({ })]);
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({
}), include: [User]
Group.findAll({ })]);
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({
}), include: [User]
Group.findAll({ })]);
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({
}), include: [User]
Group.findAll({ })]);
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({
}), include: [
User.findAll({ { model: Company, include: [Group] }
include: [ ]
{ model: Company, include: [Group] } }), User.findOne({
] where: {},
}), include: [
User.findOne({ { model: Company, required: true, include: [Group] }
where: {}, ]
include: [ }), User.findAll({
{ model: Company, required: true, include: [Group] } include: [
] { model: Company, required: true, include: [Group] }
}), ]
User.findAll({ })]);
include: [
{ 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, logging: spy
user.getProjects({ })]);
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({
}), id: 2,
Task.create({ user: { id: 2 }
id: 2, }, {
user: { id: 2 } include: [Task.User]
}, { }), Task.create({
include: [Task.User] id: 3
}), })]);
Task.create({
id: 3
})
);
}).then(tasks => { }).then(tasks => {
return Task.User.get(tasks).then(result => { return Task.User.get(tasks).then(result => {
expect(result[tasks[0].id].id).to.equal(tasks[0].user.id); expect(result[tasks[0].id].id).to.equal(tasks[0].user.id);
...@@ -366,10 +362,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { ...@@ -366,10 +362,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
Comment.belongsTo(Post, { foreignKey: 'post_id' }); Comment.belongsTo(Post, { foreignKey: 'post_id' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Post.create(), Comment.create()]).then(async ([post, comment]) => {
Post.create(),
Comment.create()
).then(async ([post, comment]) => {
expect(comment.get('post_id')).not.to.be.ok; expect(comment.get('post_id')).not.to.be.ok;
const setter = await comment.setPost(post, { save: false }); const setter = await comment.setPost(post, { save: false });
...@@ -1029,9 +1022,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { ...@@ -1029,9 +1022,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
it('should load with an alias', function() { it('should load with an alias', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Individual.create({ name: 'Foo Bar' }), this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' })); this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => { }).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat); return individual.setPersonwearinghat(hat);
}).then(() => { }).then(() => {
...@@ -1058,9 +1052,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { ...@@ -1058,9 +1052,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
it('should load all', function() { it('should load all', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Individual.create({ name: 'Foo Bar' }), this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' })); this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => { }).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat); return individual.setPersonwearinghat(hat);
}).then(() => { }).then(() => {
......
...@@ -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,29 +75,25 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -75,29 +75,25 @@ 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: [ {},
{}, {},
{}, {}
{} ]
] }, {
}, { include: [User.Tasks]
include: [User.Tasks] }), User.create({
}), id: 2,
User.create({ tasks: [
id: 2, {}
tasks: [ ]
{} }, {
] include: [User.Tasks]
}, { }), User.create({
include: [User.Tasks] id: 3
}), })]);
User.create({
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,27 +112,24 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -116,27 +112,24 @@ 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' }, { title: 'c' },
{ title: 'c' }, { title: 'a' }
{ title: 'a' } ]
] }, {
}, { include: [User.Tasks]
include: [User.Tasks] }), User.create({
}), tasks: [
User.create({ { title: 'a' },
tasks: [ { title: 'c' },
{ title: 'a' }, { title: 'b' }
{ title: 'c' }, ]
{ title: 'b' } }, {
] 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,49 +161,46 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -168,49 +161,46 @@ 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: [ { title: 'c' },
{ title: 'c' }, { title: 'a' }
{ title: 'a' } ] },
] }, { title: 'd' },
{ title: 'd' }, { title: 'c', subtasks: [
{ title: 'c', subtasks: [ { title: 'b' },
{ title: 'b' }, { title: 'a' },
{ title: 'a' }, { title: 'c' }
{ title: 'c' } ] },
] }, { title: 'a', subtasks: [
{ title: 'a', subtasks: [ { title: 'c' },
{ title: 'c' }, { title: 'a' },
{ title: 'a' }, { title: 'b' }
{ title: 'b' } ] }
] } ]
] }, {
}, { include: [{ association: User.Tasks, include: [Task.SubTasks] }]
include: [{ association: User.Tasks, include: [Task.SubTasks] }] }), User.create({
}), id: 2,
User.create({ tasks: [
id: 2, { title: 'a', subtasks: [
tasks: [ { title: 'b' },
{ title: 'a', subtasks: [ { title: 'a' },
{ title: 'b' }, { title: 'c' }
{ title: 'a' }, ] },
{ title: 'c' } { title: 'c', subtasks: [
] }, { title: 'a' }
{ title: 'c', subtasks: [ ] },
{ title: 'a' } { title: 'b', subtasks: [
] }, { title: 'a' },
{ title: 'b', subtasks: [ { title: 'b' }
{ title: 'a' }, ] }
{ title: 'b' } ]
] } }, {
] 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,27 +265,24 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -275,27 +265,24 @@ 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: {} }, { title: 'c', category: {} },
{ title: 'c', category: {} }, { title: 'a', category: {} }
{ title: 'a', category: {} } ]
] }, {
}, { include: [{ association: User.Tasks, include: [Task.Category] }]
include: [{ association: User.Tasks, include: [Task.Category] }] }), User.create({
}), tasks: [
User.create({ { title: 'a', category: {} },
tasks: [ { title: 'c', category: {} },
{ title: 'a', category: {} }, { title: 'b', category: {} }
{ title: 'c', category: {} }, ]
{ title: 'b', category: {} } }, {
] 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,49 +327,46 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -340,49 +327,46 @@ 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: [ { title: 'c' },
{ title: 'c' }, { title: 'a' }
{ title: 'a' } ] },
] }, { title: 'd' },
{ title: 'd' }, { title: 'c', subtasks: [
{ title: 'c', subtasks: [ { title: 'b' },
{ title: 'b' }, { title: 'a' },
{ title: 'a' }, { title: 'c' }
{ title: 'c' } ] },
] }, { title: 'a', subtasks: [
{ title: 'a', subtasks: [ { title: 'c' },
{ title: 'c' }, { title: 'a' },
{ title: 'a' }, { title: 'b' }
{ title: 'b' } ] }
] } ]
] }, {
}, { include: [{ association: User.Tasks, include: [Task.SubTasks] }]
include: [{ association: User.Tasks, include: [Task.SubTasks] }] }), User.create({
}), id: 2,
User.create({ tasks: [
id: 2, { title: 'a', subtasks: [
tasks: [ { title: 'b' },
{ title: 'a', subtasks: [ { title: 'a' },
{ title: 'b' }, { title: 'c' }
{ title: 'a' }, ] },
{ title: 'c' } { title: 'c', subtasks: [
] }, { title: 'a' }
{ title: 'c', subtasks: [ ] },
{ title: 'a' } { title: 'b', subtasks: [
] }, { title: 'a' },
{ title: 'b', subtasks: [ { title: 'b' }
{ title: 'a' }, ] }
{ title: 'b' } ]
] } }, {
] 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({
}), id: 2,
Player.create({ user: {}
id: 2, }, {
user: {} include: [Player.User]
}, { }), Player.create({
include: [Player.User] id: 3
}), })]);
Player.create({
id: 3
})
);
}).then(players => { }).then(players => {
return Player.User.get(players).then(result => { return Player.User.get(players).then(result => {
expect(result[players[0].id].id).to.equal(players[0].user.id); expect(result[players[0].id].id).to.equal(players[0].user.id);
...@@ -900,9 +896,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { ...@@ -900,9 +896,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
it('should load with an alias', function() { it('should load with an alias', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Individual.create({ name: 'Foo Bar' }), this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' })); this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => { }).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat); return individual.setPersonwearinghat(hat);
}).then(() => { }).then(() => {
...@@ -929,9 +926,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { ...@@ -929,9 +926,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
it('should load all', function() { it('should load all', function() {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Individual.create({ name: 'Foo Bar' }), this.Individual.create({ name: 'Foo Bar' }),
this.Hat.create({ name: 'Baz' })); this.Hat.create({ name: 'Baz' })
]);
}).then(([individual, hat]) => { }).then(([individual, hat]) => {
return individual.setPersonwearinghat(hat); return individual.setPersonwearinghat(hat);
}).then(() => { }).then(() => {
......
...@@ -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(), title: 'I am a comment'
this.Comment.create({ }), this.Comment.create({
title: 'I am a comment' title: 'I am a main comment',
}), isMain: true
this.Comment.create({ })]);
title: 'I am a main comment',
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({
}), include: [this.Comment]
this.Image.findOne({ }), this.Question.findOne({
include: [this.Comment] include: [this.Comment]
}), })]);
this.Question.findOne({
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(), title: 'I am a blue comment',
this.Comment.create({ type: 'blue'
title: 'I am a blue comment', }), this.Comment.create({
type: 'blue' title: 'I am a red comment',
}), type: 'red'
this.Comment.create({ }), this.Comment.create({
title: 'I am a red comment', title: 'I am a green comment',
type: 'red' type: 'green'
}), })]);
this.Comment.create({
title: 'I am a green comment',
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,35 +372,31 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -396,35 +372,31 @@ 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') },
}, include: [
include: [ { model: this.Tag, as: 'tags' },
{ model: this.Tag, as: 'tags' }, { model: this.Tag, as: 'categories' }
{ model: this.Tag, as: 'categories' } ]
] }), this.Post.findOne({
}), where: {
this.Post.findOne({ id: this.postB.get('id')
where: { },
id: this.postB.get('id') include: [
}, { model: this.Tag, as: 'tags' },
include: [ { model: this.Tag, as: 'categories' }
{ model: this.Tag, as: 'tags' }, ]
{ model: this.Tag, as: 'categories' } }), this.Post.findOne({
] where: {
}), id: this.postC.get('id')
this.Post.findOne({ },
where: { include: [
id: this.postC.get('id') { model: this.Tag, as: 'tags' },
}, { model: this.Tag, as: 'categories' }
include: [ ]
{ model: this.Tag, as: 'tags' }, })]);
{ 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({
}), where: {},
this.Image.findOne({ include: [this.Tag]
where: {}, }), this.Question.findOne({
include: [this.Tag] where: {},
}), include: [this.Tag]
this.Question.findOne({ })]).then(([post, image, question]) => {
where: {},
include: [this.Tag]
})
).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({
}), title: 'pursuit'
user.createTask({ })]);
title: 'pursuit'
})
);
}).then(() => { }).then(() => {
return User.findOne({ return User.findOne({
include: [ include: [
...@@ -271,10 +265,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -271,10 +265,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
user: User.create(), user: User.create(),
group: Group.create() group: Group.create()
}).then(props => { }).then(props => {
return Promise.join( return Promise.all([props.task.setUser(props.user), props.user.setGroup(props.group)]).then(() => props);
props.task.setUser(props.user),
props.user.setGroup(props.group)
).then(() => props);
}).then(props => { }).then(props => {
return Task.findOne({ return Task.findOne({
where: { where: {
......
...@@ -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([
]), { title: 'Chair' },
Product.bulkCreate([ { title: 'Desk' },
{ title: 'Chair' }, { title: 'Dress' }
{ title: 'Desk' }, ]), Tag.bulkCreate([
{ title: 'Dress' } { name: 'A' },
]), { name: 'B' },
Tag.bulkCreate([ { name: 'C' }
{ name: 'A' }, ])]).then(() => {
{ name: 'B' }, return Promise.all([Set.findAll(), Product.findAll(), Tag.findAll()]);
{ name: 'C' }
])
).then(() => {
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,44 +445,41 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -453,44 +445,41 @@ 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([ {},
{}, {},
{}, {},
{}, {},
{}, {},
{}, {},
{}, {},
{}, {}
{} ]).then(() => {
]).then(() => { return A.findAll();
return A.findAll(); }), (function(singles) {
}), let promise = Promise.resolve(),
(function(singles) { previousInstance,
let promise = Promise.resolve(), b;
previousInstance,
b; singles.forEach(model => {
promise = promise.then(() => {
singles.forEach(model => { return model.create({}).then(instance => {
promise = promise.then(() => { if (previousInstance) {
return model.create({}).then(instance => { return previousInstance[`set${_.upperFirst(model.name)}`](instance).then(() => {
if (previousInstance) { previousInstance = instance;
return previousInstance[`set${_.upperFirst(model.name)}`](instance).then(() => { });
previousInstance = instance; }
}); previousInstance = b = instance;
}
previousInstance = b = instance;
});
}); });
}); });
});
promise = promise.then(() => { promise = promise.then(() => {
return b; return b;
}); });
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,50 +534,47 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -545,50 +534,47 @@ 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([ {},
{}, {},
{}, {},
{}, {},
{}, {},
{}, {},
{}, {},
{}, {}
{} ]).then(() => {
]).then(() => { return A.findAll();
return A.findAll(); }), (function(singles) {
}), let promise = Promise.resolve(),
(function(singles) { previousInstance,
let promise = Promise.resolve(), b;
previousInstance,
b; singles.forEach(model => {
const values = {};
singles.forEach(model => {
const values = {}; if (model.name === 'g') {
values.name = 'yolo';
if (model.name === 'g') { }
values.name = 'yolo';
}
promise = promise.then(() => { promise = promise.then(() => {
return model.create(values).then(instance => { return model.create(values).then(instance => {
if (previousInstance) { if (previousInstance) {
return previousInstance[`set${_.upperFirst(model.name)}`](instance).then(() => { return previousInstance[`set${_.upperFirst(model.name)}`](instance).then(() => {
previousInstance = instance; previousInstance = instance;
}); });
} }
previousInstance = b = instance; previousInstance = b = instance;
});
}); });
}); });
});
promise = promise.then(() => { promise = promise.then(() => {
return b; return b;
}); });
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([
]), { name: 'Important task', fk: 3 },
Task.bulkCreate([ { name: 'Important task', fk: 4 },
{ name: 'Important task', fk: 3 }, { name: 'Important task', fk: 5 },
{ name: 'Important task', fk: 4 }, { name: 'Important task', fk: 6 }
{ name: 'Important task', fk: 5 }, ]), Employee.bulkCreate([
{ name: 'Important task', fk: 6 } { name: 'Jane Doe', fk: 1 },
]), { name: 'John Doe', fk: 4 },
Employee.bulkCreate([ { name: 'Jane John Doe', fk: 5 },
{ name: 'Jane Doe', fk: 1 }, { name: 'John Jane Doe', fk: 6 }
{ name: 'John Doe', fk: 4 }, ])]).then(() =>{
{ name: 'Jane John Doe', fk: 5 },
{ name: 'John Jane Doe', fk: 6 }
])
).then(() =>{
//Find all projects with tasks and employees //Find all projects with tasks and employees
const availableProjects = 3; const availableProjects = 3;
const limit = 2; const limit = 2;
...@@ -101,55 +97,49 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -101,55 +97,49 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
// Create an enviroment // Create an enviroment
return Promise.join( return Promise.all([User.bulkCreate([
User.bulkCreate([ { name: 'Youtube' },
{ name: 'Youtube' }, { name: 'Facebook' },
{ name: 'Facebook' }, { name: 'Google' },
{ name: 'Google' }, { name: 'Yahoo' },
{ name: 'Yahoo' }, { name: '404' }
{ name: '404' } ]), SomeConnection.bulkCreate([ // Lets count, m: A and u: 1
]), { u: 1, m: 'A', fk: 1 }, // 1 // Will be deleted
SomeConnection.bulkCreate([ // Lets count, m: A and u: 1 { u: 2, m: 'A', fk: 1 },
{ u: 1, m: 'A', fk: 1 }, // 1 // Will be deleted { u: 3, m: 'A', fk: 1 },
{ u: 2, m: 'A', fk: 1 }, { u: 4, m: 'A', fk: 1 },
{ u: 3, m: 'A', fk: 1 }, { u: 5, m: 'A', fk: 1 },
{ u: 4, m: 'A', fk: 1 }, { u: 1, m: 'B', fk: 1 },
{ u: 5, m: 'A', fk: 1 }, { u: 2, m: 'B', fk: 1 },
{ u: 1, m: 'B', fk: 1 }, { u: 3, m: 'B', fk: 1 },
{ u: 2, m: 'B', fk: 1 }, { u: 4, m: 'B', fk: 1 },
{ u: 3, m: 'B', fk: 1 }, { u: 5, m: 'B', fk: 1 },
{ u: 4, m: 'B', fk: 1 }, { u: 1, m: 'C', fk: 1 },
{ u: 5, m: 'B', fk: 1 }, { u: 2, m: 'C', fk: 1 },
{ u: 1, m: 'C', fk: 1 }, { u: 3, m: 'C', fk: 1 },
{ u: 2, m: 'C', fk: 1 }, { u: 4, m: 'C', fk: 1 },
{ u: 3, m: 'C', fk: 1 }, { u: 5, m: 'C', fk: 1 },
{ u: 4, m: 'C', fk: 1 }, { u: 1, m: 'A', fk: 2 }, // 2 // Will be deleted
{ u: 5, m: 'C', fk: 1 }, { u: 4, m: 'A', fk: 2 },
{ u: 1, m: 'A', fk: 2 }, // 2 // Will be deleted { u: 2, m: 'A', fk: 2 },
{ u: 4, m: 'A', fk: 2 }, { u: 1, m: 'A', fk: 3 }, // 3
{ u: 2, m: 'A', fk: 2 }, { u: 2, m: 'A', fk: 3 },
{ u: 1, m: 'A', fk: 3 }, // 3 { u: 3, m: 'A', fk: 3 },
{ u: 2, m: 'A', fk: 3 }, { u: 2, m: 'B', fk: 2 },
{ u: 3, m: 'A', fk: 3 }, { u: 1, m: 'A', fk: 4 }, // 4
{ u: 2, m: 'B', fk: 2 }, { u: 4, m: 'A', fk: 2 }
{ u: 1, m: 'A', fk: 4 }, // 4 ]), A.bulkCreate([
{ u: 4, m: 'A', fk: 2 } { name: 'Just' },
]), { name: 'for' },
A.bulkCreate([ { name: 'testing' },
{ name: 'Just' }, { name: 'proposes' },
{ name: 'for' }, { name: 'only' }
{ name: 'testing' }, ]), B.bulkCreate([
{ name: 'proposes' }, { name: 'this should not' },
{ name: 'only' } { name: 'be loaded' }
]), ]), C.bulkCreate([
B.bulkCreate([ { name: 'because we only want A' }
{ name: 'this should not' }, ])]).then(() => {
{ name: 'be loaded' }
]),
C.bulkCreate([
{ name: 'because we only want A' }
])
).then(() => {
// Delete some of conns to prove the concept // Delete some of conns to prove the concept
return SomeConnection.destroy({ where: { return SomeConnection.destroy({ where: {
m: 'A', m: 'A',
......
...@@ -151,10 +151,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -151,10 +151,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return this.sequelize return this.sequelize
.sync({ force: true }) .sync({ force: true })
.then(() => { .then(() => {
return Promise.join( return Promise.all([A.create({}), B.create({})]);
A.create({}),
B.create({})
);
}) })
.then(([a, b]) => { .then(([a, b]) => {
return a.addB(b, { through: { name: 'Foobar' } }); return a.addB(b, { through: { name: 'Foobar' } });
...@@ -293,39 +290,36 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -293,39 +290,36 @@ describe(Support.getTestDialectTeaser('Include'), () => {
G.belongsTo(H); G.belongsTo(H);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([A.create({}), (function(singles) {
A.create({}), let promise = Promise.resolve(),
(function(singles) { previousInstance,
let promise = Promise.resolve(), b;
previousInstance,
b;
singles.forEach(model => {
const values = {};
if (model.name === 'g') {
values.name = 'yolo';
}
promise = promise.then(() => { singles.forEach(model => {
return model.create(values).then(instance => { const values = {};
if (previousInstance) {
return previousInstance[`set${_.upperFirst(model.name)}`](instance).then(() => { if (model.name === 'g') {
previousInstance = instance; values.name = 'yolo';
}); }
}
previousInstance = b = instance;
});
});
});
promise = promise.then(() => { promise = promise.then(() => {
return b; return model.create(values).then(instance => {
if (previousInstance) {
return previousInstance[`set${_.upperFirst(model.name)}`](instance).then(() => {
previousInstance = instance;
});
}
previousInstance = b = instance;
});
}); });
});
promise = promise.then(() => {
return b;
});
return promise; return promise;
})([B, C, D, E, F, G, H]) })([B, C, D, E, F, G, H])]).then(([a, b]) => {
).then(([a, b]) => {
return a.setB(b); return a.setB(b);
}).then(() => { }).then(() => {
return A.findOne({ return A.findOne({
......
...@@ -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,26 +21,23 @@ if (current.dialect.supports.groupedLimit) { ...@@ -21,26 +21,23 @@ if (current.dialect.supports.groupedLimit) {
User.Tasks = User.hasMany(Task, { as: 'tasks' }); User.Tasks = User.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, tasks: [
tasks: [ {},
{}, {},
{}, {}
{} ]
] }, {
}, { include: [User.Tasks]
include: [User.Tasks] }), User.create({
}), id: 2,
User.create({ tasks: [
id: 2, {}
tasks: [ ]
{} }, {
] include: [User.Tasks]
}, { })]).then(() => {
include: [User.Tasks]
})
).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Tasks, separate: true } { association: User.Tasks, separate: true }
...@@ -193,29 +190,26 @@ if (current.dialect.supports.groupedLimit) { ...@@ -193,29 +190,26 @@ if (current.dialect.supports.groupedLimit) {
User.Tasks = User.hasMany(Task, { as: 'tasks', foreignKey: 'userId' }); User.Tasks = User.hasMany(Task, { as: 'tasks', foreignKey: 'userId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, tasks: [
tasks: [ {},
{}, {},
{}, {}
{} ]
] }, {
}, { include: [User.Tasks]
include: [User.Tasks] }), User.create({
}), id: 2,
User.create({ tasks: [
id: 2, {},
tasks: [ {},
{}, {},
{}, {}
{}, ]
{} }, {
] include: [User.Tasks]
}, { })]).then(() => {
include: [User.Tasks]
})
).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Tasks, limit: 2 } { association: User.Tasks, limit: 2 }
...@@ -245,34 +239,31 @@ if (current.dialect.supports.groupedLimit) { ...@@ -245,34 +239,31 @@ if (current.dialect.supports.groupedLimit) {
Company.Tasks = Company.hasMany(Task, { as: 'tasks' }); Company.Tasks = Company.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, company: {
company: { tasks: [
tasks: [ {},
{}, {},
{}, {}
{}
]
}
}, {
include: [
{ association: User.Company, include: [Company.Tasks] }
] ]
}), }
User.create({ }, {
id: 2, include: [
company: { { association: User.Company, include: [Company.Tasks] }
tasks: [ ]
{} }), User.create({
] id: 2,
} company: {
}, { tasks: [
include: [ {}
{ association: User.Company, include: [Company.Tasks] }
] ]
}) }
).then(() => { }, {
include: [
{ association: User.Company, include: [Company.Tasks] }
]
})]).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Company, include: [ { association: User.Company, include: [
...@@ -306,28 +297,26 @@ if (current.dialect.supports.groupedLimit) { ...@@ -306,28 +297,26 @@ if (current.dialect.supports.groupedLimit) {
Task.Project = Task.belongsTo(Project, { as: 'project' }); Task.Project = Task.belongsTo(Project, { as: 'project' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Company.create({
Company.create({ id: 1,
id: 1, users: [
users: [ {
{ tasks: [
tasks: [ { project: {} },
{ project: {} }, { project: {} },
{ project: {} }, { project: {} }
{ project: {} } ]
] }
} ]
] }, {
}, { include: [
include: [ { association: Company.Users, include: [
{ association: Company.Users, include: [ { association: User.Tasks, include: [
{ association: User.Tasks, include: [ Task.Project
Task.Project
] }
] } ] }
] ] }
}) ]
).then(() => { })]).then(() => {
return Company.findAll({ return Company.findAll({
include: [ include: [
{ association: Company.Users, include: [ { association: Company.Users, include: [
...@@ -359,47 +348,44 @@ if (current.dialect.supports.groupedLimit) { ...@@ -359,47 +348,44 @@ if (current.dialect.supports.groupedLimit) {
Project.Tasks = Project.hasMany(Task, { as: 'tasks' }); Project.Tasks = Project.hasMany(Task, { as: 'tasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, projects: [
projects: [ {
{ id: 1,
id: 1, tasks: [
tasks: [ {},
{}, {},
{}, {}
{} ]
] },
}, {
{ id: 2,
id: 2, tasks: [
tasks: [ {}
{} ]
] }
} ]
] }, {
}, { include: [
include: [ { association: User.Projects, include: [Project.Tasks] }
{ association: User.Projects, include: [Project.Tasks] } ]
] }), User.create({
}), id: 2,
User.create({ projects: [
id: 2, {
projects: [ id: 3,
{ tasks: [
id: 3, {},
tasks: [ {}
{}, ]
{} }
] ]
} }, {
] include: [
}, { { association: User.Projects, include: [Project.Tasks] }
include: [ ]
{ association: User.Projects, include: [Project.Tasks] } })]).then(() => {
]
})
).then(() => {
return User.findAll({ return User.findAll({
include: [ include: [
{ association: User.Projects, separate: true, include: [ { association: User.Projects, separate: true, include: [
...@@ -445,29 +431,26 @@ if (current.dialect.supports.groupedLimit) { ...@@ -445,29 +431,26 @@ if (current.dialect.supports.groupedLimit) {
return Support.dropTestSchemas(this.sequelize).then(() => { return Support.dropTestSchemas(this.sequelize).then(() => {
return this.sequelize.createSchema('archive').then(() => { return this.sequelize.createSchema('archive').then(() => {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([User.create({
User.create({ id: 1,
id: 1, tasks: [
tasks: [ { id: 1, title: 'b' },
{ id: 1, title: 'b' }, { id: 2, title: 'd' },
{ id: 2, title: 'd' }, { id: 3, title: 'c' },
{ id: 3, title: 'c' }, { id: 4, title: 'a' }
{ id: 4, title: 'a' } ]
] }, {
}, { include: [User.Tasks]
include: [User.Tasks] }), User.create({
}), id: 2,
User.create({ tasks: [
id: 2, { id: 5, title: 'a' },
tasks: [ { id: 6, title: 'c' },
{ id: 5, title: 'a' }, { id: 7, title: 'b' }
{ id: 6, title: 'c' }, ]
{ id: 7, title: 'b' } }, {
] include: [User.Tasks]
}, { })]);
include: [User.Tasks]
})
);
}).then(() => { }).then(() => {
return User.findAll({ return User.findAll({
include: [{ model: Task, limit: 2, as: 'tasks', order: [['id', 'ASC']] }], include: [{ model: Task, limit: 2, as: 'tasks', order: [['id', 'ASC']] }],
......
...@@ -46,10 +46,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -46,10 +46,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.Course.belongsToMany(this.Student, { through: this.Score, foreignKey: 'CourseId' }); this.Course.belongsToMany(this.Student, { through: this.Score, foreignKey: 'CourseId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.Student.create({ no: 1, name: 'ryan' }), this.Student.create({ no: 1, name: 'ryan' }),
this.Course.create({ no: 100, name: 'history' }) this.Course.create({ no: 100, name: 'history' })
).then(([student, course]) => { ]).then(([student, course]) => {
return student.addCourse(course, { through: { score: 98, test_value: 1000 } }); return student.addCourse(course, { through: { score: 98, test_value: 1000 } });
}).then(() => { }).then(() => {
expect(callCount).to.equal(1); expect(callCount).to.equal(1);
...@@ -58,10 +58,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -58,10 +58,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
}) })
.then(() => { .then(() => {
return Promise.join( return Promise.all([
this.Student.build({ no: 1 }).getCourses({ where: { no: 100 } }), this.Student.build({ no: 1 }).getCourses({ where: { no: 100 } }),
this.Score.findOne({ where: { StudentId: 1, CourseId: 100 } }) this.Score.findOne({ where: { StudentId: 1, CourseId: 100 } })
); ]);
}) })
.then(([courses, score]) => { .then(([courses, score]) => {
expect(score.test_value).to.equal(1001); expect(score.test_value).to.equal(1001);
......
...@@ -542,14 +542,11 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -542,14 +542,11 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it('should work with a belongsTo association getter', function() { it('should work with a belongsTo association getter', function() {
const userId = Math.floor(Math.random() * 100000); const userId = Math.floor(Math.random() * 100000);
return Promise.join( return Promise.all([this.User.create({
this.User.create({ id: userId
id: userId }), this.Task.create({
}), user_id: userId
this.Task.create({ })]).then(([user, task]) => {
user_id: userId
})
).then(([user, task]) => {
return Promise.all([user, task.getUser()]); return Promise.all([user, task.getUser()]);
}).then(([userA, userB]) => { }).then(([userA, userB]) => {
expect(userA.get('id')).to.equal(userB.get('id')); expect(userA.get('id')).to.equal(userB.get('id'));
......
...@@ -432,26 +432,25 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -432,26 +432,25 @@ describe(Support.getTestDialectTeaser('Model'), () => {
if (current.dialect.supports.transactions) { if (current.dialect.supports.transactions) {
it('works with a transaction', function() { it('works with a transaction', function() {
return this.sequelize.transaction().then(transaction => { return this.sequelize.transaction().then(transaction => {
return Promise.join( return Promise.all([
this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction }), this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction }),
this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction }), this.User.findOrCreate({ where: { uniqueName: 'winner' }, transaction })
(first, second) => { ]).then(([first, second]) => {
const firstInstance = first[0], const firstInstance = first[0],
firstCreated = first[1], firstCreated = first[1],
secondInstance = second[0], secondInstance = second[0],
secondCreated = second[1]; secondCreated = second[1];
// Depending on execution order and MAGIC either the first OR the second call should return true // Depending on execution order and MAGIC either the first OR the second call should return true
expect(firstCreated ? !secondCreated : secondCreated).to.be.ok; // XOR expect(firstCreated ? !secondCreated : secondCreated).to.be.ok; // XOR
expect(firstInstance).to.be.ok; expect(firstInstance).to.be.ok;
expect(secondInstance).to.be.ok; expect(secondInstance).to.be.ok;
expect(firstInstance.id).to.equal(secondInstance.id); expect(firstInstance.id).to.equal(secondInstance.id);
return transaction.commit(); return transaction.commit();
} });
);
}); });
}); });
} }
...@@ -512,87 +511,82 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -512,87 +511,82 @@ describe(Support.getTestDialectTeaser('Model'), () => {
username: 'gottlieb' username: 'gottlieb'
}); });
}).then(() => { }).then(() => {
return Promise.join( return Promise.all([User.findOrCreate({
User.findOrCreate({ where: {
where: { objectId: 'asdasdasd'
objectId: 'asdasdasd' },
}, defaults: {
defaults: { username: 'gottlieb'
username: 'gottlieb' }
} }).then(() => {
}).then(() => { throw new Error('I should have ben rejected');
throw new Error('I should have ben rejected'); }).catch(err => {
}).catch(err => { expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok;
expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok; expect(err.fields).to.be.ok;
expect(err.fields).to.be.ok; }), User.findOrCreate({
}), where: {
User.findOrCreate({ objectId: 'asdasdasd'
where: { },
objectId: 'asdasdasd' defaults: {
}, username: 'gottlieb'
defaults: { }
username: 'gottlieb' }).then(() => {
} throw new Error('I should have ben rejected');
}).then(() => { }).catch(err => {
throw new Error('I should have ben rejected'); expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok;
}).catch(err => { expect(err.fields).to.be.ok;
expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok; })]);
expect(err.fields).to.be.ok;
})
);
}); });
}); });
// Creating two concurrent transactions and selecting / inserting from the same table throws sqlite off // Creating two concurrent transactions and selecting / inserting from the same table throws sqlite off
(dialect !== 'sqlite' ? it : it.skip)('works without a transaction', function() { (dialect !== 'sqlite' ? it : it.skip)('works without a transaction', function() {
return Promise.join( return Promise.all([
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } })
(first, second) => { ]).then(([first, second]) => {
const firstInstance = first[0], const firstInstance = first[0],
firstCreated = first[1], firstCreated = first[1],
secondInstance = second[0], secondInstance = second[0],
secondCreated = second[1]; secondCreated = second[1];
// Depending on execution order and MAGIC either the first OR the second call should return true // Depending on execution order and MAGIC either the first OR the second call should return true
expect(firstCreated ? !secondCreated : secondCreated).to.be.ok; // XOR expect(firstCreated ? !secondCreated : secondCreated).to.be.ok; // XOR
expect(firstInstance).to.be.ok; expect(firstInstance).to.be.ok;
expect(secondInstance).to.be.ok; expect(secondInstance).to.be.ok;
expect(firstInstance.id).to.equal(secondInstance.id); expect(firstInstance.id).to.equal(secondInstance.id);
} });
);
}); });
}); });
}); });
describe('findCreateFind', () => { describe('findCreateFind', () => {
(dialect !== 'sqlite' ? it : it.skip)('should work with multiple concurrent calls', function() { (dialect !== 'sqlite' ? it : it.skip)('should work with multiple concurrent calls', function() {
return Promise.join( return Promise.all([
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } }),
this.User.findOrCreate({ where: { uniqueName: 'winner' } }), this.User.findOrCreate({ where: { uniqueName: 'winner' } })
(first, second, third) => { ]).then(([first, second, third]) => {
const firstInstance = first[0], const firstInstance = first[0],
firstCreated = first[1], firstCreated = first[1],
secondInstance = second[0], secondInstance = second[0],
secondCreated = second[1], secondCreated = second[1],
thirdInstance = third[0], thirdInstance = third[0],
thirdCreated = third[1]; thirdCreated = third[1];
expect([firstCreated, secondCreated, thirdCreated].filter(value => { expect([firstCreated, secondCreated, thirdCreated].filter(value => {
return value; return value;
}).length).to.equal(1); }).length).to.equal(1);
expect(firstInstance).to.be.ok; expect(firstInstance).to.be.ok;
expect(secondInstance).to.be.ok; expect(secondInstance).to.be.ok;
expect(thirdInstance).to.be.ok; expect(thirdInstance).to.be.ok;
expect(firstInstance.id).to.equal(secondInstance.id); expect(firstInstance.id).to.equal(secondInstance.id);
expect(secondInstance.id).to.equal(thirdInstance.id); expect(secondInstance.id).to.equal(thirdInstance.id);
} });
);
}); });
}); });
...@@ -656,13 +650,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -656,13 +650,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
Log.removeAttribute('id'); Log.removeAttribute('id');
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([Log.create({ level: 'info' }), Log.bulkCreate([
Log.create({ level: 'info' }), { level: 'error' },
Log.bulkCreate([ { level: 'debug' }
{ level: 'error' }, ])]);
{ level: 'debug' }
])
);
}).then(() => { }).then(() => {
return Log.findAll(); return Log.findAll();
}).then(logs => { }).then(logs => {
......
...@@ -51,22 +51,22 @@ if (current.dialect.supports['UNION ALL']) { ...@@ -51,22 +51,22 @@ if (current.dialect.supports['UNION ALL']) {
this.User.Tasks = this.User.hasMany(this.Task); this.User.Tasks = this.User.hasMany(this.Task);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.User.bulkCreate([{ age: -5 }, { age: 45 }, { age: 7 }, { age: -9 }, { age: 8 }, { age: 15 }, { age: -9 }]), this.User.bulkCreate([{ age: -5 }, { age: 45 }, { age: 7 }, { age: -9 }, { age: 8 }, { age: 15 }, { age: -9 }]),
this.Project.bulkCreate([{}, {}]), this.Project.bulkCreate([{}, {}]),
this.Task.bulkCreate([{}, {}]) this.Task.bulkCreate([{}, {}])
); ]);
}) })
.then(() => Promise.all([this.User.findAll(), this.Project.findAll(), this.Task.findAll()])) .then(() => Promise.all([this.User.findAll(), this.Project.findAll(), this.Task.findAll()]))
.then(([users, projects, tasks]) => { .then(([users, projects, tasks]) => {
this.projects = projects; this.projects = projects;
return Promise.join( return Promise.all([
projects[0].setMembers(users.slice(0, 4)), projects[0].setMembers(users.slice(0, 4)),
projects[1].setMembers(users.slice(2)), projects[1].setMembers(users.slice(2)),
projects[0].setParanoidMembers(users.slice(0, 4)), projects[0].setParanoidMembers(users.slice(0, 4)),
projects[1].setParanoidMembers(users.slice(2)), projects[1].setParanoidMembers(users.slice(2)),
users[2].setTasks(tasks) users[2].setTasks(tasks)
); ]);
}); });
}); });
...@@ -218,19 +218,19 @@ if (current.dialect.supports['UNION ALL']) { ...@@ -218,19 +218,19 @@ if (current.dialect.supports['UNION ALL']) {
this.User.Tasks = this.User.hasMany(this.Task); this.User.Tasks = this.User.hasMany(this.Task);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
this.User.bulkCreate([{}, {}, {}]), this.User.bulkCreate([{}, {}, {}]),
this.Task.bulkCreate([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }]) this.Task.bulkCreate([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }])
); ]);
}) })
.then(() => Promise.all([this.User.findAll(), this.Task.findAll()])) .then(() => Promise.all([this.User.findAll(), this.Task.findAll()]))
.then(([users, tasks]) => { .then(([users, tasks]) => {
this.users = users; this.users = users;
return Promise.join( return Promise.all([
users[0].setTasks(tasks[0]), users[0].setTasks(tasks[0]),
users[1].setTasks(tasks.slice(1, 4)), users[1].setTasks(tasks.slice(1, 4)),
users[2].setTasks(tasks.slice(4)) users[2].setTasks(tasks.slice(4))
); ]);
}); });
}); });
......
...@@ -210,26 +210,23 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -210,26 +210,23 @@ 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', last: 'Simpson'
last: 'Simpson' },
}, employment: 'Nuclear Safety Inspector'
employment: 'Nuclear Safety Inspector' }
} }), this.Event.create({
}), data: {
this.Event.create({ name: {
data: { first: 'Marge',
name: { last: 'Simpson'
first: 'Marge', },
last: 'Simpson' 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,26 +334,23 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -341,26 +334,23 @@ 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', last: 'Simpson'
last: 'Simpson' },
}, age: 40
age: 40 }
} }), this.Event.create({
}), data: {
this.Event.create({ name: {
data: { first: 'Marge',
name: { last: 'Simpson'
first: 'Marge', },
last: 'Simpson' age: 37
}, }
age: 37 })]).then(() => {
}
})
).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
data: { data: {
...@@ -385,26 +375,23 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -385,26 +375,23 @@ 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', last: 'Simpson'
last: 'Simpson' },
}, employment: 'Nuclear Safety Inspector'
employment: 'Nuclear Safety Inspector' }
} }), this.Event.create({
}), data: {
this.Event.create({ name: {
data: { first: 'Marge',
name: { last: 'Simpson'
first: 'Marge', },
last: 'Simpson' employment: null
}, }
employment: null })]).then(() => {
}
})
).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
data: { data: {
...@@ -425,31 +412,28 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -425,31 +412,28 @@ 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', last: 'Simpson'
last: 'Simpson' },
}, status_report: {
status_report: { 'red-indicator': {
'red-indicator': { 'level$$level': true
'level$$level': true }
} },
}, employment: 'Nuclear Safety Inspector'
employment: 'Nuclear Safety Inspector' }
} }), this.Event.create({
}), data: {
this.Event.create({ name: {
data: { first: 'Marge',
name: { last: 'Simpson'
first: 'Marge', },
last: 'Simpson' employment: null
}, }
employment: null })]).then(() => {
}
})
).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
data: { data: {
...@@ -488,26 +472,23 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -488,26 +472,23 @@ 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', last: 'Simpson'
last: 'Simpson' },
}, employment: 'Housewife'
employment: 'Housewife' }
} }), this.Event.create({
}), data: {
this.Event.create({ name: {
data: { first: 'Bart',
name: { last: 'Simpson'
first: 'Bart', },
last: 'Simpson' employment: 'None'
}, }
employment: 'None' })]);
}
})
);
}).then(() => { }).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
...@@ -555,26 +536,23 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -555,26 +536,23 @@ 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', last: 'Simpson'
last: 'Simpson' },
}, employment: 'Housewife'
employment: 'Housewife' }
} }), this.Event.create({
}), data: {
this.Event.create({ name: {
data: { first: 'Bart',
name: { last: 'Simpson'
first: 'Bart', },
last: 'Simpson' employment: 'None'
}, }
employment: 'None' })]);
}
})
);
}).then(() => { }).then(() => {
return this.Event.findAll({ return this.Event.findAll({
where: { where: {
...@@ -628,35 +606,31 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -628,35 +606,31 @@ describe(Support.getTestDialectTeaser('Model'), () => {
} }
}; };
return Promise.join( return Promise.all([this.Event.create({
this.Event.create({ data: {
data: { name: {
name: { first: 'Elliot',
first: 'Elliot', last: 'Alderson'
last: 'Alderson' },
}, employment: 'Hacker'
employment: 'Hacker' }
} }), this.Event.create({
}), data: {
this.Event.create({ name: {
data: { first: 'Christian',
name: { last: 'Slater'
first: 'Christian', },
last: 'Slater' employment: 'Hacker'
}, }
employment: 'Hacker' }), this.Event.create({
} data: {
}), name: {
this.Event.create({ first: ' Tyrell',
data: { last: 'Wellick'
name: { },
first: ' Tyrell', employment: 'CTO'
last: 'Wellick' }
}, })]).then(() => {
employment: 'CTO'
}
})
).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,26 +727,23 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -753,26 +727,23 @@ 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', last: 'Simpson'
last: 'Simpson' },
}, employment: 'Housewife'
employment: 'Housewife' }
} }), this.Event.create({
}), data: {
this.Event.create({ name: {
data: { first: 'Bart',
name: { last: 'Simpson'
first: 'Bart', },
last: 'Simpson' 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,31 +610,27 @@ if (current.dialect.supports.transactions) { ...@@ -612,31 +610,27 @@ if (current.dialect.supports.transactions) {
return this.sequelize.transaction({ return this.sequelize.transaction({
isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED
}).then(t2 => { }).then(t2 => {
return Promise.join( return Promise.all([User.findOne({
User.findOne({ where: {
where: { username: 'jan'
username: 'jan' },
}, lock: t2.LOCK.UPDATE,
lock: t2.LOCK.UPDATE, transaction: t2
transaction: t2 }).then(() => {
}).then(() => { t2Spy();
t2Spy(); return t2.commit().then(() => {
return t2.commit().then(() => { expect(t2Spy).to.have.been.calledAfter(t1Spy); // Find should not succeed before t1 has committed
expect(t2Spy).to.have.been.calledAfter(t1Spy); // Find should not succeed before t1 has committed });
}); }), t1Jan.update({
}), awesome: true
}, {
t1Jan.update({ transaction: t1
awesome: true }).then(() => {
}, { t1Spy();
transaction: t1 return delay(2000).then(() => {
}).then(() => { return t1.commit();
t1Spy(); });
return delay(2000).then(() => { })]);
return t1.commit();
});
})
);
}); });
}); });
}); });
...@@ -695,12 +689,12 @@ if (current.dialect.supports.transactions) { ...@@ -695,12 +689,12 @@ if (current.dialect.supports.transactions) {
Task.belongsToMany(User, { through: 'UserTasks' }); Task.belongsToMany(User, { through: 'UserTasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
User.create({ username: 'John' }), User.create({ username: 'John' }),
Task.create({ title: 'Get rich', active: false }), Task.create({ title: 'Get rich', active: false })
(john, task1) => { ]).then(([john, task1]) => {
return john.setTasks([task1]); return john.setTasks([task1]);
}) })
.then(() => { .then(() => {
return this.sequelize.transaction(t1 => { return this.sequelize.transaction(t1 => {
...@@ -738,13 +732,13 @@ if (current.dialect.supports.transactions) { ...@@ -738,13 +732,13 @@ if (current.dialect.supports.transactions) {
Task.belongsToMany(User, { through: 'UserTasks' }); Task.belongsToMany(User, { through: 'UserTasks' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.join( return Promise.all([
User.create({ username: 'John' }), User.create({ username: 'John' }),
Task.create({ title: 'Get rich', active: false }), Task.create({ title: 'Get rich', active: false }),
Task.create({ title: 'Die trying', active: false }), Task.create({ title: 'Die trying', active: false })
(john, task1) => { ]).then(([john, task1]) => {
return john.setTasks([task1]); return john.setTasks([task1]);
}) })
.then(() => { .then(() => {
return this.sequelize.transaction(t1 => { return this.sequelize.transaction(t1 => {
return User.findOne({ return User.findOne({
...@@ -801,29 +795,26 @@ if (current.dialect.supports.transactions) { ...@@ -801,29 +795,26 @@ if (current.dialect.supports.transactions) {
transaction: t1 transaction: t1
}).then(t1Jan => { }).then(t1Jan => {
return this.sequelize.transaction().then(t2 => { return this.sequelize.transaction().then(t2 => {
return Promise.join( return Promise.all([User.findOne({
User.findOne({ where: {
where: { username: 'jan'
username: 'jan' },
}, lock: t2.LOCK.KEY_SHARE,
lock: t2.LOCK.KEY_SHARE, transaction: t2
transaction: t2 }).then(() => {
}).then(() => { t2Spy();
t2Spy(); return t2.commit();
return t2.commit(); }), t1Jan.update({
}), awesome: true
t1Jan.update({ }, {
awesome: true transaction: t1
}, { }).then(() => {
transaction: t1 return delay(2000).then(() => {
}).then(() => { t1Spy();
return delay(2000).then(() => { expect(t1Spy).to.have.been.calledAfter(t2Spy);
t1Spy(); return t1.commit();
expect(t1Spy).to.have.been.calledAfter(t2Spy); });
return t1.commit(); })]);
});
})
);
}); });
}); });
}); });
...@@ -854,38 +845,34 @@ if (current.dialect.supports.transactions) { ...@@ -854,38 +845,34 @@ if (current.dialect.supports.transactions) {
return this.sequelize.transaction({ return this.sequelize.transaction({
isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED
}).then(t2 => { }).then(t2 => {
return Promise.join( return Promise.all([User.findOne({
User.findOne({ where: {
where: { username: 'jan'
username: 'jan' },
}, transaction: t2
transaction: t2 }).then(t2Jan => {
}).then(t2Jan => { t2FindSpy();
t2FindSpy(); return t2Jan.update({
return t2Jan.update({ awesome: false
awesome: false
}, {
transaction: t2
}).then(() => {
t2UpdateSpy();
return t2.commit().then(() => {
expect(t2FindSpy).to.have.been.calledBefore(t1Spy); // The find call should have returned
expect(t2UpdateSpy).to.have.been.calledAfter(t1Spy); // But the update call should not happen before the first transaction has committed
});
});
}),
t1Jan.update({
awesome: true
}, { }, {
transaction: t1 transaction: t2
}).then(() => { }).then(() => {
return delay(2000).then(() => { t2UpdateSpy();
t1Spy(); return t2.commit().then(() => {
return t1.commit(); expect(t2FindSpy).to.have.been.calledBefore(t1Spy); // The find call should have returned
expect(t2UpdateSpy).to.have.been.calledAfter(t1Spy); // But the update call should not happen before the first transaction has committed
}); });
}) });
); }), t1Jan.update({
awesome: true
}, {
transaction: t1
}).then(() => {
return delay(2000).then(() => {
t1Spy();
return t1.commit();
});
})]);
}); });
}); });
}); });
......
...@@ -309,17 +309,13 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => { ...@@ -309,17 +309,13 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}); });
it('should allow decimal as scientific notation', () => { it('should allow decimal as scientific notation', () => {
return Promise.join( return Promise.all([expect(User.create({
expect(User.create({ number: '2321312301230128391820e219'
number: '2321312301230128391820e219' })).not.to.be.rejected, expect(User.create({
})).not.to.be.rejected, number: '2321312301230128391820e+219'
expect(User.create({ })).not.to.be.rejected, expect(User.create({
number: '2321312301230128391820e+219' number: '2321312301230128391820f219'
})).not.to.be.rejected, })).to.be.rejected]);
expect(User.create({
number: '2321312301230128391820f219'
})).to.be.rejected
);
}); });
it('should allow string as a number', () => { it('should allow string as a number', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!