Skip to content

Instantly share code, notes, and snippets.

@iDVB
Created May 6, 2021 16:09
Show Gist options
  • Save iDVB/4c77f2160bbd6ff35067e6fd7cf647a5 to your computer and use it in GitHub Desktop.
Save iDVB/4c77f2160bbd6ff35067e6fd7cf647a5 to your computer and use it in GitHub Desktop.
Cypress Recursive Request
const reqHSContactByEmail = async (email, retryNum = 0) => {
expect(retryNum).to.be.lessThan(10)
return cy
.request({
url: `${HUBSPOT_CONTACT_API(email)}?hapikey=${Cypress.env(
'HUBSPOT_API_KEY'
)}`,
failOnStatusCode: false,
})
.then((resp) => {
if (resp.status === 200 || resp.status !== 404) {
cy.log(`Found it and now call process on it`)
const vid = resp?.body?.vid
expect(vid).to.exist
return vid
} else {
cy.log('Did not find it, waiting to try again')
cy.wait(1000)
reqHSContactByEmail(email, retryNum + 1)
}
})
}
Cypress.Commands.add('getHSContactByEmail', (email) => {
reqHSContactByEmail(email)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment