I am using mocha, nodejs and pg-promise connecting to a Postgres db. I am wondering how can I unit test a function that executes a DML? This is just a simple example:
export function insertUser(db, { firstName, lastName }) {
db.one(`
INSERT INTO users
(
firstName,
lastName
)
VALUES
(
$<firstName>,
$<lastName>
)
`, { firstName, lastName });
}
If there is a typo in the query, how can the unit test capture it? I can create a test db, creating temporary tables on the fly but this will cause my test to slow down.
it is like testing pg-promise functionality.