Created
December 30, 2014 01:05
-
-
Save mockra/60825fe236417d162116 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('supertest') | |
var Post = require('../../models/post') | |
describe('Posts Controller', function() { | |
describe('index', function() { | |
it('retrieves posts', function(done) { | |
new Post({ | |
title: 'Test Post', | |
content: 'Test Content' | |
}).save() | |
request(app) | |
.get('/posts') | |
.expect('Content-Type', /json/) | |
.expect(200) | |
.end(function(err, res) { | |
expect(err).to.not.exist | |
expect(res.body.posts[0].title).to.eql('Test Post') | |
expect(res.body.posts).to.have.length(1) | |
done() | |
}) | |
}) | |
}) | |
describe('create', function() { | |
it('creates a post', function(done) { | |
request(app) | |
.post('/posts') | |
.send({title: 'Testing', content: 'Node'}) | |
.expect(201) | |
.end(function(err, res) { | |
expect(err).to.not.exist | |
expect(res.body.title).to.eql('Testing') | |
done() | |
}) | |
}) | |
it('returns error if content is invalid', function(done) { | |
request(app) | |
.post('/posts') | |
.send({title: 'Invalid posting', content: ''}) | |
.expect(400) | |
.end(function(err, res) { | |
expect(res.body.title).to.not.exist | |
expect(res.body.message).to.eql("Validation failed") | |
done() | |
}) | |
}) | |
}) | |
afterEach(function(done) { | |
Post.remove().exec() | |
done() | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment