@Jean1 I got in touch with Mateusz Wojczal and he helped me figure out this authentication issue we were having. The unit testing documentation isn’t clear about this, but we need to give privilege to the testing instance separately, it isn’t done automatically.
If you copy the contents of this example’s strapi-unit-test-example/strapi.js at master · qunabu/strapi-unit-test-example · GitHub strapi.js file and paste it into your /test/helpers/strapi.js file, then all you have to do is to add the following code into your tests/hello/index.js file:
const request = require("supertest")
const { grantPrivilege } = require("./../helpers/strapi");
beforeAll(async () => {
await grantPrivilege(2, "permissions.application.controllers.hello.index"); // Gives Public access to endpoint
});
it('should return hello world', async (done) => {
await request(strapi.server) // app server is an instance of Class: http.Server
.get('/hello')
.expect(200) // Expect response http code 200
.then((data) => {
expect(data.text).toBe('Hello World!') // expect the response text
})
done()
})
Now it should work.