garageScript / c0d3-app

C0D3 - Become a Software Engineer the Hard Way
https://www.c0d3.com
MIT License
101 stars 69 forks source link

Write integration tests #670

Open ggwadera opened 3 years ago

ggwadera commented 3 years ago

Since a lot of production breaking bugs have been happening recently due to failures that can't be caught with unit testing, writing integration tests to assure full API/client functionality can help in reduce the number of these bugs.

Basic implementation steps:

  1. Start Server
  2. Send API request
  3. Save response as a snapshot

This will probably be better implemented using a in-memory embedded database like SQLite to avoid connecting to an external database, the recent Prisma seed PR #659 can help in seeding this db with fake data for the tests.

tomrule007 commented 3 years ago

I'm glad to see progress is getting made on this issue. Last week I had mentioned how switching to the getLayout pattern interfered with our current tests and I thought next-page-tester might be a good solution. After reading this little blog post https://dev.to/toomuchdesign/dom-testing-next-js-applications-46ke it sounds like the real solution is to switch to intergration tests like this and possible impliment some e2e tests as well.

ggwadera commented 3 years ago

Yeah some e2e tests running the entire Next.js stack might be good too, so we can test the SSG and SSR rendering with Next's data fetching and also the API layer. But for the front-end components I believe most cases can be covered by the unit tests.

With E2E tests we could test an entire flow of our app's logic, for example: account creation -> login -> send submissions -> receive review -> complete lesson. That might help in detecting some regressions like we already had before. But on the other hand, e2e tests are much harder to write.

I think we can cover most of our test cases with only the API layer of Apollo Server + Prisma. But for some corner cases the E2E tests might be the best solution though.

songz commented 2 years ago

Sample PR for reference: https://github.com/garageScript/c0d3-app/pull/992