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

Unit test for the components #43

Merged
merged 24 commits into from
Dec 30, 2024
Merged

Unit test for the components #43

merged 24 commits into from
Dec 30, 2024

Conversation

Abiji-2020
Copy link
Contributor

@Abiji-2020 Abiji-2020 commented Nov 29, 2024

Unit test for the components

Currently Pending components

  • authCallbackServer in auth.js file
  • login and logout

Coverage report

image

/claim #12
closes #12

@Abiji-2020
Copy link
Contributor Author

Abiji-2020 commented Nov 29, 2024

@gemanor do we have to add unit test for the login component? As we are modifying the component itself in #13 and i see that the tests are included for them

@Abiji-2020 Abiji-2020 marked this pull request as ready for review November 29, 2024 16:08
@Abiji-2020
Copy link
Contributor Author

Abiji-2020 commented Nov 29, 2024

@quest-bot loot #12

@quest-bot quest-bot bot added the ⚔️ Quest Tracks quest-bot quests label Nov 29, 2024
@quest-bot quest-bot bot mentioned this pull request Nov 29, 2024
Copy link

quest-bot bot commented Nov 29, 2024

Quest PR submitted! image Quest PR submitted!

@Abiji-2020, you are attempting to solve the issue and loot this Quest. Will you be successful?


Questions? Check out the docs.

@gemanor
Copy link
Collaborator

gemanor commented Nov 30, 2024

@Abiji-2020, yes, I would wait for #37 and then merge from main to ensure we have 90% coverage.
I'll let you know when mergin it.

@Abiji-2020
Copy link
Contributor Author

@Abiji-2020, yes, I would wait for #37 and then merge from main to ensure we have 90% coverage. I'll let you know when mergin it.

oh okayy,

@Abiji-2020
Copy link
Contributor Author

@gemanor any updates on #37

@gemanor
Copy link
Collaborator

gemanor commented Dec 11, 2024

No, we still waiting for Jay to submit the CR changes

@Abiji-2020
Copy link
Contributor Author

@gemanor do we need tests for the hooks??

@Abiji-2020
Copy link
Contributor Author

image
image

All the components have their individual unit tests, and also the complete flow test by combining it, the major reduce in coverage is due to hooks and

even though they are commented they are included in the coverage

@gemanor
Copy link
Collaborator

gemanor commented Dec 15, 2024

You can remove these files @Abiji-2020

@gemanor
Copy link
Collaborator

gemanor commented Dec 15, 2024

And to your question, yes, hooks has critical logic in it. All the hooks that being used, should have tests

@Abiji-2020
Copy link
Contributor Author

coverage increased to 90%

@gemanor
image
image

@Abiji-2020
Copy link
Contributor Author

@gemanor could you take a look at this?

@gemanor
Copy link
Collaborator

gemanor commented Dec 29, 2024

Hey @Abiji-2020, the tests have not been passed on my local machine. Can you check that?

This is the result:

stderr | tests/logout.test.tsx > Logout > should render the logout component and call process.exit
Mocked process.exit(0)

 ✓ tests/SelectProject.test.tsx (4)
 ✓ tests/hooks/useAuthApi.test.tsx (4)
 ✓ tests/PDPCheck.test.tsx (4)
 ✓ tests/lib/auth.test.ts (9)
 ✓ tests/EnvCopy.test.tsx (3) 425ms
 ✓ tests/EnvMember.test.tsx (2) 331ms
 ✓ tests/EnvSelect.test.tsx (7) 533ms
 ✓ tests/LoginFlow.test.tsx (5)
 ✓ tests/OPAPolicy.test.tsx (2)
 ✓ tests/PDPCheck.test.tsx (4)
 ✓ tests/PDPRun.test.tsx (1)
 ✓ tests/SelectEnvironment.test.tsx (4)
 ✓ tests/SelectOrganisation.test.tsx (5) 337ms
 ✓ tests/SelectProject.test.tsx (4)
 ❯ tests/apiKey.test.tsx (4)
   ❯ ApiKey (4)
     ✓ Should save the key
     ✓ Should validate the key
     × Should read the key
     ✓ Invalid Key
 ✓ tests/cli.test.tsx (1)
 ✓ tests/github.test.tsx (16) 3995ms
 ✓ tests/index.test.tsx (1)
 ✓ tests/login.test.tsx (1)
 ✓ tests/logout.test.tsx (1)
 ✓ tests/components/AuthProvider.test.tsx (5)
 ✓ tests/components/EnvironmentSelection.test.tsx (1)
 ✓ tests/components/PDPCommand.test.tsx (2)
 ✓ tests/hooks/useApiKeyAPI.test.tsx (6) 323ms
 ✓ tests/hooks/useAuthApi.test.tsx (4)
 ✓ tests/hooks/useEnvironmentApi.test.tsx (5)
 ✓ tests/hooks/useMemberAPI.test.tsx (2)
 ✓ tests/hooks/useOrganizationAPI.test.tsx (4)
 ✓ tests/hooks/useProjectAPI.test.tsx (2)
 ✓ tests/lib/api.test.ts (1)
 ✓ tests/lib/auth.test.ts (9)
 ✓ tests/lib/gitops_utils.test.ts (7)
 ✓ tests/utils/attributes.test.ts (12)

@Abiji-2020
Copy link
Contributor Author

Hey @Abiji-2020, the tests have not been passed on my local machine. Can you check that?

