I would say absolutely, yes. Otherwise, you could make a change later which unknowingly has the side-effect that allows access to guests. A simple test will catch this immediately for you.
Should I test redirections ?
Hi there, I'm a long time lurker on this forum and I thought I would ask my first question since I usually read good and specific answers here. I'm still trying to get the hang of some Laravel's features, and I'm definetly not an expert :-)
To situate : I have a controller (let's call it ServerController). This controller has the auth middleware applied to it, therefore any guest should get redirected to the login page. Therefore, only authenticated users should have access to this resource.
I'm currently writing tests that will check every feature this controller has to "offer". My question is : should I check whether I get redirected to the login page, once authed ?
Thank you in advance for your answer.
I would. It's an easy test to write, and it ensures that your feature works correctly (and continues to work correctly when you change code).
I would have two tests:
- Guest user gets redirected to login
- Auth user gets a "200 okay" response (i.e. does not get redirected)
Please or to participate in this conversation.