PaulC91 / shinyauthr

R package with shiny authentication modules
https://paulc91.github.io/shinyauthr/
Other
428 stars 81 forks source link

Adding tests #31

Closed andodet closed 3 years ago

andodet commented 4 years ago

After experimenting with couple different approaches, I believe testing shinyauthr functionalities against the Shiny example app in inst/ would be the most practical way as it allows to test the user-facing interface (leaving room to change the underlying logic, e.g hashing, etc.).

Tests have been structured as:
Login:

Logout:

Tests run well under a minute (~26secs.), hence it shouldn't be required to skip tests when submitting.

Would be really interesting to understand if I overlooked any better approach to do this.

Help needed

Exporting values is needed in order to inspect them during testing. This is done by adding a call to exportTestValues() in app.R.

  # Export reactive values for testing
  exportTestValues(
    auth_status = credentials()$user_auth,
    auth_info   = credentials()$info,
    user_data    = user_data()  # this throws an error
  )

On the other hand, exporting user_data() reactive data frame breaks the call, trowing the following error (even when in testmode):

Unable to fetch all values from server. Is target app running with options(shiny.testmode=TRUE?)

This is blocking me from testing the right data is being show to user respecting their permission level. Hence tests have been commented out test-shinyauthr.R.

I am probably missing something obvious here but the same call works like a charm on a mock Shiny app.

PaulC91 commented 4 years ago

Thanks so much for this! Sorry I'm super busy at the moment so haven't had time to test yet but will do asap.

Thanks again, Paul

andodet commented 4 years ago

Another thing I forgot to mention is that by testing the example Shiny application, devtools::test_coverage() will obviously result in a 0% as we're not testing the core package functions. If it's a deal breaker, other approaches must be explored.

PaulC91 commented 3 years ago

Hi. Just added some tests in #52 . Mostly inspired by this PR - thanks for the contribution. And sorry it took so long!

andodet commented 3 years ago

Hey @PaulC91, no worries - happy it helped in any way. Hope to see the package on CRAN at some point.

PaulC91 commented 3 years ago

@andodet made it to CRAN! https://cran.r-project.org/package=shinyauthr