One potential cause of this issue could be that the user that is being passed to the actingAs method in the test function is not properly authenticated. Make sure that the user object being passed to the actingAs method is a valid user object that has been properly saved to the database.
Another possible cause of this issue could be that the Auth::user() method is returning a null object, this could happen if you don't have session enabled on the api routes, to enable this you need to specify auth:sanctum on the api guard in config/auth.php.
It's also a good idea to check the user's roles and permissions to ensure that the user has the necessary permissions to access the logout endpoint.
You may also have issue on the endpoint side, make sure the you don't have any middleware restriction that preventing the access to the logout.
Lastly, you can debug by adding a dd(Auth::user()) on the logout controller, this would give you better insight of what's happening on the controller level.