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

Testing the hello endpoint will fail due to 403 #1939

Closed
Tracked by #1940
Jeff-Tian opened this issue Dec 4, 2023 · 1 comment
Closed
Tracked by #1940

Testing the hello endpoint will fail due to 403 #1939

Jeff-Tian opened this issue Dec 4, 2023 · 1 comment
Assignees
Labels
issue: docs/instructions Issues about incorrect instructions found on docs.strapi.io

Comments

@Jeff-Tian
Copy link

Link to the documentation page or resource

https://docs.strapi.io/dev-docs/testing#test-a-basic-endpoint-controller

Describe the bug

I refer to the the doc to create a test case against the /api/hello endpoint. And also created the endpoint followed https://docs.strapi.io/dev-docs/backend-customization/controllers.

But the test case failed by 403.

So I go to localhost:1337/admin to tick the "find" action against the hello endpoint for "public" roles, so I can get the expected "hello world" from localhost:1337/api/hello. But the test case still failed due to it's reading test config.

Could we update the doc on how to make the test pass?

Additional context

[2023-12-04 11:36:01.033] http: GET /api/hello (27 ms) 403
 FAIL  tests/app.test.js (8.259 s)
  ✓ strapi is defined (4 ms)
  ✕ should return hello world (94 ms)

  ● should return hello world

    expected 200 "OK", got 403 "Forbidden"

       5 |   await request(strapi.server.httpServer)
       6 |     .get("/api/hello")
    >  7 |     .expect(200) // Expect response http code 200
         |      ^
       8 |     .then((data) => {
       9 |       expect(data.text).toBe("Hello World!"); // expect the response text
      10 |     });

      at Object.expect (tests/hello/index.js:7:6)
      ----
      at Test._assertStatus (node_modules/supertest/lib/test.js:252:14)
      at node_modules/supertest/lib/test.js:308:13
      at Test._assertFunction (node_modules/supertest/lib/test.js:285:13)
      at Test.assert (node_modules/supertest/lib/test.js:164:23)
      at Server.localAssert (node_modules/supertest/lib/test.js:120:14)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        8.589 s, estimated 9 s
Ran all test suites.
error Command failed with exit code 1.

Suggested improvements or fixes

Either fix the doc on Test to set up the test config to allow the hello endpoint be public, or fix the doc in Controllers to make it public by default.

Related issue(s)/PR(s)

No response

@pwizla pwizla mentioned this issue Dec 4, 2023
4 tasks
@pwizla
Copy link
Collaborator

pwizla commented Dec 4, 2023

Hi,
Thanks for reporting. I'm closing this issue, but it's included in the meta issue about reworking the Testing page (#1940).
In the meantime I'll check with Strapi engineers to see if they can come up with a solution.

@pwizla pwizla closed this as completed Dec 4, 2023
@pwizla pwizla self-assigned this Dec 4, 2023
@pwizla pwizla added the issue: docs/instructions Issues about incorrect instructions found on docs.strapi.io label Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: docs/instructions Issues about incorrect instructions found on docs.strapi.io
Projects
None yet
Development

No branches or pull requests

2 participants