dwyl / auth

🚪 🔐 UX-focussed Turnkey Authentication Solution for Web Apps/APIs (Documented, Tested & Maintained)
https://authdemo.fly.dev
GNU General Public License v2.0
135 stars 9 forks source link

Tests FAILED: Expected minimum coverage of 100%, got 99.5% #230

Closed nelsonic closed 2 years ago

nelsonic commented 2 years ago

Just ran:

mix c

On main branch on localhost and got the following output:

Finished in 16.8 seconds (16.8s async, 0.00s sync)
1 property, 150 tests, 0 failures

Randomized with seed 334479
----------------
COV    FILE                                        LINES RELEVANT   MISSED
100.0% lib/auth.ex                                     9        0        0
100.0% lib/auth/apikey.ex                            105       15        0
100.0% lib/auth/app.ex                               158       17        0
100.0% lib/auth/email.ex                              41        7        0
100.0% lib/auth/init/init.ex                         124       26        0
100.0% lib/auth/init/roles.ex                         69        3        0
100.0% lib/auth/init/statuses.ex                     113        3        0
 96.6% lib/auth/log.ex                               137       29        1
100.0% lib/auth/people_roles.ex                      136       12        0
100.0% lib/auth/permission.ex                        120        8        0
 98.3% lib/auth/person.ex                            371       58        1
100.0% lib/auth/repo.ex                                5        0        0
100.0% lib/auth/role.ex                              212       30        0
100.0% lib/auth/session.ex                           105       16        0
100.0% lib/auth/status.ex                             46        8        0
100.0% lib/auth/user_agent.ex                        101       25        0
100.0% lib/auth_web/controllers/api_controller.       70       19        0
100.0% lib/auth_web/controllers/app_controller.      111       36        0
 99.3% lib/auth_web/controllers/auth_controller      507      141        1
100.0% lib/auth_web/controllers/init_controller       45        7        0
100.0% lib/auth_web/controllers/people_controll       34        8        0
100.0% lib/auth_web/controllers/permission_cont       61       19        0
100.0% lib/auth_web/controllers/ping_controller        8        1        0
100.0% lib/auth_web/controllers/role_controller      192       67        0
100.0% lib/auth_web/endpoint.ex                       54        0        0
100.0% lib/auth_web/gettext.ex                        24        0        0
100.0% lib/auth_web/plugs/is_owner.ex                 12        1        0
100.0% lib/auth_web/router.ex                        103       25        0
100.0% lib/auth_web/views/app_view.ex                  3        0        0
100.0% lib/auth_web/views/auth_view.ex                 3        0        0
100.0% lib/auth_web/views/error_view.ex               30        4        0
100.0% lib/auth_web/views/init_view.ex                 3        0        0
100.0% lib/auth_web/views/layout_view.ex               3        0        0
100.0% lib/auth_web/views/people_view.ex              35        7        0
100.0% lib/auth_web/views/permission_view.ex           3        0        0
100.0% lib/auth_web/views/role_view.ex                10        3        0
[TOTAL]  99.5%
----------------

FAILED: Expected minimum coverage of 100%, got 99.5%.

I've made most of the recent changes to this repo ... https://github.com/dwyl/auth/commits/main 🧑‍💻 So going investigate this now. 🔍

nelsonic commented 2 years ago

Going through the test coverage report in the browser we can see that /auth/cover/excoveralls.html#lib/auth/log.ex has an uncovered guard function:

image

Which caused me to ask the question:

Why are we defining a utility function stringify/1 inside the Auth.Log module...? 🤷‍♂️

I'm sure this made sense to 2-years ago Nelson ... 🙄 ⏳ https://github.com/dwyl/auth/blame/f6a72102fd72f99ba8c42d00083e22c2fdec917a/lib/auth/log.ex#L134 But this feels like it belongs in our Useful utility library instead so that it can be independently tested, documented and re-used in other projects! ♻️

Side-quest: https://github.com/dwyl/useful/issues/11 ⚔️ #brb

nelsonic commented 2 years ago

Created PR: https://github.com/dwyl/useful/pull/26

Next in lib/auth/person.ex there is one line that isn't covered:

image

Can't that I know how I'm going to test this ... 💭

nelsonic commented 2 years ago

Added test:

  test "Auth.Person.decrypt_email/1" do
    email = "alex@gmail.com"
    encrypted = email |> Fields.AES.encrypt() |> Base58.encode()
    decrypted = Person.decrypt_email(encrypted)
    assert email == decrypted

    # Unhappy ("rescue") path:
    invalid_email = ""
    assert Person.decrypt_email(invalid_email) == 0
  end

Last one in lib/auth_web/auth_controller.ex ...

image

defp client_id_is_current? ... yay trying to test a private function! 🎉 (🙄 ...)

nelsonic commented 2 years ago

No idea why/how these lines were not being reported as uncovered by tests in previous builds ... 🤷‍♂️ But they are now all covered. ✅

nelsonic commented 2 years ago
Finished in 16.9 seconds (16.9s async, 0.00s sync)
1 property, 152 tests, 0 failures

Randomized with seed 231724
----------------
COV    FILE                                        LINES RELEVANT   MISSED
100.0% lib/auth.ex                                     9        0        0
100.0% lib/auth/apikey.ex                            105       15        0
100.0% lib/auth/app.ex                               158       17        0
100.0% lib/auth/email.ex                              41        7        0
100.0% lib/auth/init/init.ex                         124       26        0
100.0% lib/auth/init/roles.ex                         69        3        0
100.0% lib/auth/init/statuses.ex                     113        3        0
100.0% lib/auth/log.ex                               125       25        0
100.0% lib/auth/people_roles.ex                      136       12        0
100.0% lib/auth/permission.ex                        120        8        0
100.0% lib/auth/person.ex                            373       58        0
100.0% lib/auth/repo.ex                                5        0        0
100.0% lib/auth/role.ex                              212       30        0
100.0% lib/auth/session.ex                           105       16        0
100.0% lib/auth/status.ex                             46        8        0
100.0% lib/auth/user_agent.ex                        101       25        0
100.0% lib/auth_web/controllers/api_controller.       70       19        0
100.0% lib/auth_web/controllers/app_controller.      111       36        0
100.0% lib/auth_web/controllers/auth_controller      507      141        0
100.0% lib/auth_web/controllers/init_controller       45        7        0
100.0% lib/auth_web/controllers/people_controll       34        8        0
100.0% lib/auth_web/controllers/permission_cont       61       19        0
100.0% lib/auth_web/controllers/ping_controller        8        1        0
100.0% lib/auth_web/controllers/role_controller      192       67        0
100.0% lib/auth_web/endpoint.ex                       54        0        0
100.0% lib/auth_web/gettext.ex                        24        0        0
100.0% lib/auth_web/plugs/is_owner.ex                 12        1        0
100.0% lib/auth_web/router.ex                        103       25        0
100.0% lib/auth_web/views/app_view.ex                  3        0        0
100.0% lib/auth_web/views/auth_view.ex                 3        0        0
100.0% lib/auth_web/views/error_view.ex               30        4        0
100.0% lib/auth_web/views/init_view.ex                 3        0        0
100.0% lib/auth_web/views/layout_view.ex               3        0        0
100.0% lib/auth_web/views/people_view.ex              35        7        0
100.0% lib/auth_web/views/permission_view.ex           3        0        0
100.0% lib/auth_web/views/role_view.ex                10        3        0
[TOTAL] 100.0%
----------------