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

Commit 5d0f9be2 by Mick Hansen

rewrite a few tests to promises

1 parent 3229b061
Showing with 29 additions and 42 deletions
...@@ -20,21 +20,20 @@ var sortById = function(a, b) { ...@@ -20,21 +20,20 @@ var sortById = function(a, b) {
describe(Support.getTestDialectTeaser('Include'), function() { describe(Support.getTestDialectTeaser('Include'), function() {
describe('find', function() { describe('find', function() {
it('should support an empty belongsTo include', function(done) { it('should support an empty belongsTo include', function() {
var Company = this.sequelize.define('Company', {}) var Company = this.sequelize.define('Company', {})
, User = this.sequelize.define('User', {}); , User = this.sequelize.define('User', {});
User.belongsTo(Company, {as: 'Employer'}); User.belongsTo(Company, {as: 'Employer'});
this.sequelize.sync({force: true}).done(function() {
User.create().then(function() { return this.sequelize.sync({force: true}).then(function() {
User.find({ return User.create();
}).then(function() {
return User.find({
include: [{model: Company, as: 'Employer'}] include: [{model: Company, as: 'Employer'}]
}).done(function(err, user) { }).then(function(user) {
expect(err).not.to.be.ok;
expect(user).to.be.ok; expect(user).to.be.ok;
done();
}); });
}, done);
}); });
}); });
...@@ -78,21 +77,20 @@ describe(Support.getTestDialectTeaser('Include'), function() { ...@@ -78,21 +77,20 @@ describe(Support.getTestDialectTeaser('Include'), function() {
}); });
}); });
it('should support a empty hasOne include', function(done) { it('should support a empty hasOne include', function() {
var Company = this.sequelize.define('Company', {}) var Company = this.sequelize.define('Company', {})
, Person = this.sequelize.define('Person', {}); , Person = this.sequelize.define('Person', {});
Company.hasOne(Person, {as: 'CEO'}); Company.hasOne(Person, {as: 'CEO'});
this.sequelize.sync({force: true}).done(function() {
Company.create().then(function() { return this.sequelize.sync({force: true}).then(function() {
Company.find({ return Company.create().then(function() {
return Company.find({
include: [{model: Person, as: 'CEO'}] include: [{model: Person, as: 'CEO'}]
}).done(function(err, company) { }).then(function(company) {
expect(err).not.to.be.ok;
expect(company).to.be.ok; expect(company).to.be.ok;
done();
}); });
}, done); });
}); });
}); });
...@@ -212,7 +210,7 @@ describe(Support.getTestDialectTeaser('Include'), function() { ...@@ -212,7 +210,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
}); });
}); });
it('should support a simple nested belongsTo -> belongsTo include', function(done) { it('should support a simple nested belongsTo -> belongsTo include', function() {
var Task = this.sequelize.define('Task', {}) var Task = this.sequelize.define('Task', {})
, User = this.sequelize.define('User', {}) , User = this.sequelize.define('User', {})
, Group = this.sequelize.define('Group', {}); , Group = this.sequelize.define('Group', {});
...@@ -220,40 +218,29 @@ describe(Support.getTestDialectTeaser('Include'), function() { ...@@ -220,40 +218,29 @@ describe(Support.getTestDialectTeaser('Include'), function() {
Task.belongsTo(User); Task.belongsTo(User);
User.belongsTo(Group); User.belongsTo(Group);
this.sequelize.sync({force: true}).done(function() { return this.sequelize.sync({force: true}).then(function() {
async.auto({ return Promise.props({
task: function(callback) { task: Task.create(),
Task.create().done(callback); user: User.create(),
}, group: Group.create()
user: function(callback) { }).then(function (props) {
User.create().done(callback); return Promise.join(
}, props.task.setUser(props.user),
group: function(callback) { props.user.setGroup(props.group)
Group.create().done(callback); ).return(props);
}, }).then(function (props) {
taskUser: ['task', 'user', function(callback, results) { return Task.findOne({
results.task.setUser(results.user).done(callback);
}],
userGroup: ['user', 'group', function(callback, results) {
results.user.setGroup(results.group).done(callback);
}]
}, function(err, results) {
expect(err).not.to.be.ok;
Task.find({
where: { where: {
id: results.task.id id: props.task.id
}, },
include: [ include: [
{model: User, include: [ {model: User, include: [
{model: Group} {model: Group}
]} ]}
] ]
}).done(function(err, task) { }).then(function(task) {
expect(err).not.to.be.ok;
expect(task.User).to.be.ok; expect(task.User).to.be.ok;
expect(task.User.Group).to.be.ok; expect(task.User.Group).to.be.ok;
done();
}); });
}); });
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!