/**
 * Created by Tony on 2017/9/15.
 */
import test from "tape";
import mongoose from "mongoose";
let config = require("../../../config/config.js");
//config.setupDb(process.env.NODE_ENV);
config.setupDb('qa');
import dbm from "../../../config/db/db_manager";
import mdl from "../../../modules/all_models/tpl_tree_node";
import rttFacade from "../../../modules/reports/facade/rpt_tpl_tree_node_facade";

dbm.connect();

/*
test('测试 - 创建dummy报表树: ', function (t) {
    let tprTplTree = {};
    tprTplTree.compilationId = "598d239605cdd825682925d1";
    tprTplTree.engineerId = 1;
    tprTplTree.userId = -100;
    tprTplTree.properties = [{"isZhaoBiao": false}, {"isBills": true}];
    tprTplTree.name = "重庆市建筑工程";
    tprTplTree.released = true;
    tprTplTree.isDeleted = false;
    tprTplTree.items = [];

    tprTplTree.items.push( {nodeType: 1, refId: -1, name: "【封-1】招标工程量清单", items: null} );
    tprTplTree.items.push( {nodeType: 1, refId: -1, name: "【表-09】分部分项工程/施工技术措施项目清单计价表", items: null} );

    let results = rttFacade.createNewTree(tprTplTree);
    results.then(function(rst) {
        console.log(rst);
        t.pass('just pass!');
        t.end();
    });
});
 //*/

/*
test('测试 - 创建dummy报表树2: ', function (t) {
    let tprTplTree = {};
    tprTplTree.compilationId = "598d239605cdd825682925d1";
    tprTplTree.engineerId = 2;
    tprTplTree.userId = -100;
    tprTplTree.properties = [{"isZhaoBiao": false}, {"isBills": true}];
    tprTplTree.name = "重庆市装饰工程";
    tprTplTree.released = true;
    tprTplTree.isDeleted = false;
    tprTplTree.items = [];

    tprTplTree.items.push( {nodeType: 1, refId: -1, name: "【封-1】招标工程量清单", items: null} );
    tprTplTree.items.push( {nodeType: 1, refId: -1, name: "【表-09】分部分项工程/施工技术措施项目清单计价表", items: null} );

    let results = rttFacade.createNewTree(tprTplTree);
    results.then(function(rst) {
        console.log(rst);
        t.pass('just pass!');
        t.end();
    });
});
//*/

/*
test('测试 - 更新 dummy报表树2: ', function (t) {
    let tprTplTree = {};
    tprTplTree.compilationId = "598d239605cdd825682925d1";
    tprTplTree.engineerId = 2;
    tprTplTree.userId = -100;
    tprTplTree.properties = [{"isZhaoBiao": false}, {"isBills": true}];
    tprTplTree.name = "重庆市装饰工程";
    tprTplTree.released = false;
    tprTplTree.isDeleted = false;
    tprTplTree.items = [];

    tprTplTree.items.push( {nodeType: 1, refId: -1, name: "【封-1】招标工程量清单", items: null} );
    tprTplTree.items.push( {nodeType: 1, refId: -1, name: "【表-09】分部分项工程/施工技术措施项目清单计价表", items: null} );
    tprTplTree.items.push( {nodeType: 1, refId: -1, name: "【表-09-1】分部分项工程/施工技术措施项目清单计价表（一）", items: null} );

    let results = rttFacade.updateTree(tprTplTree.compilationId, tprTplTree.engineerId, tprTplTree.userId, tprTplTree);
    results.then(function(rst) {
        console.log(rst);
        t.pass('just pass!');
        t.end();
    });
});
//*/

/*
test('测试 - 真正删除 dummy报表树2: ', function (t) {
    let results = rttFacade.removeTreePhycically("598d239605cdd825682925d1", 2, -100);
    results.then(function(rst) {
        console.log(rst);
        t.pass('just pass!');
        t.end();
    });
});
//*/

/*
test('测试 - 删除 dummy 报表树: ', function (t) {
    let results = rttFacade.removeTree("598d239605cdd825682925d1", 2, -100, function(err, rst){
        console.log(err);
        console.log(rst);
    });
    results.then(function(err, rst) {
        //mongoose.disconnect();
        t.pass('just pass!');
        t.end();
    });
});
//*/

/*
test('测试 - find dummy 报表树 by ObjectId: ', function (t) {
    let results = rttFacade.findTplTreeByOid("59bb7fbbbe61c629c0b2bea6");
    results.then(function(rst) {
        console.log(rst);
        //mongoose.disconnect();
        t.pass('just pass!');
        t.end();
    });
});
//*/

//*
test('测试 - find dummy 报表树 ', function (t) {
    let results = rttFacade.findTplTree("598d239605cdd825682925d1", [1], [-101]);
    results.then(function(rst) {
        if (rst) {
            console.log('no result');
        } else {
            console.log(rst);
        }
        //mongoose.disconnect();
        t.pass('just pass!');
        t.end();
    });
});
//*/

//*
test('close the connection', function (t) {
    setTimeout(function () {
        mongoose.disconnect();
        t.pass('closing db connection');
        t.end();
    }, 500);
    // mongoose.disconnect();
    // t.pass('closing db connection');
    // t.end();
});
//*/