I basically have an api that writes to 2 different tables, and am using supertest
to make api calls to write a certain data to the database e.g. POST /userCertificates
writes his address in the address table, education in status table like so:
I basically do this as one of the integration tests:
payload = {user_id: 1, name: abc, address: {a: x, b: y}, education: {a: x, b: y} ...}
it('Post to the database'), ()=>{
request.post(/userCertificate).send(payload).expect(200)
.then(res =>
expect(payload.userAddress).toEqual(res.body.userAddress)
// more expects to verify the response received)
}
The /userCertificates api basically does this:
- creates a new user with
name
anduser_id
- saves data of address to the address table and establishes FK relation.
- saves data of education to the education table and establishes FK relation.
But, the real confusion is, do I also need to use a dao layer
that directly talks with the database to absolutely verify that the data has been written to the 2 tables? E.g.
for my case above(in the same describe
block):
NOTE: user_id is a foreign key in the address and education table
it('Verify data written to the address table', ()=> {
const data = AddressDao.find({user_id: 1})
if(data.length <= 0) {
throw 'Data not written to the database
}
}
it('Verify data written to the education table', ()=> {
const data = EducationDao.find({user_id: 1})
if(data.length <= 0) {
throw 'Data not written to the database
}
}
But, not just in the case of writing to multiple tables, is such verification of data written to the database required?