This is the result:

stderr | tests/logout.test.tsx > Logout > should render the logout component and call process.exit
Mocked process.exit(0)

 ✓ tests/SelectProject.test.tsx (4)
 ✓ tests/hooks/useAuthApi.test.tsx (4)
 ✓ tests/PDPCheck.test.tsx (4)
 ✓ tests/lib/auth.test.ts (9)
 ✓ tests/EnvCopy.test.tsx (3) 425ms
 ✓ tests/EnvMember.test.tsx (2) 331ms
 ✓ tests/EnvSelect.test.tsx (7) 533ms
 ✓ tests/LoginFlow.test.tsx (5)
 ✓ tests/OPAPolicy.test.tsx (2)
 ✓ tests/PDPCheck.test.tsx (4)
 ✓ tests/PDPRun.test.tsx (1)
 ✓ tests/SelectEnvironment.test.tsx (4)
 ✓ tests/SelectOrganisation.test.tsx (5) 337ms
 ✓ tests/SelectProject.test.tsx (4)
 ❯ tests/apiKey.test.tsx (4)
   ❯ ApiKey (4)
     ✓ Should save the key
     ✓ Should validate the key
     × Should read the key
     ✓ Invalid Key
 ✓ tests/cli.test.tsx (1)
 ✓ tests/github.test.tsx (16) 3995ms
 ✓ tests/index.test.tsx (1)
 ✓ tests/login.test.tsx (1)
 ✓ tests/logout.test.tsx (1)
 ✓ tests/components/AuthProvider.test.tsx (5)
 ✓ tests/components/EnvironmentSelection.test.tsx (1)
 ✓ tests/components/PDPCommand.test.tsx (2)
 ✓ tests/hooks/useApiKeyAPI.test.tsx (6) 323ms
 ✓ tests/hooks/useAuthApi.test.tsx (4)
 ✓ tests/hooks/useEnvironmentApi.test.tsx (5)
 ✓ tests/hooks/useMemberAPI.test.tsx (2)
 ✓ tests/hooks/useOrganizationAPI.test.tsx (4)
 ✓ tests/hooks/useProjectAPI.test.tsx (2)
 ✓ tests/lib/api.test.ts (1)
 ✓ tests/lib/auth.test.ts (9)
 ✓ tests/lib/gitops_utils.test.ts (7)
 ✓ tests/utils/attributes.test.ts (12)

I guess you have not stored any key in the keychain so it is missing let me check and update that

@gemanor
Copy link
Collaborator

gemanor commented Dec 30, 2024

@Abiji-2020, I extend the delay and now it passed locally, but not in the CI
Can you please check what happen in the CI and fix it?

@Abiji-2020
Copy link
Contributor Author

@gemanor the library we use for copying the ssh keys cannot run in the normal actions so for that to run properly I have created a PR #44

@gemanor
Copy link
Collaborator

gemanor commented Dec 30, 2024

Can we mock it instead? Having CI private versions could lead to security vulnerabilities and it's anti-pattern

@Abiji-2020
Copy link
Contributor Author

I have gone through it but it is a problem with the package clipboardy which we are using for copying there is also another solution that sindresorhus/clipboardy#63 (comment)

@gemanor
Copy link
Collaborator

gemanor commented Dec 30, 2024

It seems like it worked, but we still have problem with the keytar itself. Any idea?

@Abiji-2020
Copy link
Contributor Author

we can install the libsecret-1.so.0 package in the ci? or else we need to mock keytar in all of them

@gemanor
Copy link
Collaborator

gemanor commented Dec 30, 2024

What could be the implication of installing it in the CI?

@gemanor
Copy link
Collaborator

gemanor commented Dec 30, 2024

I added it on main, so you can revert the ci changes you made..

@Abiji-2020
Copy link
Contributor Author

All of them are working on the windows machine so let me check them and update them if any errors.

@gemanor
Copy link
Collaborator

gemanor commented Dec 30, 2024

Okay, now it all failed. I think it is better to mock the keytar functions too..

@gemanor
Copy link
Collaborator

gemanor commented Dec 30, 2024

I reverted the CI files, I think installing the lib-secret will just create more troubles. It's okay to mock the keytar IMO

@gemanor
Copy link
Collaborator

gemanor commented Dec 30, 2024

@Abiji-2020 please let me know when you have a version with keytar functions mocked, and I'll re-run the CI tests

@Abiji-2020
Copy link
Contributor Author

@Abiji-2020 please let me know when you have a version with keytar functions mocked, and I'll re-run the CI tests

ok @gemanor will update

@gemanor
Copy link
Collaborator

gemanor commented Dec 30, 2024

@Abiji-2020, this is a good progress, seems like we are mostly good with it

@Abiji-2020
Copy link
Contributor Author

yes 3 more test files should be modified .

@Abiji-2020
Copy link
Contributor Author

@gemanor updated and fixed CI

Copy link
Collaborator

@gemanor gemanor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gemanor gemanor merged commit 954a69e into permitio:main Dec 30, 2024
3 checks passed
Copy link

quest-bot bot commented Dec 30, 2024

🧚 @Abiji-2020 congratulations for completing Quest #12

💰 A reward of $250 has been credited to you.

To claim your $250 reward follow the instructions here.

Questions? Check out the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 Bounty claim ⚔️ Quest Tracks quest-bot quests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Proper Unit Test Coverage
2 participants