I am new to Zapier and try to make a Zapier CLI integration work.
I have created an integration with Zapier UI, converted it with zapier convert, and I can successfully “zappier push” it back.
However I have issues when doing “zapier test”:
I receive a 401 error from my server when each unit test is run
In fact, it is normal, because the unit test passes “Authorization: Bearer {{bundle.authData.access_token}}” litterally, without replacing the access_token with its actual value
And the session authentication (which should return an access_token from the email/password) is not even called from the tests.
So I have 2 questions:
how to manage the tests so that it uses a valid access_token?
how to make sure that {{bundle.authData.access_token}} is replaced with its value?
These are probably dummy questions, but I could not find any answer in the documentation.
Many thanks!
Best answer by bfredo123Best answer by bfredo123
Many thanks, it works!
What I did into more details, if it may help others:
I created a 0_auth folder in the test folder (‘0’ to make sure it’s invoked at first, with alphabetical order).
In this folder, I do like the provided example, in a ‘testAuth.js’ test module, and I store the access_token received from the server in a variable exported by this test module (in the example, the ‘secret’ token does not work in my case, as the server returns a token which I cannot control on the client side)
In any other test, I set the bundle.authData.access_token to this testAuth.access_token
Actually, leaving the simple quotes as ‘Bearer {{bundle.authData.access_token}}’ does the job (otherwise, I guss that the headers would be initialized at the test startup, even before the access_token has been retrieved from the server
Thanks again, I was really wondering how to properly organize my test bench.
Hi @bfredo123 - Just use normal ES6 string interpolation because the double curly braces string interpolation won’t work inside functions. In your case, it should look like the following:
Also, in your unit tests, the authentication won’t happen automatically, you should actually define the access_token in your bundle.authData. You can use this example as a reference.
What I did into more details, if it may help others:
I created a 0_auth folder in the test folder (‘0’ to make sure it’s invoked at first, with alphabetical order).
In this folder, I do like the provided example, in a ‘testAuth.js’ test module, and I store the access_token received from the server in a variable exported by this test module (in the example, the ‘secret’ token does not work in my case, as the server returns a token which I cannot control on the client side)
In any other test, I set the bundle.authData.access_token to this testAuth.access_token
Actually, leaving the simple quotes as ‘Bearer {{bundle.authData.access_token}}’ does the job (otherwise, I guss that the headers would be initialized at the test startup, even before the access_token has been retrieved from the server
Thanks again, I was really wondering how to properly organize my test bench.