Skip to main content
Best answer

Zapier CLI testing

  • September 5, 2020
  • 2 replies
  • 894 views

Hi,

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:

  1. I created a 0_auth folder in the test folder (‘0’ to make sure it’s invoked at first, with alphabetical order).
  1. 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)
  1. In any other test, I set the bundle.authData.access_token to this testAuth.access_token 
  2. 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.

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • September 5, 2020

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:

{

  //...

  headers: {

    Authorization: `Bearer ${bundle.authData.access_token}`

  }

}

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.

 


  • Author
  • Beginner
  • 1 reply
  • Answer
  • September 5, 2020

Many thanks, it works!

What I did into more details, if it may help others:

  1. I created a 0_auth folder in the test folder (‘0’ to make sure it’s invoked at first, with alphabetical order).
  1. 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)
  1. In any other test, I set the bundle.authData.access_token to this testAuth.access_token 
  2. 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.