var helper = require("../../../helper");
var Manager = require("../../../../src/etl/garment/garment-purchase-request-etl-manager");
var instanceManager = null;
var should = require("should");
var sqlHelper = require("../../../sql-helper");

var garmentPurchaseRequestDataUtil = require("../../../data-util/garment-purchasing/etl/etl-garment-purchase-request-data-util");

before("#00. connect db", function (done) {
    Promise.all([helper, sqlHelper])
        .then((result) => {
            var db = result[0];
            var sql = result[1];
            db.getDb().then((db) => {
                instanceManager = new Manager(db, {
                    username: "unit-test"
                }, sql);
                done();
            })
                .catch((e) => {
                    done(e);
                })
        });
});


// var extractedData;
// it("#01. should success when extract all data", function (done) {
//     var table1 = "Budget1";
//     var table2 = "POrder1";
//     // var table1 = "Budget";
//     // var table2 = "POrder";
//     instanceManager.extract(table1, table2)
//         .then((result) => {
//             extractedData = result;
//             extractedData.should.instanceof(Array);
//             extractedData.length.should.not.equal(0);
//             done();
//         })
//         .catch((e) => {
//             console.log(e);
//             done(e);
//         });
// });

var transfrom;
it("#02. should success when transfrom all data", function (done) {
    garmentPurchaseRequestDataUtil.getNewData()
        .then((data) => instanceManager.transform(data))
        .then((result) => {
            transfrom = result;
            transfrom.should.instanceof(Array);
            transfrom.length.should.not.equal(0);
            done();

        })
        .catch((e) => {
            console.log(e);
            done(e);
        });
});

it("#03. should success when load all data", function (done) {
    instanceManager.load(transfrom)
        .then((result) => {

            var data = result;
            data.should.instanceof(Array);
            data.length.should.not.equal(0);
            done();

        })
        .catch((e) => {
            console.log(e);
            done(e);
        });
});

// it("#04. should success migrate all data", function (done) {
//     var table1 = "Budget1";
//     var table2 = "POrder1";
//     // var table1 = "Budget";
//     // var table2 = "POrder";
//     instanceManager.run(table1, table2)
//         .then((result) => {

//             var results = result;
//             results.should.instanceof(Object);
//             done();

//         })
//         .catch((e) => {
//             console.log(e);
//             done(e);
//         });
// });


@@ -1431,25 +1431,29 @@
 var 
+ex
 tra
-nsfrom
+ctedData
 ;%0Ait(%22#0
 2. s
@@ -1448,17 +1448,17 @@
 ;%0Ait(%22#0
-2
+1
 . should
@@ -1471,25 +1471,23 @@
 ss when 
+ex
 tra
-nsfrom
+ct
  all dat
@@ -1504,24 +1504,25 @@
 on (done) %7B%0A
+%0A
     garmentP
@@ -1576,16 +1576,370 @@
 en((
-data) =%3E
+result) =%3E %7B%0A            extractedData = result;%0A            extractedData.should.instanceof(Array);%0A            extractedData.length.should.not.equal(0);%0A            done();%0A        %7D)%0A        .catch((e) =%3E %7B%0A            console.log(e);%0A            done(e);%0A        %7D);%0A%7D);%0A%0Avar transfrom;%0Ait(%22#02. should success when transfrom all data%22, function (done) %7B%0A   
  ins
@@ -1965,14 +1965,22 @@
 orm(
-d
+extractedD
 ata)
-)
 %0A   

update garment purchase request etl