mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Skip JSON tests on older versions of postgres
This commit is contained in:
parent
874c924f7a
commit
537e8e763e
@ -9,23 +9,30 @@ if (helper.config.binary) {
|
||||
test('can read and write json', function() {
|
||||
helper.pg.connect(helper.config, function(err, client, done) {
|
||||
assert.ifError(err);
|
||||
client.query('CREATE TEMP TABLE stuff(id SERIAL PRIMARY KEY, data JSON)');
|
||||
var value ={name: 'Brian', age: 250, alive: true, now: new Date()};
|
||||
client.query('INSERT INTO stuff (data) VALUES ($1)', [value]);
|
||||
client.query('SELECT * FROM stuff', assert.success(function(result) {
|
||||
assert.equal(result.rows.length, 1);
|
||||
assert.equal(typeof result.rows[0].data, 'object');
|
||||
var row = result.rows[0].data;
|
||||
assert.strictEqual(row.name, value.name);
|
||||
assert.strictEqual(row.age, value.age);
|
||||
assert.strictEqual(row.alive, value.alive);
|
||||
test('row should have "now" as a date', function() {
|
||||
return false;
|
||||
assert(row.now instanceof Date, 'row.now should be a date instance but is ' + typeof row.now);
|
||||
});
|
||||
assert.equal(JSON.stringify(row.now), JSON.stringify(value.now));
|
||||
done();
|
||||
helper.pg.end();
|
||||
helper.versionGTE(client, '9.2.0', assert.success(function(jsonSupported) {
|
||||
if(!jsonSupported) {
|
||||
console.log('skip json test on older versions of postgres');
|
||||
done();
|
||||
return helper.pg.end();
|
||||
}
|
||||
client.query('CREATE TEMP TABLE stuff(id SERIAL PRIMARY KEY, data JSON)');
|
||||
var value ={name: 'Brian', age: 250, alive: true, now: new Date()};
|
||||
client.query('INSERT INTO stuff (data) VALUES ($1)', [value]);
|
||||
client.query('SELECT * FROM stuff', assert.success(function(result) {
|
||||
assert.equal(result.rows.length, 1);
|
||||
assert.equal(typeof result.rows[0].data, 'object');
|
||||
var row = result.rows[0].data;
|
||||
assert.strictEqual(row.name, value.name);
|
||||
assert.strictEqual(row.age, value.age);
|
||||
assert.strictEqual(row.alive, value.alive);
|
||||
test('row should have "now" as a date', function() {
|
||||
return false;
|
||||
assert(row.now instanceof Date, 'row.now should be a date instance but is ' + typeof row.now);
|
||||
});
|
||||
assert.equal(JSON.stringify(row.now), JSON.stringify(value.now));
|
||||
done();
|
||||
helper.pg.end();
|
||||
}));
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user