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

How can I follow redirects? #97

Open
partounian opened this issue May 16, 2017 · 2 comments
Open

How can I follow redirects? #97

partounian opened this issue May 16, 2017 · 2 comments

Comments

@partounian
Copy link

For example, I am trying to follow a request which gets redirect to Amazon and few other places then finishes. How can I follow the hops to test them each?

@dareid
Copy link
Owner

dareid commented May 16, 2017

Request has some options regarding following redirects, see followRedirect and followAllRedirects on https://github.com/request/request#requestoptions-callback. These can be configured to seemlessly follow all redirects, or follow no redirects allowing you to test each response then manually performing the redirect

@partounian
Copy link
Author

partounian commented May 17, 2017

@dareid Sorry should've phrased the question better, it does, by default, follow the hops and show them, but I can't seem to test the redirect/request/response along the way.

For example,

    it('should upload a user photo', () => {
      let headers = auth.headers;
      return chakram.put(apiPhotoUrl, photo, { json: false, headers })
        .then((putResponse) => {
          expect(putResponse).to.have.status(200);
          //  This part needs to be modified to follow hops. 
          chakram.startDebug();
          return chakram.get(apiPhotoUrl, auth);
        })
        .then((redirect) => {
          expect(redirect).to.redirect;
        })
        .then((getResponse) => {
          expect(getResponse).to.have.status(200);
          expect(getResponse.body).to.equal(photo);
        });
    });

The apiPhotoUrl line will send the request, then I get a redirect, then a request, and finally a response. How can I test the final response? Currently the getResponse results in an error saying it's undefined. I know I should have a return right before it, but I'm not sure what to return.

PS: Also thanks for your amazing REST test suite

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

2 participants