require("should");
var FabricQualityControl = require('../../../data-util/production/finishing-printing/fabric-quality-control-data-util');
var helper = require("../../../helper");
var validate = require("dl-models").validator.production.finishingPrinting.qualityControl.defect.fabricQualityControl;
var moment = require('moment');

var FabricQualityControlManager = require("../../../../src/managers/production/finishing-printing/fabric-quality-control-manager");
var fabricQualityControlManager = null;

//delete unitest data
// var DLModels = require('dl-models');
// var map = DLModels.map;
// var MachineType = DLModels.master.MachineType;


before('#00. connect db', function (done) {
    helper.getDb()
        .then((db) => {
            fabricQualityControlManager = new FabricQualityControlManager(db, {
                username: 'dev'
            });
            done();
        })
        .catch(e => {
            done(e);
        });
});

var createdId;
it("#01. should success when create new data", function (done) {
    FabricQualityControl.getNewData()
        .then((data) => fabricQualityControlManager.create(data))
        .then((id) => {
            id.should.be.Object();
            createdId = id;
            done();
        })
        .catch((e) => {
            done(e);
        });
});

var createdData;
it(`#02. should success when get created data with id`, function (done) {
    fabricQualityControlManager.getSingleById(createdId)
        .then((data) => {
            data.should.instanceof(Object);
            validate(data);
            createdData = data;
            done();
        })
        .catch((e) => {
            done(e);
        });
});


var resultForExcelTest = {};
it('#03. should success when create report', function (done) {
    var info = {};
    info.kanbanCode = createdData.kanbanCode;
    info.productionOrderNo = createdData.productionOrderNo;
    info.productionOrderType = createdData.productionOrderType;
    info.shiftIm = createdData.shiftIm;
    info.dateFrom = moment(createdData.dateIm).format("YYYY-MM-DD");
    info.dateTo = moment(createdData.dateIm).format("YYYY-MM-DD");

    fabricQualityControlManager.getReport(info)
        .then(result => {
            resultForExcelTest = result;
            var fabricQualityControl = result.data;
            fabricQualityControl.should.instanceof(Array);
            fabricQualityControl.length.should.not.equal(0);
            done();
        }).catch(e => {
            done(e);
        });
});


it('#04. should success when get data for Excel Report', function (done) {
    var query = {};

    fabricQualityControlManager.getXls(resultForExcelTest, query)
        .then(xlsData => {
            xlsData.should.have.property('data');
            xlsData.should.have.property('options');
            xlsData.should.have.property('name');
            done();
        }).catch(e => {
            done(e);
        });
});


it("#05. should success when destroy all unit test data", function (done) {
    fabricQualityControlManager.destroy(createdData._id)
        .then((result) => {
            result.should.be.Boolean();
            result.should.equal(true);
            done();
        })
        .catch((e) => {
            done(e);
        });
});
@@ -2138,16 +2138,439 @@
 MM-DD%22);
+%0A    info.select = %5B%22code%22, %22kanbanCode%22, %22cartNo%22, %22productionOrderType%22, %22productionOrderNo%22, %22dateIm%22, %22shiftIm%22, %22operatorIm%22, %22machineNoIm%22, %22construction%22, %22buyer%22, %22color%22, %22orderQuantity%22, %22packingInstruction%22, %22fabricGradeTests.pcsNo%22, %22fabricGradeTests.initLength%22, %22fabricGradeTests.width%22, %22fabricGradeTests.finalScore%22, %22fabricGradeTests.grade%22, %22fabricGradeTests.avalLength%22, %22fabricGradeTests.sampleLength%22%5D;
 %0A%0A    fa

update fabric qc report