2014-03-31 04:16:27 +08:00
|
|
|
var helper = require(__dirname + '/test-helper');
|
2011-03-02 04:35:14 +08:00
|
|
|
var utils = require(__dirname + "/../../lib/utils");
|
|
|
|
var defaults = require(__dirname + "/../../lib").defaults;
|
2010-10-24 01:42:01 +08:00
|
|
|
|
2014-03-16 04:41:36 +08:00
|
|
|
|
|
|
|
test('ensure types is exported on root object', function() {
|
|
|
|
var pg = require('../../lib')
|
|
|
|
assert(pg.types)
|
|
|
|
assert(pg.types.getTypeParser)
|
|
|
|
assert(pg.types.setTypeParser)
|
|
|
|
})
|
|
|
|
|
2010-10-24 01:42:01 +08:00
|
|
|
//this tests the monkey patching
|
|
|
|
//to ensure comptability with older
|
|
|
|
//versions of node
|
2013-01-18 08:27:48 +08:00
|
|
|
test("EventEmitter.once", function(t) {
|
2010-12-10 08:10:42 +08:00
|
|
|
|
2010-10-24 01:42:01 +08:00
|
|
|
//an event emitter
|
|
|
|
var stream = new MemoryStream();
|
|
|
|
|
|
|
|
var callCount = 0;
|
|
|
|
stream.once('single', function() {
|
|
|
|
callCount++;
|
|
|
|
});
|
2010-12-10 08:10:42 +08:00
|
|
|
|
2010-10-24 01:42:01 +08:00
|
|
|
stream.emit('single');
|
|
|
|
stream.emit('single');
|
|
|
|
assert.equal(callCount, 1);
|
|
|
|
});
|
2010-12-10 08:10:42 +08:00
|
|
|
|
|
|
|
|
2012-12-11 15:23:06 +08:00
|
|
|
test('normalizing query configs', function() {
|
|
|
|
var config
|
2014-03-16 04:36:27 +08:00
|
|
|
var callback = function () {}
|
2012-12-11 15:23:06 +08:00
|
|
|
|
|
|
|
config = utils.normalizeQueryConfig({text: 'TEXT'})
|
2014-03-16 04:36:27 +08:00
|
|
|
assert.same(config, {text: 'TEXT'})
|
2012-12-11 15:23:06 +08:00
|
|
|
|
2014-03-16 04:36:27 +08:00
|
|
|
config = utils.normalizeQueryConfig({text: 'TEXT'}, [10])
|
|
|
|
assert.deepEqual(config, {text: 'TEXT', values: [10]})
|
2012-12-11 15:23:06 +08:00
|
|
|
|
2014-03-16 04:36:27 +08:00
|
|
|
config = utils.normalizeQueryConfig({text: 'TEXT', values: [10]})
|
|
|
|
assert.deepEqual(config, {text: 'TEXT', values: [10]})
|
2012-12-11 15:23:06 +08:00
|
|
|
|
2014-03-16 04:36:27 +08:00
|
|
|
config = utils.normalizeQueryConfig('TEXT', [10], callback)
|
|
|
|
assert.deepEqual(config, {text: 'TEXT', values: [10], callback: callback})
|
2012-12-11 15:23:06 +08:00
|
|
|
|
2014-03-16 04:36:27 +08:00
|
|
|
config = utils.normalizeQueryConfig({text: 'TEXT', values: [10]}, callback)
|
|
|
|
assert.deepEqual(config, {text: 'TEXT', values: [10], callback: callback})
|
2012-12-11 15:23:06 +08:00
|
|
|
})
|
2014-03-31 04:16:27 +08:00
|
|
|
|
|
|
|
test('prepareValues: buffer prepared properly', function() {
|
|
|
|
var buf = new Buffer("quack");
|
|
|
|
var out = utils.prepareValue(buf);
|
|
|
|
assert.strictEqual(buf, out);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prepareValues: date prepared properly', function() {
|
|
|
|
helper.setTimezoneOffset(-330);
|
|
|
|
|
|
|
|
var date = new Date(2014, 1, 1, 11, 11, 1, 7);
|
|
|
|
var out = utils.prepareValue(date);
|
|
|
|
assert.strictEqual(out, "2014-02-01T11:11:01.007+05:30");
|
|
|
|
|
|
|
|
helper.resetTimezoneOffset();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prepareValues: undefined prepared properly', function() {
|
|
|
|
var out = utils.prepareValue(void 0);
|
|
|
|
assert.strictEqual(out, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prepareValue: null prepared properly', function() {
|
|
|
|
var out = utils.prepareValue(null);
|
|
|
|
assert.strictEqual(out, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prepareValue: true prepared properly', function() {
|
|
|
|
var out = utils.prepareValue(true);
|
|
|
|
assert.strictEqual(out, 'true');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prepareValue: false prepared properly', function() {
|
|
|
|
var out = utils.prepareValue(false);
|
|
|
|
assert.strictEqual(out, 'false');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prepareValue: number prepared properly', function () {
|
|
|
|
var out = utils.prepareValue(3.042);
|
|
|
|
assert.strictEqual(out, '3.042');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prepareValue: string prepared properly', function() {
|
|
|
|
var out = utils.prepareValue('big bad wolf');
|
|
|
|
assert.strictEqual(out, 'big bad wolf');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prepareValue: array prepared properly', function() {
|
|
|
|
var out = utils.prepareValue([1, null, 3, undefined, [5, 6, "squ,awk"]]);
|
|
|
|
assert.strictEqual(out, '{1,NULL,3,NULL,{5,6,"squ,awk"}}');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('prepareValue: arbitrary objects prepared properly', function() {
|
|
|
|
var out = utils.prepareValue({ x: 42 });
|
|
|
|
assert.strictEqual(out, '{"x":42}');
|
|
|
|
});
|