Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. var app = require('../../server.js'),
  2. request = require('supertest'),
  3. should = require('should'),
  4. mongoose = require('mongoose'),
  5. User = mongoose.model('User'),
  6. Article = mongoose.model('Article');
  7.  
  8. var user, article;
  9.  
  10. describe('Articles Controller Unit Tests:', function() {
  11. beforeEach(function(done) {
  12. user = new User({
  13. firstName: 'Full',
  14. lastName: 'Name',
  15. displayName: 'Full Name',
  16. email: 'test@test.com',
  17. username: 'username',
  18. password: 'password'
  19. });
  20.  
  21. user.save(function() {
  22. article = new Article({
  23. title: 'Article Title',
  24. content: 'Article Content',
  25. user: user
  26. });
  27.  
  28. article.save(function(err) {
  29. done();
  30. })
  31. });
  32. });
  33.  
  34. describe('Testing the GET methods', function() {
  35. it('Should be able to get the list of articles', function(done) {
  36. request(app).get('/api/articles/')
  37. .set('Accept', 'application/json')
  38. .expect('Content-Type', /json/)
  39. .expect(200)
  40. .end(function(err, res) {
  41. res.body.should.be.an.Array().and.have.lengthOf(1);
  42. res.body[0].should.have.property('title', article.title);
  43. res.body[0].should.have.property('content', article.content);
  44.  
  45. done();
  46. });
  47. });
  48.  
  49. it('Should be able to get the specific article', function(done) {
  50. request(app).get('/api/articles/' + article.id)
  51. .set('Accept', 'application/json')
  52. .expect('Content-Type', /json/)
  53. .expect(200)
  54. .end(function(err, res) {
  55. res.body.should.be.an.Object().and.have.property('title', article.title);
  56. res.body.should.have.property('content', article.content);
  57.  
  58. done();
  59. });
  60. });
  61. });
  62.  
  63. afterEach(function(done) {
  64. Article.remove().exec();
  65. User.remove().exec();
  66. done();
  67. });
  68. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement