Skip to content

Instantly share code, notes, and snippets.

@samlucax
Last active July 15, 2021 17:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samlucax/cc15eb8666a580e3dd239d4d899ca97f to your computer and use it in GitHub Desktop.
Save samlucax/cc15eb8666a580e3dd239d4d899ca97f to your computer and use it in GitHub Desktop.
N1 - Rotas com Mocks

Se você está usando o server & route

// rotas com mocks. 
// Necessário por enquanto, dado que a aplicação demoautomation está instável

cy.server()
cy.route({
  method: 'POST',
  url: '**/api/1/databases/userdetails/collections/newtable?**',
  status: 200,
  response: {}
}).as('postNewtable');

cy.route({
    method: 'POST', 
    url: '**/api/1/databases/userdetails/collections/usertable?**', 
    status: 200, 
    response: {}
  }).as('postUsertable');

cy.route({
  method: 'GET',
  url: '**/api/1/databases/userdetails/collections/newtable?**',
  status: 200,
  response: {}
  }).as('getNewtable');

Se você está usando o Intercept

    // solução proposta por Jaque Nunes, Turma 5 do Agilizei Bootcamp

    cy.intercept('POST', '**/api/1/databases/userdetails/collections/newtable?**', {
      statusCode: 200,
      body: {}
    }).as('postNewtable');

    cy.intercept('POST', '**/api/1/databases/userdetails/collections/usertable?**', {
      statusCode: 200, 
      body: {}
    }).as('postUsertable');

    cy.intercept('GET', '**/api/1/databases/userdetails/collections/newtable?**', {
      statusCode: 200,
      body: {}
    }).as('getNewtable');

Se você está adicionando Asserções, veja as diferenças

Com o server / route:

    cy.wait('@postNewtable').then((resNewtable) => {
      // com o serve / route
      expect(resNewtable.status).to.eq(200)
    })

    cy.wait('@postUsertable').then((resUsertable) => {
      // com o server / route
      expect(resUsertable.status).to.eq(200)
    })

    cy.wait('@getNewtable').then((resNewtable) => {
      // com o server / route
      expect(resNewtable.status).to.eq(200)
    })

Com o intercept :

    cy.wait('@postNewtable').then((resNewtable) => {
      // com o intercept
      expect(resNewtable.response.statusCode).to.eq(200)
    })

    cy.wait('@postUsertable').then((resUsertable) => {
      // com o intercept
      expect(resUsertable.response.statusCode).to.eq(200)
    })

    cy.wait('@getNewtable').then((resNewtable) => {
      // com o intercept
      expect(resNewtable.response.statusCode).to.eq(200)
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment