hiteshchoudhary / apihub

Your own API Hub to learn and master API interaction. Ideal for frontend, mobile dev and backend developers.
https://freeapi.app
Other
3.65k stars 840 forks source link

[enhancement]: Test suite with code coverage #43

Open jwala-anirudh opened 1 year ago

jwala-anirudh commented 1 year ago

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

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

Tusharjagi commented 1 year ago

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

jwala-anirudh commented 1 year ago

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

Tusharjagi commented 1 year ago

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 ...

theunhackable commented 9 months ago

how about playwright?

wajeshubham commented 8 months ago

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

jwala-anirudh commented 8 months ago

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

shrey-dadhaniya commented 8 months ago

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 ??

wajeshubham commented 8 months ago

@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!

shrey-dadhaniya commented 8 months ago

@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.

jwala-anirudh commented 8 months ago

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

shrey-dadhaniya commented 8 months ago

@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!

theunhackable commented 8 months ago

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

shrey-dadhaniya commented 8 months ago

@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 commented 8 months ago

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

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

what are your suggestions? 

Thanks.

wajeshubham commented 8 months ago

@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.

shrey-dadhaniya commented 8 months ago

@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 ...

jwala-anirudh commented 8 months ago

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

shrey-dadhaniya commented 8 months ago

@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 ? 

wajeshubham commented 8 months ago

@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

shrey-dadhaniya commented 8 months ago

@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?

wajeshubham commented 8 months ago

Ok, raise PR to the feat/coverage branch.

shrey-dadhaniya commented 8 months ago

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

wajeshubham commented 8 months ago

Yes you can proceed! cc: @jwala-anirudh

wajeshubham commented 8 months ago

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.

shrey-dadhaniya commented 7 months ago

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 commented 6 months ago

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

@wajeshubham give me green flag to start work

jwala-anirudh commented 6 months ago

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