var testForTypeCoercion = function (type) { const pool = new pg.Pool() suite.test(`test type coercion ${type.name}`, (cb) => { pool.connect(function (err, client, done) { assert(!err) client.query('create temp table test_type(col ' + type.name + ')', assert.calls(function (err, result) { assert(!err) type.values.forEach(function (val) { var insertQuery = client.query('insert into test_type(col) VALUES($1)', [val], assert.calls(function (err, result) { assert(!err) })) var query = client.query(new pg.Query({ name: 'get type ' + type.name, text: 'select col from test_type' })) query.on('error', function (err) { console.log(err) throw err }) assert.emits(query, 'row', function (row) { var expected = val + ' (' + typeof val + ')' var returned = row.col + ' (' + typeof row.col + ')' assert.strictEqual(row.col, val, 'expected ' + type.name + ' of ' + expected + ' but got ' + returned) }, 'row should have been called for ' + type.name + ' of ' + val) client.query('delete from test_type') }) client.query('drop table test_type', function () { done() pool.end(cb) }) })) }) }) }
'use strict' var helper = require(__dirname + '/test-helper') var pg = helper.pg var sink const suite = new helper.Suite() var testForTypeCoercion = function (type) { const pool = new pg.Pool() suite.test(`test type coercion ${type.name}`, (cb) => { pool.connect(function (err, client, done) { assert(!err) client.query('create temp table test_type(col ' + type.name + ')', assert.calls(function (err, result) { assert(!err) type.values.forEach(function (val) { var insertQuery = client.query('insert into test_type(col) VALUES($1)', [val], assert.calls(function (err, result) { assert(!err) })) var query = client.query(new pg.Query({ name: 'get type ' + type.name, text: 'select col from test_type' })) query.on('error', function (err) { console.log(err) throw err }) assert.emits(query, 'row', function (row) { var expected = val + ' (' + typeof val + ')'