Skip to content

Commit

Permalink
test(sdk): Add test case for handle error
Browse files Browse the repository at this point in the history
Add new test cases to handle errors from the API in the BPMN.
  • Loading branch information
saig0 committed Feb 4, 2024
1 parent 1cabe5d commit 2b2c1aa
Show file tree
Hide file tree
Showing 4 changed files with 486 additions and 0 deletions.
105 changes: 105 additions & 0 deletions assets/error_expression.feel
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
if matches(error.code, "4\d\d")
then {
error_code: substring after(extract(error.message,"\"code\":\d{4}")[1], ":"),
error_message: substring(extract(error.message, "\"message\":\"(\w|\d|\s|\.|\-)+")[1], 12),
error_code_by_name: {
"4000":"cooldownConflictError",
"4001":"waypointNoAccessError",
"4100":"tokenEmptyError",
"4101":"tokenMissingSubjectError",
"4102":"tokenInvalidSubjectError",
"4103":"missingTokenRequestError",
"4104":"invalidTokenRequestError",
"4105":"invalidTokenSubjectError",
"4106":"accountNotExistsError",
"4107":"agentNotExistsError",
"4108":"accountHasNoAgentError",
"4109":"registerAgentExistsError",
"4110":"registerAgentSymbolReservedError",
"4111":"registerAgentConflictSymbolError",
"4200":"navigateInTransitError",
"4201":"navigateInvalidDestinationError",
"4202":"navigateOutsideSystemError",
"4203":"navigateInsufficientFuelError",
"4204":"navigateSameDestinationError",
"4205":"shipExtractInvalidWaypointError",
"4206":"shipExtractPermissionError",
"4207":"shipJumpNoSystemError",
"4208":"shipJumpSameSystemError",
"4210":"shipJumpMissingModuleError",
"4211":"shipJumpNoValidWaypointError",
"4212":"shipJumpMissingAntimatterError",
"4214":"shipInTransitError",
"4215":"shipMissingSensorArraysError",
"4216":"purchaseShipCreditsError",
"4217":"shipCargoExceedsLimitError",
"4218":"shipCargoMissingError",
"4219":"shipCargoUnitCountError",
"4220":"shipSurveyVerificationError",
"4221":"shipSurveyExpirationError",
"4222":"shipSurveyWaypointTypeError",
"4223":"shipSurveyOrbitError",
"4224":"shipSurveyExhaustedError",
"4225":"shipRefuelDockedError",
"4226":"shipRefuelInvalidWaypointError",
"4227":"shipMissingMountsError",
"4228":"shipCargoFullError",
"4229":"shipJumpFromGateToGateError",
"4230":"waypointChartedError",
"4231":"shipTransferShipNotFound",
"4232":"shipTransferAgentConflict",
"4233":"shipTransferSameShipConflict",
"4234":"shipTransferLocationConflict",
"4235":"warpInsideSystemError",
"4236":"shipNotInOrbitError",
"4237":"shipInvalidRefineryGoodError",
"4238":"shipInvalidRefineryTypeError",
"4239":"shipMissingRefineryError",
"4240":"shipMissingSurveyorError",
"4241":"shipMissingWarpDriveError",
"4242":"shipMissingMineralProcessorError",
"4243":"shipMissingMiningLasersError",
"4244":"shipNotDockedError",
"4245":"purchaseShipNotPresentError",
"4246":"shipMountNoShipyardError",
"4247":"shipMissingMountError",
"4248":"shipMountInsufficientCreditsError",
"4249":"shipMissingPowerError",
"4250":"shipMissingSlotsError",
"4251":"shipMissingMountsError",
"4252":"shipMissingCrewError",
"4253":"shipExtractDestabilizedError",
"4254":"shipJumpInvalidOriginError",
"4255":"shipJumpInvalidWaypointError",
"4256":"shipJumpOriginUnderConstructionError",
"4257":"shipMissingGasProcessorError",
"4258":"shipMissingGasSiphonsError",
"4259":"shipSiphonInvalidWaypointError",
"4260":"shipSiphonPermissionError",
"4261":"waypointNoYieldError",
"4262":"shipJumpDestinationUnderConstructionError",
"4500":"acceptContractNotAuthorizedError",
"4501":"acceptContractConflictError",
"4502":"fulfillContractDeliveryError",
"4503":"contractDeadlineError",
"4504":"contractFulfilledError",
"4505":"contractNotAcceptedError",
"4506":"contractNotAuthorizedError",
"4508":"shipDeliverTermsError",
"4509":"shipDeliverFulfilledError",
"4510":"shipDeliverInvalidLocationError",
"4511":"existingContractError",
"4600":"marketTradeInsufficientCreditsError",
"4601":"marketTradeNoPurchaseError",
"4602":"marketTradeNotSoldError",
"4603":"marketNotFoundError",
"4604":"marketTradeUnitLimitError",
"4700":"waypointNoFactionError",
"4800":"constructionMaterialNotRequired",
"4801":"constructionMaterialFulfilled",
"4802":"shipConstructionInvalidLocationError"
},
bpmn_error_code: get or else(get value(error_code_by_name, error_code), error_code),
bpmnError: bpmnError(bpmn_error_code, error_message)
}.bpmnError
else null
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,48 @@ class ContractsApiTest {
.contains(entry("result", "contract-not-fulfilled"))
}

@Test
fun `should handle BPMN error`() {
// given
client.newDeployResourceCommand()
.addResourceFromClasspath("handle-bpmn-error.bpmn")
.send()
.join()

// when
val processInstanceResult = client.newCreateInstanceCommand()
.bpmnProcessId("handle-bpmn-error")
.latestVersion()
.variables(mapOf("token" to getToken()))
.withResult()
.send()
.join()

// then
assertThat(processInstanceResult.variablesAsMap)
.contains(entry("result", "error-handled"))
}

@Test
fun `should handle invalid token error`() {
// given
client.newDeployResourceCommand()
.addResourceFromClasspath("handle-invalid-token-error.bpmn")
.send()
.join()

// when
val processInstanceResult = client.newCreateInstanceCommand()
.bpmnProcessId("handle-invalid-token-error")
.latestVersion()
.variables(mapOf("token" to getToken()))
.withResult()
.send()
.join()

// then
assertThat(processInstanceResult.variablesAsMap)
.contains(entry("result", "error-handled"))
}

}
Loading

0 comments on commit 2b2c1aa

Please sign in to comment.