Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing return of embedded promise into retrieveRecordedRequestAndResponses #172

Open
brcros opened this issue May 26, 2023 · 0 comments
Open

Comments

@brcros
Copy link

brcros commented May 26, 2023

Describe the issue
When calling retrieveRecordedRequestsAndResponses and trying to out the result from the promise, the data remains unchanged, due to inverted execution code ( classic promise issue ).

What you are trying to do
Trying to out the result from the promise...

MockServer version
5.15.0

To Reproduce
try this code :

  let records: HttpRequestAndHttpResponse[] = [];
  await mockServerClient("localhost", 1080)
    .retrieveRecordedRequestsAndResponses({})
    .then((rs: HttpRequestAndHttpResponse[]) => {
      console.log('Inside, my data are there : ' + JSON.stringify(rs));
      records = rs;
    });
  console.log('Outside, my data array is empty :-( ' + JSON.stringify(records));
  1. How you are running MockServer (i.e maven plugin, docker, etc)
    in an express instance (but not related to the bug)
  2. Code you used to create expectations
    there is no expectations, only recording requests and trying to get them after
  3. What error you saw
    no error ( but .catch does related to the missing return )

Expected behaviour
The recordedRequestAndResponses behaves as the others functions, regarding promise execution. Then the result to be passed outside the promise of my call.

** Fix proposed **
Simply add return into retrieveRecordedRequestsAndResponses for the makeRequest call, as the other functions have.

      var retrieveRecordedRequestsAndResponses = function (pathOrRequestMatcher) {
            return {
                then: function (sucess, error) {
                    return makeRequest(host, port, "/mockserver/retrieve?type=REQUEST_RESPONSES&format=JSON", addDefaultRequestMatcherHeaders(pathOrRequestMatcher))
                        .then(function (result) {
                            sucess(result.body && JSON.parse(result.body));
                        }, function (err) {
                            error(err);
                        });
                }
            };
        };```


Thank you
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant