bbyars / mountebank

Over the wire test doubles
http://www.mbtest.org
MIT License
2k stars 262 forks source link

Copied request object coming back as `[object Object]` #756

Open noel-yap opened 6 months ago

noel-yap commented 6 months ago

Duplicated from https://stackoverflow.com/questions/78044733/how-do-i-copy-a-request-object-to-the-response-in-mountebank

Expected behaviour

Request object properly injected into response. Eg:

{
  "messageHeader": {
    "userId": "USER_ID",
    "orgAlias": "ORG_ALIAS"
  },
}

...

Actual behaviour

String representation of request object injected into response. Eg:

{"messageHeader":"[object Object]"}

...

Steps to reproduce

Use the following stubs config:

const stubs = [
  {
    responses: [
      {
        is: {
          statusCode: 200,
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            messageHeader: "${MESSAGE_HEADER}",
          }),
        },
        _behaviors: {
          copy: [
            {
              from: "body",
              into: "${MESSAGE_HEADER}",
              using: {
                method: "jsonpath",
                selector: "$.messageHeader",
              },
            },
          ],
        },
      },
    ],
  },
];

with the following request:

{
  "messageHeader": {
    "userId": "USER_ID",
    "orgAlias": "ORG_ALIAS"
  },
}

...

Software versions used

OS         : Darwin Kernel Version 23.3.0
mountebank : 2.9.1

Log contents in mb.log when running mb --loglevel debug

{"level":"info","message":"[mb:2525] mountebank v2.9.1 now taking orders - point your browser to http://localhost:2525/ for help","timestamp":"2024-02-23T01:37:56.412Z"}
{"level":"info","message":"[mb:2525] POST /imposters","timestamp":"2024-02-23T01:37:56.439Z"}
{"level":"info","message":"[http:2526 Xifin] Open for business...","timestamp":"2024-02-23T01:37:56.443Z"}
{"level":"info","message":"[http:2526 Xifin] ::1:58532 => POST /test/accession/generatetoken?orgalias=ORG_ALIAS","timestamp":"2024-02-23T01:37:59.192Z"}
{"level":"info","message":"[http:2526 Xifin] ::1:58534 => POST /test/patient/restful/checkPatientEligibility?orgalias=ORG_ALIAS","timestamp":"2024-02-23T01:37:59.403Z"}