0

What is the standard or recommended approach or architecture for testing integration to third party libraries?

More specifically, for this post I am only concerned with one of the possible ways of integrating with third party libraries: that of calling a backend API from the frontend, and the backend makes a single call to the third-party service. Other potential ways you can integrate with third parties are like Stripe Elements integration which is purely on the frontend, and there's probably a million other ways.

This post is in regards to the following system. We have a button "sync" on the FE, which spawns off a background worker to asynchronously (but effectively immediately) pull some data from some website and sync it to our app. There is no third-party library we are using in this case, it is just done through manual web crawling/scraping. It goes through a GraphQL API from the FE, to a mutation on the backend, which calls to the "third party service".

Right now we have tests on the BE, which test that the mutation calls the appropriate job spawning function, which is mocked out in the test. We also have a test that has a copied HTML webpage source, which we use to stub a request response, to test that the crawler can retrieve data from the page. We don't have any frontend tests currently. What we end up doing is manually testing that when we click the button, the data gets synced to the app, by checking back in a few minutes and making sure the data is the latest (by comparing both our UI and the third-party webpage). This is manual testing though, which is undesirable.

The thinking is, there is no real way to test this automatically that won't be both burdensome in writing the tests, and time consuming to run the tests.

What is the state of the art of how you would/could/should test this sort of system?

We use cypress for running e2e tests for some things on the FE, but currently avoid anything which involves third parties or complex async things like this.

1
  • Ideally, you will never test real integrations with 3rd party services from the FE. FE only knows your BE API and responses. That's wherew the focus should be. Whether the BE responde with the latest data or mocked one, the FE won't know. This said. Does your architecture support profiles? Could you run a synchronous version of the worker when running tests? If yes, just left to decide whether you load static HTML from a file or you call the 3rd party API. Ideally you will go with the 1st because it ease the assertions on the FE.
    – Laiv
    Jul 11 '21 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.