msupply-foundation / openmsupply-client

Someone should really write a description for this repo.
2 stars 0 forks source link

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

Open josh-griffin opened 2 years ago

josh-griffin commented 2 years ago

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

  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 commented 2 years ago

The suggestion so far is to:

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 commented 2 years ago

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 😉