Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api): Make tests more stable by mocking VTEX API calls #1200

Merged
merged 7 commits into from
Mar 31, 2022

Conversation

victorhmp
Copy link
Member

@victorhmp victorhmp commented Mar 30, 2022

What's the purpose of this pull request?

Make all tests from @faststore/api more stable, by not relying on dynamic data.

How it works?

With this change, no actual HTTP request will be made when the tests suites are executed. Instead, a mocked version of the fetchAPI function will be called by each of our clients. Then the function calls are evaluated using jest.mock utilities.

This should make it so tests don't break if something changes in the account from which we get data (storeframework).

How to test it?

Run yarn test inside packages/api.

base.store Deploy Preview

No need, nothing changed in the actual package's implementation :)

@victorhmp victorhmp self-assigned this Mar 30, 2022
@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 30, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a8033f9:

Sandbox Source
Store UI Typescript Configuration

@victorhmp victorhmp force-pushed the chore/make-api-tests-more-consistent branch from 304c173 to 1ce2b3b Compare March 30, 2022 19:44
@victorhmp victorhmp force-pushed the chore/make-api-tests-more-consistent branch from 1ce2b3b to 4e75bc7 Compare March 30, 2022 21:23
@victorhmp victorhmp marked this pull request as ready for review March 31, 2022 12:23
@victorhmp victorhmp requested a review from a team as a code owner March 31, 2022 12:23
Copy link
Contributor

@tlgimenes tlgimenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future PR, we need to work towards removing these hard-coded mocked api responses too and use snapshots instead

@victorhmp
Copy link
Member Author

In a future PR, we need to work towards removing these hard-coded mocked API responses too and use snapshots instead

But how would we use snapshots for the API responses? We would have the same problem we currently have, right? If something changes in the storeframework account, the API would return something different and the snapshots would fail.

In the way it is with these mocked API responses, we're testing all the layers apart from the real VTEX's APIs. We're testing the schema, the resolvers, and the logic inside the clients.

@victorhmp victorhmp merged commit 1246eeb into master Mar 31, 2022
@victorhmp victorhmp deleted the chore/make-api-tests-more-consistent branch March 31, 2022 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants