Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var expect = require('chai').expect;
- var app = require('../app');
- var request = require('supertest');
- var agent = request.agent(app);
- describe('GET /posts', function () {
- it('should respond with 200 in case of valid request', function (done) {
- agent.get('/posts').send().end(function (err, res) {
- if (err) { return done(err); }
- //console.log('res: ', res);
- var fetchData=JSON.parse(res.text);
- expect(fetchData).to.be.an('array');
- expect(fetchData).to.not.empty;
- var post = fetchData[0];
- if(post){
- expect(post).to.have.all.keys('__v','_id','comments','upvotes','author', 'title','content','downvotes','votes','postDate');
- expect(post.comments).to.be.an('array');
- expect(post.votes).to.be.a('number');
- expect(post.upvotes).to.be.an('array');
- expect(post.downvotes).to.be.an('array');
- expect(post.content).to.be.a('string');
- expect(post.author).to.be.a('string');
- expect(post.postDate).to.be.a('string');
- done();
- }
- });
- });
- });
- var expect =require('chai').expect;
- describe('Init', function(){
- it('starts a new testing env',function(done){
- expect('test').to.equal('test');
- done();
- });
- });
- var expect = require('chai').expect;
- var app = require('../app');
- var request = require('supertest');
- var agent = request.agent(app);
- describe('GET /comments', function () {
- it('should respond with 200 in case of valid request', function (done) {
- agent.get('/posts/565dc4afd40a6e08950b2820/').send().end(function (err, res) {
- if (err) { return done(err); }
- //console.log('res: ', res);
- var fetchData=JSON.parse(res.text);
- expect(fetchData).to.be.an('object');
- expect(fetchData).to.not.empty;
- var comments = fetchData.comments;
- expect(comments).to.be.an('array');
- expect(comments).to.not.empty;
- var comment=comments[0];
- if(comment){
- expect(comment).to.have.all.keys('__v','_id','upvotes','author', 'body','post' ,'downvotes','votes');
- expect(comment.votes).to.be.a('number');
- expect(comment.upvotes).to.be.an('array');
- expect(comment.downvotes).to.be.an('array');
- expect(comment.body).to.be.a('string');
- expect(comment.author).to.be.a('string');
- done();
- }
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment