My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Acceptable Unit Test Criteria for 3rd Party API's?

Phillip Chan's photo
Phillip Chan
·Oct 2, 2017

We have an application that leverages 3rd party API's (in our instance Hubspot) to run logic on the data. As I'm building out Unit Tests for internal methods, the internal methods have a clear "expected" assertion "reality" type of tests where we expect a certain output for a certain input. (e.g. `add(2,2).should.equal(4)`).

As I'm trying to build tests to make sure our external API calls would be continually functional, what's the best way to structure the assertion in a unit test to make it work?

For instance we have a method that pulls a single contact from Hubspot. Matching the JSON object property by property seems unreasonable and ineffective.

Should I... match just the properties of interest in the test? (e.g. `contact.name === 'Phillip Chan'`)? Or somehow assert how the shape of the JSON object should be?

How would you build a reliable and effective unit test?

P.s. I'm unit testing in Node using Mocha.