Assistance in writing tests using bootcamp/google_sign_in

I’m currently writing a small app trying to understand “tests” better. More specifically testing the authentication of my little app. Right now I’ve set it up with the bootcamp/google_sign_in gem. Everything works correctly in my application, but when I go to write the test for it I’m unsure how since I’m expecting a 3rd party to provide information. Is this where I would mock the return object from google and proceed the lookup from my fixtures user file? I’m unsure this is the approach that should be taken. If anyone could give me more insight into how to properly do this it would be greatly appreciated. Thanks!

David,
You test only functionality provided by YOU. You don’t necessarily need to test upstream functionality. For example, in an app I recently wrote, I needed to provide the time of intersection between two curves and used a library to provide the (maybe complex) maths for the intersection. Rightly or wrongly, I would rely on the upstream developers to make sure the maths are accurate and just test that if curve A and curve B intersect, a time is provided. Also, if there isn’t an intersection, a sentinel is returned. – H

Thanks for you reply! I guess my thought process was to check authentication on my site in the following way. And I saw this as something that I should be testing and not the developers of the google_sign_in gem.

Test:

  1. Test that when an admin user clicks on the “Sign in with Google” link, that person is then redirected to an “admin page”.

  2. Test that when a site visitor clicks on the “Sign in with Google” link, that person is then redirected to the root_path.

If I’m correct in testing these two options… How do I test the “Sign in with Google” link where I send Google information and then receive their authentication object back? Perhaps Google supplies a “fake” login for developers to use? I couldn’t find it if so.

Thanks for you reply! I guess my thought process was to check authentication on my site in the following way. And I saw this as something that I should be testing and not the developers of the google_sign_in gem.

Test:

1. Test that when an admin user clicks on the "Sign in with Google" link, that person is then redirected to an "admin page".
2. Test that when a site visitor clicks on the "Sign in with Google" link, that person is then redirected to the root_path.

If I'm correct in testing these two options... How do I test the "Sign in with Google" link where I send Google information and then receive their authentication object back? Perhaps Google supplies a "fake" login for developers to use? I couldn't find it if so.

Usually what you have to do in these cases is mock the reply from Google, and check that your app responds correctly when there's a Yes or No answer. But honestly, the gem that you are using should have its own tests that cover this. Your app should be testing whether it does whatever it is supposed to do.

Walter