apihub icon indicating copy to clipboard operation
apihub copied to clipboard

[enhancement]: Test suite with code coverage

Open anirudhuuu opened this issue 2 years ago • 27 comments

Background

FreeApi.app as of today doesn't come with any test cases writtern for the application. I want to keep this as a open issue until we reach the goal of 50% coverage in phase 1.

Phase 2 would be to reach min code coverage of 80% for every subsequent release.

Plan

  • To utilise Jest for unit testing as it provides code coverage as well
  • To utilise Playwright for end-to-end testing
    • Need to use a third-party tool for reporting
    • No option of code coverage available that is built-in
  • Setup necessary packages & configuration to generate coverage report
  • To segregate various modules of FreeApi.app into buckets such as
    • Simple
    • Moderate
    • Complex
  • Test cases writing format must be at levels to ensure the quality of code
    • Unit
    • Integration
    • End-to-End

Outcome

  1. Improved code quality
  2. Avoid unnecessary bugs
  3. Confidence to refactor the code
  4. Easy review of PRs

Additional information

We will not be closing this issue until the stated Phases are achieved. Until then all are welcomed to contribute

anirudhuuu avatar Aug 20 '23 07:08 anirudhuuu

I didn't see Jest in package.json should I install it? And for the Integration test can I use a superset npm package

Tusharjagi avatar Sep 02 '23 17:09 Tusharjagi

Hi @Tusharjagi,

Thank you for your interest towards contributing to FreeApi.app currently the test suite setup is under progress. We are commiting the code under branch feat/coverage branch.

You can add jest, supertest & update the test script in package.json

I am also expecting to have a babel configuration json file that will include the presets & plugins necessary for the project. You can start with the base healthcheck API endpoint with a base test case for it to expect 200 as status code on making async call.

I would see this as a good starting point for our enhancement

anirudhuuu avatar Sep 03 '23 12:09 anirudhuuu

Sure @jwala-anirudh I will investigate it, Firstly I need to understand the code base, and then I will raise a PR for it, If I have another query I will reach out to you ...

Tusharjagi avatar Sep 03 '23 16:09 Tusharjagi

how about playwright?

theunhackable avatar Dec 27 '23 15:12 theunhackable

Any update on this one? playwright seems a good option.

wajeshubham avatar Jan 17 '24 09:01 wajeshubham

Alright, let me get started with playwright then 👍🏻 Thanks Shubham & Ranga

anirudhuuu avatar Jan 18 '24 04:01 anirudhuuu

Hello @jwala-anirudh ,

I have one question why we are using playwright for api testing as per my understanding it's used E2E testing for web apps

can you explain bit more how we are going to add unit test using playwright or i'm missing something ??

shrey-dadhaniya avatar Jan 18 '24 10:01 shrey-dadhaniya

@shrey-dadhaniya Yes the Playwright is more favourable for browser based E2E tests but it also provides an API testing module which I think is enough for our use case and has really simple apis to just do high level testing.

We could've gone for something like Jest or Mocha but our main focus is on business logic and working on the core functionality rather than robust testing.

However, we understand that doing testing is best practice and it eliminates manual testing work upon doing some major changes.

Playwright API testing reference: https://playwright.dev/docs/api-testing

@jwala-anirudh correct me if I'm wrong

Thanks!

wajeshubham avatar Jan 18 '24 19:01 wajeshubham

@wajeshubham Thanks. @jwala-anirudh can you update here once you finish with setup so i can start with basic and easy tests. meanwhile i will go through playwright documents for api testing.

shrey-dadhaniya avatar Jan 18 '24 19:01 shrey-dadhaniya

@shrey-dadhaniya available on feat/coverage branch, we look forward for your contributions Thanks!

anirudhuuu avatar Jan 21 '24 07:01 anirudhuuu

@jwala-anirudh, @wajeshubham, 

I have started adding test cases I want to make sure i'm going in right direction. I'm using mongodb-memory-server to connect mongodb and playwrite to test apis please check commit. commit is under development but i want your opinion on this. feel free to give you opinion.

Thanks!

shrey-dadhaniya avatar Jan 25 '24 18:01 shrey-dadhaniya

@shrey-dadhaniya why do you have yarn-lock and package-lock in the commit? should'nt you be using only one package manager

