Nanciee/cypress-autorecord

Does this handle multiple calls to the same url/method with different responses in the right order?

Closed this issue · 6 comments

How best to record and play back in order, multiple calls to the same url/method?

Also, how does this project relate/compare to and I wonder if any can handle the above.

From my testing, if called url/method called 3 times, it records 3 records, but only returns the last one 3 times during playback.

  1. https://github.com/scottschafer/cypressautomocker (also seemed to have problem with multiple calls to same order and required registration of lib in target app)

  2. https://medium.com/ax2-inc/dynamic-xhr-responses-recording-stubbing-with-cypress-9257d4f730cd (the comment section led me here, repo https://github.com/ax2inc/cypress-xhr-responses-recording)

  3. https://github.com/Cloudo/cy-auto-stub/blob/master/src/commands.js (author said in this repo they were unsuccessful 9 days ago?)

  4. https://github.com/PinkyJie/cypress-auto-stub-example (author of above #3 was inspired by this one?)

This is automatically taken care of by this plugin! I commented about it in detail in issue #5. It records each call separately and should return them in the correct order it was initially recorded in. In the issue I mentioned above, I tested this out by hitting the same login api twice, first time with false credentials and second time with real credentials.

This is what my passing test looked like:
61165421-54991100-a4ee-11e9-85f1-7de5c8db824e

This is what my recording looked like:

 {
      "url": "https://conduit.productionready.io/api/users/login",
      "method": "POST",
      "status": 422,
      "body": {
        "user": {
          "email": "asdfasdf",
          "password": "asfasdf"
        }
      },
      "response": {
        "errors": {
          "email or password": [
            "is invalid"
          ]
        }
      }
    },
    {
      "url": "https://conduit.productionready.io/api/users/login",
      "method": "POST",
      "status": 200,
      "body": {
        "user": {
          "email": "test@test.com",
          "password": "12345678"
        }
      },
      "response": {
        "user": {
          "id": 59968,
          "email": "test@test.com",
          "createdAt": "2019-07-05T02:34:20.846Z",
          "updatedAt": "2019-07-05T02:34:20.854Z",
          "username": "nancy",
          "bio": null,
          "image": null,
          "token": "..."
        }
      }
    },

You can see in the playback that it is returning the 422 response and then the 200 the two times I'm hitting /api/users/login.

If this is not what you are seeing in your own tests, could you provide me with your test details so I can try to debug this?

As for the other plugins, I haven't really used any of them before. I initially tried to use cypressautomocker but wasn't able to get it up and running in an Angular application. I saw the blog post you mentioned on medium and it is what inspired me to build this out!

Would it still work if they were GETs instead of POSTs? The 3 calls I have are GETs, and it returns the 3rd one for all 3 calls. I don't have anything to send right this moment. thanks!

UPDATE: it works for my 2 POST login call when I fail and the successfully sign in. So wondering still if it's related to the GET method...

Is it because line 100 checks for request.body value before pushing into sortedRoutes[request.url]?

if (request.body) {

Thanks for contributing!! I published the changes in in v1.0.13, could you double check that this fixes your issue before I close this bug off?

I am traveling for the next couple of weeks. No access to test currently. FYI

no problem! I'll close this for now and will reopen if you still see an issue!