const expect = require('code').expect;
const lab = exports.lab = require('lab').script();
const fs = require("fs");
var taxiCharger = require("../lib/taxi_charger.js");
var sftp = require("../lib/sftp.js");
var config = require("../config/database.js");
var moment = require("moment");

lab.experiment('zTrip Taxi Charger', { timeout: 10000 }, () => {

    lab.before({ timeout: 500 }, () => {

    });

    lab.after({ timeout: 500 }, () => {

    });

    lab.test('Generate CSV File', async () => {
        var sampleData = [
            {
                VtodTripId: '1234545',
                DispatchTripId: '1234542',
                Gratuity: '2.88',
                GratuityRate: '20',
                FareAmount: '14.4',
                TotalFareAmount: '17.28',
                PickupDateTime: Date.now(),
                ChargeTry: '0',
                ChargeStatus: null,
                PaymentType: 'Cash',
                IsFlatRate: 'False',
                EmailAddress: 'james@knomatic.com',
                FirstName: 'Test,Comma',
                LastName: 'Becwar',
                PhoneNumber: '713-254-7267',
                PickupFullAddress: '1776 St. James Place, Houston, TX 77032',
                PickupAirport: null,
                DropOffFullAddress: null,
                DropOffAirport: null,
                TransactionNumber: null,
                AmountCharged: '0',
                CreditsApplied: '0',
                ChargingException: null,
                DriverID: '12',
                DriverNumber: 'Y50014',
                DriverFirstName: 'Arun',
                DriverLastName: 'Rao'
            }
        ];

        var result = await taxiCharger.generateZtripFile(sampleData);

        
        //fs.writeFileSync("test.csv", result);
        //await sftp.uploadString(config.sftp, "Knomatic" +  moment().format("YYYYMMDD_HHmmss")+".csv", result);



        expect(result).to.contain("1234545");
        expect(result).to.not.contain("Test,Comma");



    });
});