theunhackable avatar Jan 26 '24 16:01 theunhackable

@shrey-dadhaniya why do you have yarn-lock and package-lock in the commit? should'nt you be using only one package manager

yes, you are right. it's just draft commit i will remove yarn-lock file in final commit. The goal for that commit that i'm using playwright correctly or not. the way we decided erilier. once we lock that I will start actual development and then i will remove unnecessary code and files

Thanks for reviewing my code @theunhackable, I really appreciate that 😇 

shrey-dadhaniya avatar Jan 26 '24 16:01 shrey-dadhaniya

Hello @jwala-anirudh , @wajeshubham,

I think we should devide this issue in to multiple smaller issues or PR because it is time consuming task and we can not wait untill everything in done.

My suggestion is we can devide like

  1. front-end
  • core setup (adding packages and example test) 
  • create issue for all apps we have in FE.
  1. back-end
  • core setup (adding packages and example test)
  • create issuesfor all apps we have in BE.

once core setup is done for BE and FE then multiple developers can work separately on different apps

what are your suggestions? 

Thanks.

shrey-dadhaniya avatar Jan 31 '24 20:01 shrey-dadhaniya

@shrey-dadhaniya This issue is only targeting backend testing and that too on a higher level. We are not focusing on the front-end testing as it will be done by the contributors creating the front-end apps which is optional.

wajeshubham avatar Feb 01 '24 04:02 wajeshubham

@wajeshubham Okay.we can still divide BE test cases into multiple PRs. what you think?

  1. first core setup
  2. todo app test
  3. social media app test
  4. e-commerce app test
  5. chat app test ...

shrey-dadhaniya avatar Feb 01 '24 04:02 shrey-dadhaniya

@shrey-dadhaniya That is right, we expect this to be delivered in multiple PRs rather than one.

anirudhuuu avatar Feb 01 '24 11:02 anirudhuuu

@jwala-anirudh how we want to proceed? I will rais PR for master branch ? and what about git workflow I suggest we should add workflow that run test when anyone create PR. what is your input ? 

shrey-dadhaniya avatar Feb 01 '24 15:02 shrey-dadhaniya

@shrey-dadhaniya Let's first start with the testing. Workflows and pipelines we can implement later. Also, please read the contribution guide, we have mentioned everything regarding how to contribute there.

Thanks

wajeshubham avatar Feb 01 '24 18:02 wajeshubham

@wajeshubham yes right but my question is we have already branch feat/coverage that is created by someone my code is dependent on that branch

i can create one branch where i setup playwright and add test case for health function then we merge that branch to master and then we can proceed with app wise PR

what you suggest?

shrey-dadhaniya avatar Feb 01 '24 19:02 shrey-dadhaniya

Ok, raise PR to the feat/coverage branch.

wajeshubham avatar Feb 01 '24 19:02 wajeshubham

Todo and health check is done now I think i should take more easy app to test so i'm thinking to add Database Seeding feature

@wajeshubham, @jwala-anirudh give me green flag and i will start working on that

shrey-dadhaniya avatar Feb 04 '24 18:02 shrey-dadhaniya

Yes you can proceed! cc: @jwala-anirudh

wajeshubham avatar Feb 05 '24 07:02 wajeshubham

Hi @jwala-anirudh, PR #81 has been merged. Just a reminder to ensure that this branch is prepared for merging into the main branch. Additionally, we'll need to update the README.md to include testing-related instructions. Please let me know if you need any assistance from my side.

wajeshubham avatar Feb 13 '24 19:02 wajeshubham

what is next we decide to merge master branch and then will continue to add test for other apps and also update readme.

how we are going to proceed from here?

@jwala-anirudh @wajeshubham please advise

shrey-dadhaniya avatar Feb 20 '24 13:02 shrey-dadhaniya

Hello, anyone working on this? I'm planning to start with authentication test cases.

@wajeshubham give me green flag to start work

shrey-dadhaniya avatar Mar 31 '24 05:03 shrey-dadhaniya

Sounds good @shrey-dadhaniya - you can start, please open a draft PR once you complete 50% of work

anirudhuuu avatar Apr 07 '24 03:04 anirudhuuu