Fake Execution

Test Scenario JavaScript Engine API

The Javascript engine allows you to inject custom Javascript at different steps of a Task execution.

 

Fake Execution

You can toggle the “Fake Execution” mode on each task, which executes your custom Javascript code instead of performing the task as configured. That way, you can mock, for instance, a web service result to quickly develop your test cases, even if the real web service that would be used in tests is not ready to be used yet.

To use Fake Execution, call the “callback(result)” method, providing a string containing the fake result you want your task to have.

For each task type, a default fake execution script is provided. The default scripts are as follows.

 

Send Message Task / Send Task File

This script fakes the task’s execution as if the messages were successfully sent, and the configured connection endpoint returned an HL7-ACK.

callback(`MSH|^~\&|GHH LAB, INC.|GOOD HEALTH HOSPITAL|ADT1|GOOD HEALTH HOSPITAL|20210305104622||ACK^A01^ACK|ACK-MSG00001|T|2.5.1
MSA|AA|MSG00001
`);

 

Receive Message Task / Read File Task

This script fakes the task’s execution as if it received/read the HL7v2 messages provided in the callback method.

callback(`MSH|^~\&|ADT1|GOOD HEALTH HOSPITAL|GHH LAB, INC.|GOOD HEALTH HOSPITAL|198808181126|SECURITY|ADT^A01^ADT_A01|MSG00001|T|2.5.1
EVN||200708181123||
PID|1||PATID1234^5^M11^ADT1^MR^GOOD HEALTH HOSPITAL~123456789^^^USSSA^SS||EVERYMAN^ADAM^A^III||19610615|M||2106-3|2222 HOME STREET^^GREENSBORO^NC^27401-1020
NK1|1|JONES^BARBARA^K|SPO^Spouse^HL70063||||NK^NEXT OF KIN
PV1|1|I|2000^2012^01||||004777^ATTEND^AARON^A|||SUR||||7|A0|
`);

 

Query Database Task

This script fakes a database query result. A JSON Array with 2 entries is provided as a result. This mocks the following dataset

callback(`[
{
"column1": "value 1",
"column2": "value 2"
},
{
"column1": "value 3",
"column2": "value 4"
}
]`);

Column 1 Column 2
Value 1 Value 2
Value 3 Value 3

 

Web Service Task

This script fakes the execution of the task as if an HTTP result is returned. A JSON object is provided, allowing you to mock the HTTP Response Status Code (200, 404, 500) and the response Body. The above script would return an OK – 200 status code with a JSON value in the response body.

callback(`{
"responseStatusCode": "200",
"responseBody": {
"resourceType": "operationOutcome"
},
}`);

HTTP Response Status: 200 (OK)
HTTP Body: { "resourceType": "operationOutcome" }