Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
muhme opened this issue May 8, 2024 · 5 comments
Closed

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

muhme opened this issue May 8, 2024 · 5 comments

Comments

@muhme
Copy link
Contributor

muhme commented May 8, 2024

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

  • fails on all branches 4.4-dev, 5.1-dev, 5.2-dev and 6.0-dev
  • fails on macOS-local, macOS-docker and ubuntu-docker
  • sometimes means e.g. the second run on ubuntu-docker for 5.1-dev fails even the first run was successful, or that it fails as a single specification but runs in the overall test
  • I will take a look and comment here
  • can anyone else confirm that the error has appeared?
@alikon
Copy link
Contributor

alikon commented May 8, 2024

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
Copy link
Contributor Author

muhme commented May 8, 2024

  • @alikon gave the correct hint there are problems with __menu table 👍
  • the check of the table __menu shows that there is no entry with id 1 and therefore the used parent_id 1 fails, hardwired the parent_id was changed to (at this moment) existing id 2 the test run was successful several times
  • a stable solution would therefore be to initial search for a (e.g. the first) menu item and then use this menu item ID as parent_id

@muhme
Copy link
Contributor Author

muhme commented May 9, 2024

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
Copy link
Contributor

alikon commented May 11, 2024

please test #43456

@alikon alikon closed this as completed May 11, 2024
@muhme
Copy link
Contributor Author

muhme commented May 12, 2024

on fresh macOS-docker-4.4-dev installation

  • tested before the PR:
    • every run of SiteMenuItems.cy.js deletes one more entry from the __menu table, starting with id=1
    • from the 2nd run, the test case can create a site menu item fails because there is no longer a parent menu entry id=1
    • restored entry with:
INSERT INTO `jos44_menu` (`id`, `menutype`, `title`, `alias`, `note`, `path`, `link`, `type`, `published`, `parent_id`, `level`, `component_id`, `checked_out`, `checked_out_time`, `browserNav`, `access`, `img`, `template_style_id`, `params`, `lft`, `rgt`, `home`, `language`, `client_id`, `publish_up`, `publish_down`) VALUES
(1, '', 'Menu_Item_Root', 'root', '', '', '', '', 1, 0, 0, 0, NULL, NULL, 0, 0, '', 0, '', 0, 43, 0, '*', 0, NULL, NULL);
  • applied gh pr checkout 43456
    • checked tests/System/integration/api/com_menus/SiteMenuItems.cy.js has changed to beforeEach
    • multiple runs of SiteMenuItems.cy.js
      • no test failures anymore ✅
      • no __menu entries are deleted ✅
    • overall test run with 110 specs and 435 test cases passed ✅

Thank you for fixing 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants