forked from brianc/node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevented-api-tests.js
115 lines (107 loc) · 3.43 KB
/
evented-api-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var helper = require(__dirname + "/../test-helper");
var Client = require(__dirname + "/../../lib/native");
var setupClient = function() {
var client = new Client(helper.config);
client.connect();
client.query("CREATE TEMP TABLE boom(name varchar(10), age integer)");
client.query("INSERT INTO boom(name, age) VALUES('Aaron', 26)");
client.query("INSERT INTO boom(name, age) VALUES('Brian', 28)");
return client;
}
//test('connects', function() {
//var client = new Client(helper.config);
//client.connect();
//test('good query', function() {
//var query = client.query("SELECT 1 as num, 'HELLO' as str");
//assert.emits(query, 'row', function(row) {
//test('has integer data type', function() {
//assert.strictEqual(row.num, 1);
//})
//test('has string data type', function() {
//assert.strictEqual(row.str, "HELLO")
//})
//test('emits end AFTER row event', function() {
//assert.emits(query, 'end');
//test('error query', function() {
//var query = client.query("LSKDJF");
//assert.emits(query, 'error', function(err) {
//assert.ok(err != null, "Should not have emitted null error");
//client.end();
//})
//})
//})
//})
//})
//})
test('multiple results', function() {
test('queued queries', function() {
var client = setupClient();
var q = client.query("SELECT name FROM BOOM");
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'Aaron');
assert.emits(q, 'row', function(row) {
assert.equal(row.name, "Brian");
})
})
assert.emits(q, 'end', function() {
test('query with config', function() {
var q2 = client.query({text:'SELECT 1 as num'});
assert.emits(q2, 'row', function(row) {
assert.strictEqual(row.num, 1);
assert.emits(q2, 'end', function() {
client.end();
})
})
})
})
})
})
test('parameterized queries', function() {
test('with a single string param', function() {
var client = setupClient();
var q = client.query("SELECT * FROM boom WHERE name = $1", ['Aaron']);
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'Aaron');
})
assert.emits(q, 'end', function() {
client.end();
});
})
test('with object config for query', function() {
var client = setupClient();
var q = client.query({
text: "SELECT name FROM boom WHERE name = $1",
values: ['Brian']
});
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'Brian');
})
assert.emits(q, 'end', function() {
client.end();
})
})
test('multiple parameters', function() {
var client = setupClient();
var q = client.query('SELECT name FROM boom WHERE name = $1 or name = $2 ORDER BY name', ['Aaron', 'Brian']);
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'Aaron');
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'Brian');
assert.emits(q, 'end', function() {
client.end();
})
})
})
})
test('integer parameters', function() {
var client = setupClient();
var q = client.query('SELECT * FROM boom WHERE age > $1', [27]);
assert.emits(q, 'row', function(row) {
assert.equal(row.name, 'Brian');
assert.equal(row.age, 28);
});
assert.emits(q, 'end', function() {
client.end();
})
})
})