Skip to content

Instantly share code, notes, and snippets.

@ullmark
Forked from marcusoftnet/needPromise.js
Last active August 29, 2015 13:56
Show Gist options
  • Save ullmark/9187969 to your computer and use it in GitHub Desktop.
Save ullmark/9187969 to your computer and use it in GitHub Desktop.
var mongoose = require("mongoose");
var should = require("should");
var Q = require('Q');
var _ = require('underscore');
var dbAccess = require("../dbAccess");
var testHelpers = require("./testHelpers.js");
describe("Getting posts", function () {
beforeEach(function(done) {
// add a couple of posts...
var postToCreate = [];
// ... by adding a couple of promises
_(10).times(function(index) {
var futurePost = Q.fcall(dbAccess.addPost, testHelpers.USERNAME, '#tjaaana ' + (index+1));
postToCreate.push(futurePost);
});
Q
.all(postsToCreate)
.then(function() {
done();
});
});
describe("by other properties", function () {
it("gets all posts with a certain hashtag", function (done) {
Q
.fcall(dbAccess.getPostsByHashTag, "#tjaaana")
.then(function(result) {
result.data.length.should.equal(4);
done();
});
});
it("gets all posts in pages", function (done) {
Q
.fcall(dbAccess.getAllPosts, 1)
.then(function(result) {
testHelpers.validateOkResult(result);
result.data.length.should.equal(10);
result.data[9].message.should.containEql("10");
done();
});
});
});
afterEach(function (done) {
testHelpers.deleteAll();
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment