1
resposta

[Bug] Meu teste de login-api não passa no github actions

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

testes em API
    Testes em rotas com usuário autorizado
      1) "before each" hook for "GET via url front para teste em resposta da home"
    Requisições de usuário clínica em especialistas
      2) "before each" hook for "POSt em especialista"


  0 passing (1s)
  2 failing

  1) testes em API
       Testes em rotas com usuário autorizado
         "before each" hook for "GET via url front para teste em resposta da home":
     CypressError: `cy.request()` failed on:

http://localhost:8080/auth/login

The response we received from your web server was:

  > 500: Internal Server Error

This was considered a failure because the status code was not `2xx` or `3xx`.

If you do not want status codes to cause failures pass the option: `failOnStatusCode: false`

-----------------------------------------------------------

The request we sent was:

Method: POST
URL: http://localhost:8080/auth/login
Headers: {
  "Connection": "keep-alive",
  "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/13.7.2 Chrome/118.0.5993.159 Electron/27.1.3 Safari/537.36",
  "accept": "*/*",
  "accept-encoding": "gzip, deflate",
  "content-type": "application/json",
  "content-length": 47
}
Body: {"email":"clinica@gmail.com","password":"4321"}

-----------------------------------------------------------

The response we got was:

Status: 500 - Internal Server Error
Headers: {
  "x-powered-by": "Express",
  "access-control-allow-origin": "*",
  "content-type": "application/json; charset=utf-8",
  "content-length": "181",
  "etag": "W/\"b5-x9oIfrr3pIq2kwwlcV1K2LilZTI\"",
  "date": "Mon, 06 Oct 2025 03:00:18 GMT",
  "connection": "keep-alive",
  "keep-alive": "timeout=5"
}
Body: {
  "status": 500,
  "message": "Internal server error: The \"password\" argument must be of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView. Received undefined"
}


https://on.cypress.io/request

Because this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `Testes em rotas com usuário...`
      at <unknown> (http://localhost:3000/__cypress/runner/cypress_runner.js:133123:72)
      at tryCatcher (http://localhost:3000/__cypress/runner/cypress_runner.js:1807:23)
      at Promise._settlePromiseFromHandler (http://localhost:3000/__cypress/runner/cypress_runner.js:1519:31)
      at Promise._settlePromise (http://localhost:3000/__cypress/runner/cypress_runner.js:1576:18)
      at Promise._settlePromise0 (http://localhost:3000/__cypress/runner/cypress_runner.js:1621:10)
      at Promise._settlePromises (http://localhost:3000/__cypress/runner/cypress_runner.js:1701:18)
      at _drainQueueStep (http://localhost:3000/__cypress/runner/cypress_runner.js:2407:12)
      at _drainQueue (http://localhost:3000/__cypress/runner/cypress_runner.js:2400:9)
      at Async._drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:2416:5)
      at Async.drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:2286:14)
  From Your Spec Code:
      at ee (webpack://web-ci/./node_modules/cypress-plugin-api/dist/support.js:14:2002)
      at Context.eval (webpack://web-ci/./node_modules/cypress-plugin-api/dist/support.js:14:2181)

  2) testes em API
       Requisições de usuário clínica em especialistas
         "before each" hook for "POSt em especialista":
     CypressError: `cy.request()` failed on:

http://localhost:8080/auth/login

The response we received from your web server was:

  > 500: Internal Server Error

This was considered a failure because the status code was not `2xx` or `3xx`.

If you do not want status codes to cause failures pass the option: `failOnStatusCode: false`

-----------------------------------------------------------

The request we sent was:

Method: POST
URL: http://localhost:8080/auth/login
Headers: {
  "Connection": "keep-alive",
  "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/13.7.2 Chrome/118.0.5993.159 Electron/27.1.3 Safari/537.36",
  "accept": "*/*",
  "accept-encoding": "gzip, deflate",
  "content-type": "application/json",
  "content-length": 47
}
Body: {"email":"clinica@gmail.com","password":"4321"}

-----------------------------------------------------------

The response we got was:

Status: 500 - Internal Server Error
Headers: {
  "x-powered-by": "Express",
  "access-control-allow-origin": "*",
  "content-type": "application/json; charset=utf-8",
  "content-length": "181",
  "etag": "W/\"b5-x9oIfrr3pIq2kwwlcV1K2LilZTI\"",
  "date": "Mon, 06 Oct 2025 03:00:19 GMT",
  "connection": "keep-alive",
  "keep-alive": "timeout=5"
}
1 resposta

Boa tardeO erro mostrado na imagem indica que o teste do Cypress está falhando porque a requisição para http://localhost:8080/auth/login retorna 500 Internal Server Error.
A mensagem principal é:

Internal server error: The "password" argument must be of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView. Received undefined

Isso significa que, no backend, o campo password não está chegando corretamente — provavelmente está vindo undefined.
Esse erro ocorre por dois motivos comuns:

Variáveis de ambiente não configuradas no GitHub Actions
O teste depende de dados como e-mail e senha (clinica@gmail.com, 4321), mas no GitHub Actions essas variáveis podem não estar definidas. Verifique se estão sendo passadas corretamente no arquivo .github/workflows/...yml, por exemplo:

env:
  EMAIL: clinica@gmail.com
  PASSWORD: 4321

E no teste, use-as assim:

cy.request({
  method: 'POST',
  url: 'http://localhost:8080/auth/login',
  body: {
    email: Cypress.env('EMAIL'),
    password: Cypress.env('PASSWORD')
  }
})

Servidor backend não inicializado antes do teste
Se o backend (localhost:8080) não estiver rodando no ambiente do GitHub Actions, a requisição vai falhar.
Nesse caso, é preciso garantir que o serviço seja iniciado antes de rodar o Cypress, por exemplo:

services:
  api:
    image: node:18
    working_dir: /app
    volumes:
      - .:/app
    command: npm start
    ports:
      - 8080:8080