Skip to content

Commit 4bda436

Browse files
committed
added test for transactions
1 parent 55f8492 commit 4bda436

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var helper = require(__dirname + '/test-helper');
2+
3+
test('a single connection transaction', function() {
4+
var connectionString = helper.connectionString();
5+
var sink = new helper.Sink(1, function() {
6+
helper.pg.end();
7+
});
8+
9+
helper.pg.connect(connectionString, assert.calls(function(err, client) {
10+
assert.isNull(err);
11+
12+
client.query('begin');
13+
14+
var getZed = {
15+
text: 'SELECT * FROM person WHERE name = $1',
16+
values: ['Zed']
17+
};
18+
19+
test('Zed should not exist in the database', function() {
20+
client.query(getZed, assert.calls(function(err, result) {
21+
assert.isNull(err);
22+
assert.empty(result.rows);
23+
}))
24+
})
25+
26+
client.query("INSERT INTO person(name, age) VALUES($1, $2)", ['Zed', 270], assert.calls(function(err, result) {
27+
assert.isNull(err)
28+
}));
29+
30+
test('Zed should exist in the database', function() {
31+
client.query(getZed, assert.calls(function(err, result) {
32+
assert.isNull(err);
33+
assert.equal(result.rows[0].name, 'Zed');
34+
}))
35+
})
36+
37+
client.query('rollback');
38+
39+
test('Zed should not exist in the database', function() {
40+
client.query(getZed, assert.calls(function(err, result) {
41+
assert.isNull(err);
42+
assert.empty(result.rows);
43+
sink.add();
44+
}))
45+
})
46+
47+
}))
48+
})

0 commit comments

Comments
 (0)