Skip to content

Instantly share code, notes, and snippets.

@mockra
Created December 30, 2014 01:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mockra/60825fe236417d162116 to your computer and use it in GitHub Desktop.
Save mockra/60825fe236417d162116 to your computer and use it in GitHub Desktop.
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