import { DataTable } from '@cucumber/cucumber'; import DC_ACTION from '../../enum/dcAction'; import PARTY from '../../enum/party'; import USER_ROLE from '../../enum/userRole'; import envConfig from '../../env/env-config'; import { getNodeProfile } from '../../env/nodeProfile'; import { checkerApproverResponse, isWorkflowReadyForExecution } from '../apiUtil'; import { HTTP_METHOD } from '../httpMethod'; import { makeAuthenticatedRequest } from '../loginUtil'; import scenarioContext from '../scenarioContext'; import { executeDraftAndMapNewId } from '../updateDcId'; import { generateApplicantProceededDc } from './generateApplicantProceededDc'; import { checkForIdentitySwitching } from './multiIdentityUtil'; export async function generateIssuingBankProceededDc( dcScenario: string, action: string = DC_ACTION.ISSUED, proceededUserRoles: string = USER_ROLE.MAKER + '.' + USER_ROLE.CHECKER_APPROVER, attachmentNum = 0, documentSourceDataTable: DataTable = null ) { logger.debug(`generateIssuingBankProceededDc - starting...`); await generateApplicantProceededDc(dcScenario, USER_ROLE.ADMIN1, attachmentNum, documentSourceDataTable); scenarioContext().currentParty = PARTY.ISSUING_BANK; const roles = proceededUserRoles.split('.'); const actionInfoMap = new Map() .set(DC_ACTION.ISSUED, { endPoint: 'locapp/issuer/approve/' + scenarioContext().dc.appRefId, json: { args: { lcReference: envConfig.scenario[dcScenario].issuedLCRef, instructionsToPayingBank: envConfig.scenario[dcScenario].instructionsToPayingBank, clause: { content: envConfig.scenario[dcScenario].clauseContent, attachments: [] } }, draftComment: null } }) .set(DC_ACTION.REJECTED, { endPoint: 'locapp/issuer/reject/' + scenarioContext().dc.appRefId, json: { args: {}, draftComment: null } }); const json = actionInfoMap.get(action).json; const endPoint = actionInfoMap.get(action).endPoint; const issuingNode = scenarioContext().getPartyNode(dcScenario, PARTY.ISSUING_BANK); const nodeProfile = getNodeProfile(issuingNode); await checkForIdentitySwitching(PARTY.ISSUING_BANK, issuingNode, nodeProfile, roles[0]); let dcIssuanceResponse = await makeAuthenticatedRequest( issuingNode, roles[0], endPoint, HTTP_METHOD.PUT, JSON.stringify(json) ); dcIssuanceResponse = isWorkflowReadyForExecution(dcIssuanceResponse) ? dcIssuanceResponse : await checkerApproverResponse(issuingNode, roles[1], dcIssuanceResponse); await executeDraftAndMapNewId(issuingNode, await dcIssuanceResponse.id); }