import USER_ROLE from '../enum/userRole'; import { retryWithCondition } from './common'; import { HTTP_METHOD } from './httpMethod'; import * as loginUtil from './loginUtil'; import scenarioContext from './scenarioContext'; function checkRefId(response: any): boolean { logger.info('Checking for valid Amendment Ref ID..'); return checkValidActiveAmmRefId(response); } function checkValidActiveAmmRefId(response: any): boolean { if ( response.active.length == 0 && (response.accepted.length > 0 || response.rejected.length > 0 || response.discarded.length > 0) ) { return true; } if (response.active[0].drafts != null) { return false; } const refId = response.active[0].ref; const amendPos = scenarioContext().amendment.amendPos; logger.info('Current Ref ID: ' + refId); logger.info('Previous Ref ID: ' + scenarioContext().dc.locAmendId[amendPos]); return refId != scenarioContext().dc.locAmendId[amendPos]; } export async function updateAmendmentId(party: string, updatePos: number, responseId: string) { await loginUtil.makeAuthenticatedRequest( party, USER_ROLE.ADMIN1, 'draft/execute/' + responseId, HTTP_METHOD.POST, null ); if (!scenarioContext().dc.locAmendId) { scenarioContext().dc.locAmendId = []; scenarioContext().dc.concludedAmendmentSize = 0; } scenarioContext().amendment.amendPos = updatePos; const responseJson = await retryWithCondition( 15, loginUtil.makeAuthenticatedRequest, [party, USER_ROLE.ADMIN1, `locamend/appLinId/${scenarioContext().dc.uuid}/all`, HTTP_METHOD.GET, null], checkRefId ); const pos = responseJson.active.length - (updatePos - scenarioContext().dc.concludedAmendmentSize) - 1; if (pos >= 0) { scenarioContext().dc.locAmendId[updatePos] = responseJson.active[pos].ref; logger.info('locAmendId[' + updatePos + '] = ' + scenarioContext().dc.locAmendId[updatePos]); } }