diff --git a/test/integration/client/api-tests.js b/test/integration/client/api-tests.js index c4d6eea3..0df7acfb 100644 --- a/test/integration/client/api-tests.js +++ b/test/integration/client/api-tests.js @@ -8,30 +8,44 @@ var preparedCalled = false pg.connect(helper.args, function(err, client) { connected = true test('error is null', function() { - assert.equal(err, null) + assert.equal(err, null); }) + client.query('CREATE TEMP TABLE band(name varchar(100))'); + + ['the flaming lips', 'wolf parade', 'radiohead', 'bright eyes', 'the beach boys', 'dead black hearts'].forEach(function(bandName) { + client.query("INSERT INTO band (name) VALUES ('"+ bandName +"')") + }); + + test('simple query execution', function() { - client.query('CREATE TEMP TABLE band(name varchar(100))') - client.query("INSERT INTO band (name) VALUES ('dead black hearts')") - client.query("SELECT * FROM band WHERE name = 'dead black hearts'", function(err, result) { + client.query("SELECT * FROM band WHERE name = 'the beach boys'", function(err, result) { simpleCalled = true - assert.equal(result.rows.pop().name, 'dead black hearts') - }) + assert.length(result.rows, 1) + assert.equal(result.rows.pop().name, 'the beach boys') + }); + }) test('prepared statement execution', function() { client.query('SELECT * FROM band WHERE name = $1', ['dead black hearts'], function(err, result) { - preparedCalled = true - assert.equal(result.rows.pop().name, 'dead black hearts') + preparedCalled = true; + assert.length(result.rows, 1); + assert.equal(result.rows.pop().name, 'dead black hearts'); + }) + + client.query('SELECT * FROM band WHERE name LIKE $1 ORDER BY name', ['the %'], function(err, result) { + assert.length(result.rows, 2); + assert.equal(result.rows.pop().name, 'the flaming lips'); + assert.equal(result.rows.pop().name, 'the beach boys'); }) }) }) process.on('exit', function() { - assert.ok(connected, 'never connected') - assert.ok(simpleCalled, 'query result callback was never called') - assert.ok(preparedCalled, 'prepared callback was never called') + assert.ok(connected, 'never connected'); + assert.ok(simpleCalled, 'query result callback was never called'); + assert.ok(preparedCalled, 'prepared callback was never called'); }) test('raises error if cannot connect', function() {