From 194fe8a0acbab37e9fdde152c1d58d84c4acc0c1 Mon Sep 17 00:00:00 2001 From: Luca Rainone Date: Tue, 17 Oct 2023 23:39:04 +0200 Subject: [PATCH 1/2] fix: missed await on begin transaction query --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8add88a..1c5162f 100644 --- a/index.js +++ b/index.js @@ -161,7 +161,7 @@ function fastifyPostgres (fastify, options, next) { } } - client.query('BEGIN') + await client.query('BEGIN') } const onError = (req, reply, error, done) => { From 359af9bd30b33e080b7e7d1abddea99ff157242b Mon Sep 17 00:00:00 2001 From: Luca Rainone Date: Tue, 17 Oct 2023 23:40:57 +0200 Subject: [PATCH 2/2] fix: using delete all instead of `TRUNCATE` in order to avoid tests conflicts --- test/req-initialization.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/req-initialization.test.js b/test/req-initialization.test.js index 5bf23e2..5a11b6f 100644 --- a/test/req-initialization.test.js +++ b/test/req-initialization.test.js @@ -16,7 +16,7 @@ test('When we use the fastify-postgres transaction route option', t => { connectionString }) - await fastify.pg.query('TRUNCATE users') + await fastify.pg.query('DELETE FROM "users" WHERE TRUE') fastify.get('/count-users', async (req, reply) => { const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'') @@ -49,7 +49,7 @@ test('When we use the fastify-postgres transaction route option', t => { name: 'test' }) - await fastify.pg.test.query('TRUNCATE users') + await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE') fastify.get('/count-users', async (req, reply) => { const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'') @@ -82,7 +82,7 @@ test('When we use the fastify-postgres transaction route option', t => { connectionString }) - await fastify.pg.query('TRUNCATE users') + await fastify.pg.query('DELETE FROM "users" WHERE TRUE') fastify.get('/count-users', async (req, reply) => { const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'') @@ -117,7 +117,7 @@ test('When we use the fastify-postgres transaction route option', t => { name: 'test' }) - await fastify.pg.test.query('TRUNCATE users') + await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE') fastify.get('/count-users', async (req, reply) => { const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'')