/**
 * Created by Tony on 2017/3/30.
 */
var test = require('tape');
var mongoose = require('mongoose');
var dbm = require("../../../config/db/db_manager");
var smartcostdb = dbm.getLocalConnection("Demo");
var Schema = mongoose.Schema;
var DecSchema = new Schema({
    "id" : Number,
    "name" : String,
    "value" : Schema.Types.Decimal128
});

var DouSchema = new Schema({
    "id" : Number,
    "name" : String,
    "value" : Number
});

var Dec = smartcostdb.model("dec_tests", DecSchema);
var Dou = smartcostdb.model("dou_tests", DouSchema);

test('try to save decimal: ', function (t) {
        new Dec({id: 2, name:"save decimal new model", value: "2.0999"}).save(function(err){
            console.log("err:" + err);
            t.equal(err == null, true);
            t.end();
        });
    }
);

test('test decimal: ', function (t) {
        Dec.find( {}, function(err, result) {
            console.log(result);
            t.equal(result != null, true);
            t.end();
        });
    }
);

test('test double: ', function (t) {
        Dou.find( {}, function(err, result) {
            console.log(result);
            t.equal(result != null, true);
            t.end();
        });
    }
);

test('finish', function (t) {
    mongoose.disconnect();
    t.pass('closing db connection');
    t.end();
});