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

feat: add hasPlugin method #3963

Merged
merged 8 commits into from
Jun 3, 2022
Merged

feat: add hasPlugin method #3963

merged 8 commits into from
Jun 3, 2022

Conversation

is2ei
Copy link
Contributor

@is2ei is2ei commented Jun 1, 2022

Related to fastify/fastify-secure-session#143

Checklist

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

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

LGTM.

docs/Reference/Server.md Outdated Show resolved Hide resolved
docs/Reference/Server.md Outdated Show resolved Hide resolved
fastify.js Outdated Show resolved Hide resolved
test/plugin.test.js Outdated Show resolved Hide resolved
Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

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

Can you separate the test in a independent unit test case.
People do not know what is the goal for that test if it mixed in the existing one.

The unit test should includes

  1. function existence check (optional)
  2. positive use-case (e.g. @fastify/secure-session)
  3. negative use-case (e.g. it should return false when the plugin is not registered)

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

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

negative use-case (e.g. it should return false when the plugin is not registered)

Looking at the edited changes there is not an encapsulation test too:

root
  |--- plugin 1
  |      |----pluging foo
  |             |----- plugin bar (hasPlugin foo true)
  |--- plugin 2 (hasPlugin foo false)

@is2ei
Copy link
Contributor Author

is2ei commented Jun 2, 2022

@climba03003 @Eomm
Thanks for your comments. I separated the tests. Could you review it?
76ee510

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

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

I think the implementation is a bit too naive. See:

❯ node
Welcome to Node.js v16.15.0.
Type ".help" for more information.
> var foo = 'fastify -> plugin-FOO -> plugin-AB -> plugin-AC'
undefined
> foo.includes('plugin-A')
true
>

We need a test case that covers the above and the function needs to be written such that it will return false.

@is2ei
Copy link
Contributor Author

is2ei commented Jun 2, 2022

@jsumners
Thanks for your comments.
I guess you are talking about String.prototype.includes().
But hasPlugin method uses Array.prototype.includes().
Anyway, I'll add test cases for that.

@is2ei
Copy link
Contributor Author

is2ei commented Jun 2, 2022

@jsumners
I modified the test cases.
8a22678

When the pluginName returns fastify -> plugin-AA, fastify.hasPlugin('plugin-AA') will return true and fastify.hasPlugin('plugin-A') will return false. Does it answer your question?

@is2ei is2ei requested a review from jsumners June 2, 2022 13:49
@jsumners jsumners merged commit 99ffba9 into fastify:main Jun 3, 2022
@github-actions
Copy link

github-actions bot commented Jun 4, 2023

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 4, 2023
@is2ei is2ei deleted the has-plugin-method branch June 17, 2023 12:04
@jsumners jsumners added notable-change A change that should be explicitly outlined in release notes and migration guides and removed notable labels Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
notable-change A change that should be explicitly outlined in release notes and migration guides
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants