<commit_before>require("should");
var SpinningSalesContract = require("../../data-util/sales/spinning-sales-contract-data-util");
var helper = require("../../helper");
var validate = require("dl-models").validator.sales.spinningSalesContract;
var moment = require('moment');

var SpinningSalesContractManager = require("../../../src/managers/sales/spinning-sales-contract-manager");
var spinningSalesContractManager = null;


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

var createdId;
it("#01. should success when create new data", function (done) {
    SpinningSalesContract.getNewData()
        .then((data) => spinningSalesContractManager.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) {
    spinningSalesContractManager.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.buyerId = createdData.buyerId;
    info.comodityId = createdData.comodityId;
    info.salesContractNo = createdData.salesContractNo;
    info.dateFrom = createdData._createdDate;
    info.dateTo = createdData._createdDate;

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


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

    spinningSalesContractManager.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) {
    spinningSalesContractManager.destroy(createdData._id)
        .then((result) => {
            result.should.be.Boolean();
            result.should.equal(true);
            done();
        })
        .catch((e) => {
            done(e);
        });
});<commit_msg>update spinning sales contract report unit test<commit_after>require("should");
var SpinningSalesContract = require("../../data-util/sales/spinning-sales-contract-data-util");
var helper = require("../../helper");
var validate = require("dl-models").validator.sales.spinningSalesContract;
var moment = require('moment');

var SpinningSalesContractManager = require("../../../src/managers/sales/spinning-sales-contract-manager");
var spinningSalesContractManager = 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 => {
            spinningSalesContractManager = new SpinningSalesContractManager(db, {
                username: 'dev'
            });
            done();
        })
        .catch(e => {
            done(e);
        });
});

var createdId;
it("#01. should success when create new data", function (done) {
    SpinningSalesContract.getNewData()
        .then((data) => spinningSalesContractManager.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) {
    spinningSalesContractManager.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.buyerId = createdData.buyerId;
    info.comodityId = createdData.comodityId;
    info.salesContractNo = createdData._id;
    info.dateFrom = createdData._createdDate;
    info.dateTo = createdData._createdDate;

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


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

    spinningSalesContractManager.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) {
    spinningSalesContractManager.destroy(createdData._id)
        .then((result) => {
            result.should.be.Boolean();
            result.should.equal(true);
            done();
        })
        .catch((e) => {
            done(e);
        });
});

{'fraction_non_alphanumeric': 0.1439319594373569, 'fraction_numerical': 0.004252535165194635, 'mean_word_length': 2.259594882729211, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1360167', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1677, 'n_words': 320}