Created
          May 6, 2021 16:09 
        
      - 
      
- 
        Save iDVB/4c77f2160bbd6ff35067e6fd7cf647a5 to your computer and use it in GitHub Desktop. 
    Cypress Recursive Request
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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