System Information
- Strapi Version: 4.20.0
- Operating System: macOS 14.6.1 darwin-arm64
- Database: SQLite
- Node Version: 18.20.3
- NPM Version: 10.8.2
- Yarn Version:
I am writing unit tests and have followed the instructions in the docs. Each time the tests are run a temporary file is created to run a SQLite database. I have written a test fo rone of my endpoints and expect to get a 200 status back. Instead I get 403 unauthorised. I have written the code included below to set all routes to public access, and have tried alternatively getting a jwt for a user in the database and attaching this to the request. I feel like I must be missing something obvious!
// set all routes to public access
const roles = await strapi
.service("plugin::users-permissions.role")
.find();
console.log(roles)
const _public = await strapi
.service("plugin::users-permissions.role")
.findOne(roles.filter((role) => role.type === "public")[0].id);
Object.keys(_public.permissions)
.filter(permission => permission.startsWith('api'))
.forEach(permission => {
const controller = Object.keys(
_public.permissions[permission].controllers
)[0];
setAllEndpointsToEnableTrue(
_public.permissions[permission].controllers[controller]
);
});
....
function setAllEndpointsToEnableTrue(obj) {
for (let key in obj) {
if (obj[key] && typeof obj[key] === "object" && "enabled" in obj[key]) {
obj[key].enabled = true;
}
}
}