Skip to content

Commit d7d188a

Browse files
committed
Added callback test
1 parent 66eee07 commit d7d188a

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

test.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ test('fastify.pg.test should throw with duplicate connection names', t => {
254254
})
255255
})
256256

257-
test('fastify.pg.test use transact util', t => {
257+
test('fastify.pg.test use transact util with promise', t => {
258258
t.plan(3)
259259

260260
const fastify = Fastify()
@@ -293,3 +293,35 @@ test('fastify.pg.test use transact util', t => {
293293
})
294294
})
295295
})
296+
297+
test('fastify.pg.test use transact util with callback', t => {
298+
t.plan(2)
299+
300+
const fastify = Fastify()
301+
302+
fastify.register(fastifyPostgres, {
303+
name: 'test',
304+
connectionString: 'postgres://postgres@localhost/postgres'
305+
})
306+
307+
fastify.ready(err => {
308+
t.error(err)
309+
fastify.pg.test
310+
.query('CREATE TABLE users2(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL)')
311+
.then(function () {
312+
fastify.pg.test
313+
.transact('INSERT INTO users2(username) VALUES($1) RETURNING id', ['brianc'], function (err, res) {
314+
if (err) {
315+
t.fail(err)
316+
fastify.close()
317+
} else {
318+
t.ok(res.rows[0].id === 1)
319+
}
320+
})
321+
})
322+
.catch(err => {
323+
t.fail(err)
324+
fastify.close()
325+
})
326+
})
327+
})

0 commit comments

Comments
 (0)