Skip to main content

I’ve created a number of integration tests (using Jest) for my integration/app that require valid credentials for the tests to succeed.

What’s the recommend approach to perform the authentication?  Maybe invoke the perfrom method of the authentication.js script in a before filter?  

beforeAll(() => {
// TODO: get a new access token
// invoke authenticate.js?
});

 

Hey @benjamink9 ,

Great question!

Yes, while I haven’t tried that personally, using appTester to invoke the authentication before the tests certainly sounds like a valid approach.

Alternatively, a less dynamic option might be to grab credentials, export them as environment variables, and import them into a mocked data bundle. You could also hardcode them into the mocked bundle, but we recommend utilizing environment variables. Here’s an example of this for reference:

https://github.com/zapier/zapier-platform/blob/1217d2797881462d732da1d764ef51655b05a08b/example-apps/oauth2/test/authentication.test.js#L85

One other option that comes to mind is to use Nock to mock requests. If you’re not testing the authentication directly and are looking to test how other parts handle a given response, Nock can help simulate a request, and you could likely exclude auth from the mocked request:

https://github.com/zapier/zapier-platform/blob/main/packages/cli/README.md#mocking-requests