import { DataTable } from '@cucumber/cucumber'; import ContourDataTable from './ContourDataTable'; import scenarioContext from './scenarioContext'; export function generateDocumentSourceJson(dataTable: DataTable, isUpdateFlow = false) { logger.debug(`generateDocumentSourceJson - dataTable: ${JSON.stringify(dataTable, null, 2)}`); const documentSourceJson = []; if (dataTable) { updateDocumentSourceBaseOnDataTable(dataTable, isUpdateFlow, documentSourceJson); } else { documentSourceJson.push({ documentType: 'INVOICE', description: '' }); } logger.debug(`generateDocumentSourceJson - returnJson: ${JSON.stringify(documentSourceJson, null, 2)}`); scenarioContext().dc.documentSourceJson = documentSourceJson; return documentSourceJson; } function updateDocumentSourceBaseOnDataTable(dataTable: DataTable, isUpdateFlow: boolean, documentSourceJson: any[]) { const table = new ContourDataTable(dataTable); logger.debug(`generateDocumentSourceJson - data: ${JSON.stringify(table, null, 2)}`); const colName = isUpdateFlow ? 'updatedValue' : 'value'; documentSourceJson.push({ documentType: 'INVOICE', description: table.getDataOnMatchedRow('field', 'Invoice Description', colName) }); if (table.hashes()['Tick - Certificate of Origin'] != '') { documentSourceJson.push({ documentType: 'CERTIFICATE_OF_ORIGIN', description: table.getDataOnMatchedRow('field', 'Certificate of Origin Description', colName) }); } if (table.hashes()['Tick - Packing List'] != '') { documentSourceJson.push({ documentType: 'PACKING_LIST', description: table.getDataOnMatchedRow('field', 'Packing List Description', colName) }); } if (table.hashes()['Tick - Transport Document'] != '') { const description = table.getDataOnMatchedRow('field', 'Transport Document Description', colName); if (table.hashes()['Select Transport Document'] == 'Bolero electronic bill of lading') { documentSourceJson.push({ documentType: 'TRANSPORT_DOCUMENT_BOLERO', description: description }); } else if (table.hashes()['Select Transport Document'] == 'essDOCS electronic bill of lading') { documentSourceJson.push({ documentType: 'TRANSPORT_DOCUMENT_ESSDOCS', description: description }); } else { documentSourceJson.push({ documentType: 'TRANSPORT_DOCUMENT_OTHER', subtype: table.getDataOnMatchedRow('field', 'Other Transport Document', colName), description: description }); } } }