Skip to content

Instantly share code, notes, and snippets.

@mockra mockra/posts_test.js
Created Dec 30, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.