normal approach here would be to have an adapter a...
# testing
a
normal approach here would be to have an adapter around the
<cfhttp>
call, precisely for this; then you mock that out.
Keep the adapter as skinny as poss, eg:
Copy code
// MyHttpAdapter.cfc
component {

    function makerequest(url, etc) {
        http url=arguments.url result=local.result;
        
        return local.result
    }
}
any logic around building the URL, deciding the method, organising wot params to pass etc should NOT be done in the adapter. The adapter is an adapter for cfhttp, not your business logic.
Then have an integration test for
MyHttpAdapter.makeRequest
that does a legit call to example.com or some internal test fixture which has a known canned response, etc.
You could have a MyExampleComHttpAdapter and bake in the URL as a static string, perhaps. but no code other than "use that string for the URL" etc.
r
Yes, that would be my approach when authoring from new but in this situation I'm working to improve some ancient code. TBH it's the least of my issues (
request
scope bleeding in and a id value being an optional argument), to create a method to wrap around the request so I can mock it before I can start testing.
Copy code
<cfhttp
	charset = "utf-8"
	url = "#request.api_endpoingUrl#/emp/customerstatusapi/v1/#customerid#"
	method="get"
	username = "#request.api_username#"
	password = "#request.api_password#"
	timeout = "20"
	result = "result_raw">
</cfhttp>
Thanks for the confirmation Adam.
👍 1