https://cypress.io logo
Quick Question I'm writing API tests. Would it be ...
# best-practices
k
Quick Question I'm writing API tests. Would it be best practice to have UTIL files or call cy.request inside the commands file? Also if I want to use commands file should I call the UTIL file from my commands? So it would be something like this Test file
Copy code
cy.request({
          method: data.POST,
          url: `${resourceEndPoint}${createAcademy}`,
          headers: baseUtils.getAuthorizationHeaderPayload(access_token),
          body: postUtils.getAddAcademyBodyPayload(0, false),
        })
Or does it make more sense Commands file
Copy code
cy.request({
    method: 'POST',
    url: `${resourceEndPoint}${addIndividulaUsers}`,
    headers: {
      Authorization: `Bearer ${accessToken}`,
    },
    body: {
      userCompanyId: userId,
      academyId: academyId,
      status: status,
    },
  }).then((res) => {
    const academyId = res.body;
    cy.wrap(academyId).as('academyId');
  });