I am working on node js rest api in which database is Postgres and we are not using any ORM. How I am writing is as below which is hitting database for create and update
it('it should create customer', (done) => {
const payload = {
customerId: "test",
customerName: "test",
customerAddress: "Some place, NWZ"
}
chai
.request(server)
.post('/customer')
.send(payload)
.end((err, res) => {
res.should.have.status(200);
res.body.success.should.equal(true);
done();
});
});
Now I want to know that what is best way to write unit test cases ? Like
- Should I write unit test cases by mocking api response excluding database query ?
- Or should I write unit test case which will hit database ?
Or in any way we can mock database ? What is best way to do it ?