mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
added test for transactions
This commit is contained in:
parent
55f84924f2
commit
4bda436b2b
48
test/integration/client/transaction-tests.js
Normal file
48
test/integration/client/transaction-tests.js
Normal file
@ -0,0 +1,48 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
|
||||
test('a single connection transaction', function() {
|
||||
var connectionString = helper.connectionString();
|
||||
var sink = new helper.Sink(1, function() {
|
||||
helper.pg.end();
|
||||
});
|
||||
|
||||
helper.pg.connect(connectionString, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
|
||||
client.query('begin');
|
||||
|
||||
var getZed = {
|
||||
text: 'SELECT * FROM person WHERE name = $1',
|
||||
values: ['Zed']
|
||||
};
|
||||
|
||||
test('Zed should not exist in the database', function() {
|
||||
client.query(getZed, assert.calls(function(err, result) {
|
||||
assert.isNull(err);
|
||||
assert.empty(result.rows);
|
||||
}))
|
||||
})
|
||||
|
||||
client.query("INSERT INTO person(name, age) VALUES($1, $2)", ['Zed', 270], assert.calls(function(err, result) {
|
||||
assert.isNull(err)
|
||||
}));
|
||||
|
||||
test('Zed should exist in the database', function() {
|
||||
client.query(getZed, assert.calls(function(err, result) {
|
||||
assert.isNull(err);
|
||||
assert.equal(result.rows[0].name, 'Zed');
|
||||
}))
|
||||
})
|
||||
|
||||
client.query('rollback');
|
||||
|
||||
test('Zed should not exist in the database', function() {
|
||||
client.query(getZed, assert.calls(function(err, result) {
|
||||
assert.isNull(err);
|
||||
assert.empty(result.rows);
|
||||
sink.add();
|
||||
}))
|
||||
})
|
||||
|
||||
}))
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user