I've been able to successfully write some integrat...
# testing
j
I've been able to successfully write some integration and unit tests for an app that doesn't require authentication (hooray!). However, now I'm starting some tests on an app that does require authentication. Unit tests are still no problem, however, I'm struggling to figure out how to write an integration test when I need
cgi.remote_user
populated in
main.index
as I'm doing something like
userId = cgi.remote_user
and then passing
userID
into a function to retrieve data and then display it on the screen based on who is logged in. What is the best approach here?
z
this uses lucee's _internalRequest but you can just substitute cfhttp if you like https://github.com/lucee/Lucee/blob/6.0/test/general/AdminPages.cfc
j
Thanks! I'll take a look!
b
without seeing the context, I might recommend making that a method like
getUserID
that is an easy-to-mock method in a testing environment.
in the
main
handler, the method would return
cgi.remove_user
, but in your tests, could you mock it to return something else?
j
I'm not sure! I'm only familiar with mocking in a unit testing context. Not sure if mocking works in tandem with the
execute
handler\method function in integration tests or not. I'll have to play around with it some more. Thanks for the thought. I know I can set values in the rc scope with
getRequestContext().setValue( "name", "value" )
but struggling to figure out how to override values that are populated in the handler method itself by calls to service methods.