timvr01

Untitled

Dec 5th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. var expect = require('chai').expect;
  2. var app = require('../app');
  3. var request = require('supertest');
  4.  
  5. var agent = request.agent(app);
  6.  
  7. describe('GET /posts', function () {
  8. it('should respond with 200 in case of valid request', function (done) {
  9. agent.get('/posts').send().end(function (err, res) {
  10. if (err) { return done(err); }
  11. //console.log('res: ', res);
  12. var fetchData=JSON.parse(res.text);
  13. expect(fetchData).to.be.an('array');
  14. expect(fetchData).to.not.empty;
  15. var post = fetchData[0];
  16.  
  17. if(post){
  18. expect(post).to.have.all.keys('__v','_id','comments','upvotes','author', 'title','content','downvotes','votes','postDate');
  19. expect(post.comments).to.be.an('array');
  20. expect(post.votes).to.be.a('number');
  21. expect(post.upvotes).to.be.an('array');
  22. expect(post.downvotes).to.be.an('array');
  23. expect(post.content).to.be.a('string');
  24. expect(post.author).to.be.a('string');
  25. expect(post.postDate).to.be.a('string');
  26. done();
  27. }
  28. });
  29. });
  30.  
  31. });
  32.  
  33.  
  34. var expect =require('chai').expect;
  35.  
  36. describe('Init', function(){
  37.  
  38. it('starts a new testing env',function(done){
  39. expect('test').to.equal('test');
  40. done();
  41. });
  42. });
  43.  
  44. var expect = require('chai').expect;
  45. var app = require('../app');
  46. var request = require('supertest');
  47.  
  48. var agent = request.agent(app);
  49.  
  50. describe('GET /comments', function () {
  51. it('should respond with 200 in case of valid request', function (done) {
  52. agent.get('/posts/565dc4afd40a6e08950b2820/').send().end(function (err, res) {
  53. if (err) { return done(err); }
  54. //console.log('res: ', res);
  55. var fetchData=JSON.parse(res.text);
  56. expect(fetchData).to.be.an('object');
  57. expect(fetchData).to.not.empty;
  58. var comments = fetchData.comments;
  59. expect(comments).to.be.an('array');
  60. expect(comments).to.not.empty;
  61. var comment=comments[0];
  62.  
  63. if(comment){
  64. expect(comment).to.have.all.keys('__v','_id','upvotes','author', 'body','post' ,'downvotes','votes');
  65.  
  66. expect(comment.votes).to.be.a('number');
  67. expect(comment.upvotes).to.be.an('array');
  68. expect(comment.downvotes).to.be.an('array');
  69. expect(comment.body).to.be.a('string');
  70. expect(comment.author).to.be.a('string');
  71.  
  72. done();
  73. }
  74. });
  75. });
  76.  
  77. });
Advertisement
Add Comment
Please, Sign In to add comment