samedi 10 avril 2021

Cypress: intercepting registration response

So, I need to intercept the registration request. I need the response body to be a user object but also I need an authorization token which is sent as response.headers.authorization. The code looks something like this:

cy.intercept(`${Cypress.env('apiUrl')}/users`, { fixture: 'registrationResponse.json' });

fixtures/registrationResponse:

{
  "id": 83,
  "email": "john.doe@gmail.com",
  "created_at": "2021-04-08T18:00:22.235Z",
  "updated_at": "2021-04-08T18:00:22.235Z",
  "role": "user",
  "first_name": "John",
  "last_name": "Doe",
  "phone": null
}

I am able to mock the response body but I am not sure where should I put my headers object. I started learning Cypress a few days ago so this probably sounds extremely stupid.

Aucun commentaire:

Enregistrer un commentaire