From 9fc4e5e887f6cd7e714696de41f4c529d6ea4360 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Sat, 6 Apr 2013 14:34:16 +0400 Subject: [PATCH] Added datatypes tests --- test/common.batch.js | 1 + test/datatype.test.js | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 test/datatype.test.js diff --git a/test/common.batch.js b/test/common.batch.js index f93f4535..a9aa1764 100644 --- a/test/common.batch.js +++ b/test/common.batch.js @@ -1,3 +1,4 @@ +require('./datatype.test.js'); require('./basic-querying.test.js'); require('./hooks.test.js'); require('./relations.test.js'); diff --git a/test/datatype.test.js b/test/datatype.test.js new file mode 100644 index 00000000..cdc0202f --- /dev/null +++ b/test/datatype.test.js @@ -0,0 +1,58 @@ +var db, Model; +var should = require('should'); + +describe.only('datatypes', function() { + + before(function(done){ + db = getSchema(); + Model = db.define('Model', { + str: String, + date: Date, + num: Number, + bool: Boolean, + list: {type: []}, + }); + db.automigrate(function() { + Model.destroyAll(done); + }); + }); + + it('should keep types when get read data from db', function(done) { + var d = new Date, id; + Model.create({ + str: 'hello', date: d, num: 3, bool: true, list: ['test'] + }, function(err, m) { + should.not.exist(err); + should.exist(m && m.id); + id = m.id; + testFind(testAll); + }); + + function testFind(next) { + Model.find(id, function(err, m) { + should.not.exist(err); + should.exist(m); + m.str.should.be.a('string'); + m.num.should.be.a('number'); + m.bool.should.be.a('boolean'); + m.date.should.be.an.instanceOf(Date); + m.date.toString().should.equal(d.toString(), 'Time must match'); + next(); + }); + } + + function testAll() { + Model.findOne(function(err, m) { + should.not.exist(err); + should.exist(m); + m.str.should.be.a('string'); + m.num.should.be.a('number'); + m.bool.should.be.a('boolean'); + m.date.should.be.an.instanceOf(Date); + m.date.toString().should.equal(d.toString(), 'Time must match'); + done(); + }); + } + }); + +});