joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.69k stars 3.63k forks source link

Sometimes system test SiteMenuItems fails from API with 400 Bad Request #43441

Closed muhme closed 1 month ago

muhme commented 2 months ago

Steps to reproduce the issue

npm run cypress:run -- --spec 'tests/System/integration/api/com_menus/SiteMenuItems.cy.js'

Expected result

all 6 tests are successfull

Actual result

the one test 'can create a site menu item' fails with 'Status: 400 - Bad Request'

System information (as much as possible)

  1 failing

  1) Test that menu items site API endpoint
       can create a site menu item:
     CypressError: `cy.request()` failed on:

http://localhost:8080/api/index.php/v1/menus/site/items

The response we received from your web server was:

  > 400: Bad Request

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/api/index.php/v1/menus/site/items
Headers: {
  "Connection": "keep-alive",
  "Authorization": "Bearer c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==",
  "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/13.2.0 Chrome/114.0.5735.289 Electron/25.8.0 Safari/537.36",
  "accept": "*/*",
  "accept-encoding": "gzip, deflate",
  "content-type": "application/json",
  "content-length": 268
}
Body: {"title":"automated test site menu item","menutype":"main-menu","access":"1","parent_id":"1","publish_down":"","publish_up":"","published":"1","template_style_id":"0","toggle_modules_assigned":"1","toggle_modules_published":"1","type":"component","alias":"","link":""}

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

The response we got was:

Status: 400 - Bad Request
Headers: {
  "date": "Wed, 08 May 2024 05:43:31 GMT",
  "server": "Apache/2.4.59 (Unix) PHP/8.3.6",
  "x-powered-by": "JoomlaAPI/1.0",
  "x-frame-options": "SAMEORIGIN",
  "referrer-policy": "strict-origin-when-cross-origin",
  "cross-origin-opener-policy": "same-origin",
  "expires": "Wed, 17 Aug 2005 00:00:00 GMT",
  "last-modified": "Wed, 08 May 2024 05:43:31 GMT",
  "cache-control": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
  "pragma": "no-cache",
  "content-length": "156",
  "connection": "close",
  "content-type": "application/vnd.api+json; charset=utf-8"
}
Body: {
  "errors": [
    {
      "title": "Save failed with the following error: Joomla\\Component\\Menus\\Administrator\\Table\\MenuTable::_getNode(1, id) failed.",
      "code": 400
    }
  ]
}

https://on.cypress.io/request
      at <unknown> (http://localhost:8080/__cypress/runner/cypress_runner.js:133013:72)
      at tryCatcher (http://localhost:8080/__cypress/runner/cypress_runner.js:1807:23)
      at Promise._settlePromiseFromHandler (http://localhost:8080/__cypress/runner/cypress_runner.js:1519:31)
      at Promise._settlePromise (http://localhost:8080/__cypress/runner/cypress_runner.js:1576:18)
      at Promise._settlePromise0 (http://localhost:8080/__cypress/runner/cypress_runner.js:1621:10)
      at Promise._settlePromises (http://localhost:8080/__cypress/runner/cypress_runner.js:1701:18)
      at _drainQueueStep (http://localhost:8080/__cypress/runner/cypress_runner.js:2407:12)
      at _drainQueue (http://localhost:8080/__cypress/runner/cypress_runner.js:2400:9)
      at Async._drainQueues (http://localhost:8080/__cypress/runner/cypress_runner.js:2416:5)
      at Async.drainQueues (http://localhost:8080/__cypress/runner/cypress_runner.js:2286:14)
  From Your Spec Code:
      at Context.eval (webpack://joomla/./tests/System/support/commands/api.js:8:92)

Additional comments

alikon commented 2 months ago

i was able to reproduce on 2nd run ": "Save failed with the following error: Joomla\\Component\\Menus\\Administrator\\Table\\MenuTable::_getNode(1, id) failed.",

and the #__menu table is messed up for lft, rgt

muhme commented 2 months ago
muhme commented 2 months ago

But the more important question is, why is the so importand looking __menu entry id=1 title=Menu_Item_Root alias=root deleted in a fresh instance with running only sytem tests? The obvious suspect is the test case can delete a site menu item in the same file. And with this question, the approach of getting the first menu entry and using its id sound more like a work around and does not fix the main cause that menu entry #1 being deleted.

alikon commented 1 month ago

please test #43456

muhme commented 1 month ago

on fresh macOS-docker-4.4-dev installation

Thank you for fixing 😄