So you yourself has just given an example how easy it is to temporarily get good at "test-filling", by simply preparing for that.
The question is whether a given test measures anything relevant - did your friend become a better programmer for doing 6 weeks of leetcodes? E.g. what kind of experience did he gain about large code bases and how to handle those? Continuing your analogy, would you fly with a pilot who drilled on taking off a bunch of time, but never practised flying in a storm?
I'm not saying leetcodes or exams are useless, but Goodhart's Law apply.
Regardless of the content, a test filters for people willing to put in the work to pass. All else being equal, given two candidates, where one has passed a test and another one who didn't bother, the first one sends a stronger signal to the potential employer.
It's still worth discussing if the particular test is ideal, but the answer IMO is not to say let's remove tests in general.