0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

using promises correctly in tests

This commit is contained in:
Tim Griesser 2013-05-26 19:53:44 -04:00
parent a3d2fb7aa9
commit 3446fe7461
3 changed files with 100 additions and 132 deletions

View file

@ -26,9 +26,7 @@
results.length.should.equal(2); results.length.should.equal(2);
done(); done();
}, function (error) { }, done);
throw error;
});
}); });
it('can read', function (done) { it('can read', function (done) {
@ -41,18 +39,13 @@
firstPost = results.models[0]; firstPost = results.models[0];
posts.read({slug: firstPost.attributes.slug}).then(function (found) { return posts.read({slug: firstPost.attributes.slug});
}).then(function (found) {
should.exist(found); should.exist(found);
found.attributes.title.should.equal(firstPost.attributes.title); found.attributes.title.should.equal(firstPost.attributes.title);
done(); done();
}, function (error) {
throw error;
});
}, function (error) {
throw error;
}); });
}); });
@ -60,25 +53,24 @@
var firstPost; var firstPost;
posts.browse().then(function (results) { posts.browse().then(function (results) {
should.exist(results); should.exist(results);
results.length.should.be.above(0); results.length.should.be.above(0);
firstPost = results.models[0]; firstPost = results.models[0];
posts.edit({id: firstPost.id, title: "new title"}).then(function (edited) { return posts.edit({id: firstPost.id, title: "new title"});
}).then(function (edited) {
should.exist(edited); should.exist(edited);
edited.attributes.title.should.equal('new title'); edited.attributes.title.should.equal('new title');
done(); done();
}, function (error) {
throw error;
});
}, function (error) { }, done);
throw error;
});
}); });
it('can add', function (done) { it('can add', function (done) {
@ -101,20 +93,23 @@
}); });
it('can delete', function (done) { it('can delete', function (done) {
var firstPostId, var firstPostId;
ids,
hasDeletedId;
posts.browse().then(function (results) { posts.browse().then(function (results) {
should.exist(results); should.exist(results);
results.length.should.be.above(0); results.length.should.be.above(0);
firstPostId = results.models[0].id; firstPostId = results.models[0].id;
posts.destroy(firstPostId).then(function () { return posts.destroy(firstPostId);
posts.browse().then(function (newResults) { }).then(function () {
return posts.browse();
}).then(function (newResults) {
var ids, hasDeletedId;
ids = _.pluck(newResults.models, "id"); ids = _.pluck(newResults.models, "id");
@ -125,15 +120,8 @@
hasDeletedId.should.equal(false); hasDeletedId.should.equal(false);
done(); done();
}, function (error) {
throw error; }, done);
});
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}); });
}); });
}()); }());

View file

@ -27,9 +27,7 @@
results.length.should.be.above(0); results.length.should.be.above(0);
done(); done();
}, function (error) { }, done);
throw error;
});
}); });
it('can read', function (done) { it('can read', function (done) {
@ -43,20 +41,17 @@
firstSetting = results.models[0]; firstSetting = results.models[0];
settings.read(firstSetting.attributes.key).then(function (found) { return settings.read(firstSetting.attributes.key);
}).then(function (found) {
should.exist(found); should.exist(found);
found.attributes.value.should.equal(firstSetting.attributes.value); found.attributes.value.should.equal(firstSetting.attributes.value);
done(); done();
}, function (error) {
throw error;
});
}, function (error) { }, done);
throw error;
});
}); });
it('can edit single', function (done) { it('can edit single', function (done) {
@ -75,7 +70,9 @@
// key/value pairs // key/value pairs
toEdit[firstPost.attributes.key] = "new value"; toEdit[firstPost.attributes.key] = "new value";
settings.edit(toEdit).then(function (edited) { return settings.edit(toEdit);
}).then(function (edited) {
should.exist(edited); should.exist(edited);
@ -87,13 +84,8 @@
edited.attributes.value.should.equal('new value'); edited.attributes.value.should.equal('new value');
done(); done();
}, function (error) {
throw error;
});
}, function (error) { }, done);
throw error;
});
}); });
it('can edit multiple', function (done) { it('can edit multiple', function (done) {
@ -116,7 +108,9 @@
toEdit[firstPost.attributes.key] = "new value1"; toEdit[firstPost.attributes.key] = "new value1";
toEdit[secondPost.attributes.key] = "new value2"; toEdit[secondPost.attributes.key] = "new value2";
settings.edit(toEdit).then(function (edited) { return settings.edit(toEdit);
}).then(function (edited) {
should.exist(edited); should.exist(edited);
@ -133,12 +127,8 @@
editedPost.attributes.value.should.equal('new value2'); editedPost.attributes.value.should.equal('new value2');
done(); done();
}, function (error) {
throw error; }, done);
});
}, function (error) {
throw error;
});
}); });
it('can add', function (done) { it('can add', function (done) {
@ -155,15 +145,11 @@
createdSetting.attributes.value.should.equal(newSetting.value, "value is correct"); createdSetting.attributes.value.should.equal(newSetting.value, "value is correct");
done(); done();
}, function (error) { }, done);
throw error;
});
}); });
it('can delete', function (done) { it('can delete', function (done) {
var firstSettingId, var firstSettingId;
ids,
hasDeletedId;
settings.browse().then(function (results) { settings.browse().then(function (results) {
@ -173,9 +159,15 @@
firstSettingId = results.models[0].id; firstSettingId = results.models[0].id;
settings.destroy(firstSettingId).then(function () { return settings.destroy(firstSettingId);
settings.browse().then(function (newResults) { }).then(function () {
return settings.browse();
}).then(function (newResults) {
var ids, hasDeletedId;
ids = _.pluck(newResults.models, "id"); ids = _.pluck(newResults.models, "id");
@ -186,15 +178,8 @@
hasDeletedId.should.equal(false); hasDeletedId.should.equal(false);
done(); done();
}, function (error) {
throw error; }, done);
});
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}); });
}); });
}()); }());

View file

@ -103,9 +103,7 @@
}); });
it('can delete', function (done) { it('can delete', function (done) {
var firstUserId, var firstUserId;
ids,
hasDeletedId;
users.browse().then(function (results) { users.browse().then(function (results) {
@ -115,9 +113,14 @@
firstUserId = results.models[0].id; firstUserId = results.models[0].id;
users.destroy(firstUserId).then(function () { return users.destroy(firstUserId);
users.browse().then(function (newResults) { }).then(function () {
return users.browse();
}).then(function (newResults) {
var ids, hasDeletedId;
if (newResults.length < 1) { if (newResults.length < 1) {
// Bug out if we only had one user and deleted it. // Bug out if we only had one user and deleted it.
@ -133,15 +136,7 @@
hasDeletedId.should.equal(false); hasDeletedId.should.equal(false);
done(); done();
}, function (error) { }, done);
throw error;
});
}, function (error) {
throw error;
});
}, function (error) {
throw error;
});
}); });
}); });