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

Make unit tests for async/graphql related code easier #781

Open
josh-griffin opened this issue Feb 9, 2022 · 2 comments
Open

Make unit tests for async/graphql related code easier #781

josh-griffin opened this issue Feb 9, 2022 · 2 comments

Comments

@josh-griffin
Copy link
Contributor

Would like to make writing unit tests for async/graphql related code easier.

  • Technically, we have code gen msw handlers: invoiceQueryMock. However, if we use them, the amount of random fields we need to add is outrageous!
  • Not 100% sure what the best thing to do is here but I do have some thoughts on what a great end goal could be..
  1. Easily attach a msw handler to a msw server running in test files, without having to think about or handle the restarting of the server etc.
  2. Easily generate simple mock objects, not having to specify every field
  3. Easily modify values of fields on mock objects for a single test

I think if we had a way to have those 3 goals covered, it would be super nice and easy to write unit tests for any async work.

Right now, it's tedious and annoying which results in essentially.. not writing them 🤷

Some extra nice to haves:

  1. Allow for whatever data that is generated to be used in some sort of end to end testing suite? For example, maybe using https://github.com/sorry-cypress/sorry-cypress to run tests to insert the data 🤷 I don't really know how this works.
  2. The backend team also have mock data. We could work together to create a suite of json files to share the work load? Unsure if this is more troublesome than helpful!
@josh-griffin
Copy link
Contributor Author

The suggestion so far is to:

  • Use JSON files of mock data
  • Replace the use of faker to instead parse over these json files

This way we could more easily use the msw server handlers in our test files, the same as we do as the msw worker handlers.

It might be best to keep the faker implementation in place for now. It is good to be able to generate large amounts of data? If we were to do that with JSON files, they might get pretty big?

@mark-prins
Copy link
Contributor

that would be really good. Would be keen to remove faker at some point, it's a large package.
Having small data sets is fine - if we do need larger, could we just load the small set and repeat it a number of times, updating the ids?

Would like to implement end-to-end test suite too. after we get the MSW / unit tests going though 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants