Closed ok200paul closed 3 years ago
Hi @ok200paul,
Thanks for the question :)
Yeah testing against Xero is somewhat frustrating (hence why the package so far doesn't have any tests!)
My suggestion would be to create a "MemoryStore" for the credential manager. https://github.com/webfox/laravel-xero-oauth2/blob/master/src/Oauth2CredentialManagers/FileStore.php
Manually authenticate against Xero to get the token/refresh token and the set your tests up to load those credentials into memory.
@SidneyAllen do you have any input on the best way to do automatic integration tests with the Xero API? (Language aside, I just mean the general concept) Xero doesn't have a sandbox environment does it?
Thanks for the quick response @hailwood! I see what you mean, we use S3 for our production/staging/CI/local environments so we'll need to persist the token to there, so that our CI can do its thing. Cheers.
While I have you, is there a way to manually set the token expiry? It'd be good to set it longer for certain environments.
Hmm. The more I think about this, the more our CI system is going to have issues with it over time (manual intervention upon expiry etc)
Unfortunately not, the 30 minute expiry comes from Xero. Though as long as you ensure the refresh token is stored you should be able to just request a new access token.
Understood - thanks @hailwood
@ok200paul (I like your username)
@hailwood is correct that Xero's access token has a 30 min expiration which means either manually generating a new token each time for 30 min use OR saving the refresh token details and performing a token refresh call.
We are working on a premium option for custom, and machine-to-machine integrations. We’re hoping to have this ready early 2021.
Long term we want to offer developers sandbox environments, but that is not on our current roadmap.
Hey @SidneyAllen, thanks very much for weighing in! This is great, I'll keep an eye on developments from your side over the coming months.
On the sandbox environments piece: pretty please add it to the roadmap? Testing against the live API is fraught with risk, I've personally been responsible for mistakenly pulling the wrong contact via the API and updating their real-life POs/Invoices when meaning to test code away from real people. The simple answer here is "be more careful" of course.
I'll close this now - thanks to you both for taking the time to respond!
Not so much a feature request, nor an issue, apologies. First off: thanks for this package, it definitely makes things easier when interacting with Xero. I'm new to this package so please excuse any lack of prior knowledge.
Is your feature request related to a problem? Please describe. I'm confused as to how we'd instantiate a connection to Xero in our testing suite (we test against real APIs - I wish Xero had a Stripe-style testing section!). Using the dependency injection in Laravel's test suite fails. I'm after some documentation that would give me examples as to how to begin testing my functions that use this package, in Laravel's test suite.
Describe the solution you'd like It'd be great if we got a few examples of how to best create a test/set of tests so we can assert against real data in Xero.
Describe alternatives you've considered I've done the below to "make it work", but not sure if this is the best practise, or what's the best way to connect to Xero when in the testing environment.
Additional context