38
loading...
This website collects cookies to deliver better user experience
function saveData(data, {q = query, con = connect} = {}) {
/**
Call 'q' to execute the db query
Call 'con' to connect to the database
*/
con()
const strQuery = "insert into mydatabase.mytable (data) value ('" + data +"')";
if(q(strQuery)) {
return true;
} else {
return {
error: true,
msg: "There was a problem saving your data"
}
}
}
describe("Unit Test", () => {
it ("should return true if the data is saved into the database", () => {
const result = await saveData('hi there!', {q: () => true, con: () => true})
result.should.be.true;
})
it ("should return an error object if the data is not saved into the database", () => {
const result = await saveData('hi there!', {q: () => false, con: () => true})
result.should.equal({
error: true,
msg: "There was a problem saving your data"
})
})
}
"insert into mydatabase.mytable (data) value ('" + data +"')"
as follows.describe("Integration Test", () => {
it ("should save data in database", () => {
const strQuery = "insert into mydatabase.mytable (data) value ('hello world')"
const result = await query(strQuery)
result.should.be.equal(1);
})
}
Unit tests are made for testing business logic; on the other hand, integration tests are for verifying the external dependencies.