Skip to content

Commit 537e8e7

Browse files
committed
Skip JSON tests on older versions of postgres
1 parent 874c924 commit 537e8e7

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

test/integration/client/json-type-parsing-tests.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@ if (helper.config.binary) {
99
test('can read and write json', function() {
1010
helper.pg.connect(helper.config, function(err, client, done) {
1111
assert.ifError(err);
12-
client.query('CREATE TEMP TABLE stuff(id SERIAL PRIMARY KEY, data JSON)');
13-
var value ={name: 'Brian', age: 250, alive: true, now: new Date()};
14-
client.query('INSERT INTO stuff (data) VALUES ($1)', [value]);
15-
client.query('SELECT * FROM stuff', assert.success(function(result) {
16-
assert.equal(result.rows.length, 1);
17-
assert.equal(typeof result.rows[0].data, 'object');
18-
var row = result.rows[0].data;
19-
assert.strictEqual(row.name, value.name);
20-
assert.strictEqual(row.age, value.age);
21-
assert.strictEqual(row.alive, value.alive);
22-
test('row should have "now" as a date', function() {
23-
return false;
24-
assert(row.now instanceof Date, 'row.now should be a date instance but is ' + typeof row.now);
25-
});
26-
assert.equal(JSON.stringify(row.now), JSON.stringify(value.now));
27-
done();
28-
helper.pg.end();
12+
helper.versionGTE(client, '9.2.0', assert.success(function(jsonSupported) {
13+
if(!jsonSupported) {
14+
console.log('skip json test on older versions of postgres');
15+
done();
16+
return helper.pg.end();
17+
}
18+
client.query('CREATE TEMP TABLE stuff(id SERIAL PRIMARY KEY, data JSON)');
19+
var value ={name: 'Brian', age: 250, alive: true, now: new Date()};
20+
client.query('INSERT INTO stuff (data) VALUES ($1)', [value]);
21+
client.query('SELECT * FROM stuff', assert.success(function(result) {
22+
assert.equal(result.rows.length, 1);
23+
assert.equal(typeof result.rows[0].data, 'object');
24+
var row = result.rows[0].data;
25+
assert.strictEqual(row.name, value.name);
26+
assert.strictEqual(row.age, value.age);
27+
assert.strictEqual(row.alive, value.alive);
28+
test('row should have "now" as a date', function() {
29+
return false;
30+
assert(row.now instanceof Date, 'row.now should be a date instance but is ' + typeof row.now);
31+
});
32+
assert.equal(JSON.stringify(row.now), JSON.stringify(value.now));
33+
done();
34+
helper.pg.end();
35+
}));
2936
}));
3037
});
3138
});

0 commit comments

Comments
 (0)