-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
74 lines (64 loc) · 2.11 KB
/
test.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
var timeoutSeconds = 5;
var tid = setTimeout(function() {
throw new Error('Tests did not finish within ' + timeoutSeconds + ' seconds');
}, timeoutSeconds * 1000);
var assert = require('assert');
var async = require('async');
var ok = require('okay');
var pg = require('pg');
var setup = function() {
before(function(done) {
this.client = new pg.Client();
this.client.connect();
var client = this.client;
client.query('CREATE TEMP TABLE floatz(small FLOAT4, big FLOAT8, num NUMERIC)', ok(function(result) {
client.query('INSERT INTO floatz(small, big, num) VALUES($1, $2, $3)', [1.1, '2.2', 3.3], ok(function(result) {
done();
}));
}));
});
};
var teardown = function() {
after(function(done) {
this.client.on('end', done);
this.client.end();
});
};
describe('existing (string) functionality', function() {
setup();
it('returns floats as strings', function(done) {
var client = this.client;
client.query('SELECT * FROM floatz', ok(function(result) {
assert(result, 'should have returned result');
assert(result.rows, 'result should have rows');
assert.equal(result.rows.length, 1, 'should have 1 row but returned ' + result.rows.length);
var row = result.rows.pop();
assert.strictEqual(row.small, '1.1');
assert.strictEqual(row.big, '2.2');
assert.strictEqual(row.num, '3.3');
done();
}));
});
teardown();
});
describe('new (parseFloat) functionality', function() {
before(function() {
//load the pg-parse-float module
require(__dirname)(pg);
});
setup();
it('returns floats as floats', function(done) {
var client = this.client;
client.query('SELECT * FROM floatz', ok(function(result) {
assert(result, 'should have returned result');
assert(result.rows, 'result should have rows');
assert.equal(result.rows.length, 1, 'should have 1 row but returned ' + result.rows.length);
var row = result.rows.pop();
assert.strictEqual(row.small, 1.1);
assert.strictEqual(row.big, 2.2);
assert.strictEqual(row.num, 3.3);
done();
}));
});
teardown();
});