Testing an MEVN Application Chapter 9
});
});
describe('POST /movies', () => {
it('should respond with the movie that was added', (done) => {
chai.request(server)
.post('/movies')
.send({
name: 'test1',
description: 'test1',
release_year: 2018,
genre: 'test1'
})
.end((err, res) => {
should.not.exist(err);
res.status.should.equal(200);
res.body.should.be.an('object');
res.body.should.include.keys(
'_id', 'name', 'description', 'release_year', 'genre'
);
done();
});
});
});
})
Here, in the preceding code block, what we have done is, for the POST request:
We are sending the POST request with movie parameters: name, description,
release_year, and genre
We had three expectations:
The status of the request should be 200
The request response should be an object
The response should contain all four attributes, along with the ID
of the movie
Now if we run the tests again, they should all pass.
Similarly, we can add tests for other controllers as well.