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

fix(signature-colletion): remove candidate if all lists removed #16425

Merged
merged 6 commits into from
Oct 16, 2024

Conversation

alexdiljar
Copy link
Member

@alexdiljar alexdiljar commented Oct 16, 2024

Candidate is not removed when the last list is removed. This fixes that

Summary by CodeRabbit

  • New Features

    • Enhanced API definitions with an order property for better structure.
    • Added a new method to manage candidate removal when no lists are owned.
  • Improvements

    • Simplified logic for determining candidate national IDs.
    • Updated error message for better user guidance regarding candidacy details.
    • Improved readability in method parameter destructuring.
    • Simplified logic for checking invalid signatures.

@alexdiljar alexdiljar requested a review from a team as a code owner October 16, 2024 11:46
Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The pull request includes modifications to several files related to the parliamentary list creation service. Key changes involve simplifying dependencies, enhancing method readability, and streamlining logic for candidate validation. Additionally, API definitions have been updated to include an order property for better structure, and error messages have been revised to provide more context. A new private method for handling candidate removal has also been introduced in the signature collection client service.

Changes

File Change Summary
libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-creation/parliamentary-list-creation.service.ts Removed ReasonKey import, improved parameter destructuring in parliamentaryCollection, streamlined contactNationalId logic, and retained error throwing for invalid collections or candidates.
libs/application/templates/signature-collection/parliamentary-list-creation/src/dataProviders/index.ts Added order property to CandidateApi, ParliamentaryCollectionApi, and ParliamentaryIdentityApi with values 0, 1, and 2, respectively.
libs/application/templates/signature-collection/parliamentary-list-creation/src/lib/errors.ts Updated defaultMessage for alreadyCandidate error to provide additional context regarding candidacy information.
libs/clients/signature-collection/src/lib/signature-collection.service.ts Introduced checkIfRemoveCandidate method to manage candidate removal, updated removeLists to call this method, and simplified logic in canSign for checking invalid signatures.

Possibly related PRs

Suggested labels

high priority

Suggested reviewers

  • juni-haukur
  • kksteini

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1faf57e and bc78b25.

📒 Files selected for processing (1)
  • libs/clients/signature-collection/src/lib/signature-collection.service.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/clients/signature-collection/src/lib/signature-collection.service.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kksteini kksteini added the automerge Merge this PR as soon as all checks pass label Oct 16, 2024
coderabbitai[bot]
coderabbitai bot previously requested changes Oct 16, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (1)
libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-creation/parliamentary-list-creation.service.ts (1)

Line range hint 46-62: Approved changes with a minor suggestion.

The modifications to the parliamentaryCollection method improve code readability and simplify the logic. The added comment provides valuable context for the implementation. These changes align well with our coding guidelines for reusability and TypeScript usage.

Consider using the non-null assertion operator (!) for auth.nationalId to avoid potential TypeScript errors, as it's a crucial part of the logic:

(c) => c.nationalId.replace('-', '') === auth.nationalId!,

This change ensures that TypeScript understands that auth.nationalId will always be defined in this context.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a6999da and e766a58.

📒 Files selected for processing (4)
  • libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-creation/parliamentary-list-creation.service.ts (2 hunks)
  • libs/application/templates/signature-collection/parliamentary-list-creation/src/dataProviders/index.ts (1 hunks)
  • libs/application/templates/signature-collection/parliamentary-list-creation/src/lib/errors.ts (1 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-creation/parliamentary-list-creation.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/signature-collection/parliamentary-list-creation/src/dataProviders/index.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/signature-collection/parliamentary-list-creation/src/lib/errors.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/clients/signature-collection/src/lib/signature-collection.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (5)
libs/application/templates/signature-collection/parliamentary-list-creation/src/dataProviders/index.ts (1)

5-5: LGTM! The addition of the order property enhances API structure.

The changes introduce an order property to each API definition, which provides a clear sequence for these APIs. This addition:

  1. Improves the structure and organization of the API definitions.
  2. Could facilitate easier processing or rendering of these APIs in a specific order.
  3. Maintains consistency across all three constants.

The modifications align well with the coding guidelines for files in the libs directory, ensuring reusability and proper TypeScript usage.

Also applies to: 10-10, 15-15

libs/application/templates/signature-collection/parliamentary-list-creation/src/lib/errors.ts (1)

37-37: Improved error message clarity and user guidance

The update to the alreadyCandidate error message is a positive change. It not only informs users that they are already candidates but also guides them to where they can find more information about their candidacy ("Mínar Síður"). This enhancement improves the user experience by providing clear next steps, which is particularly important in error scenarios.

libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-creation/parliamentary-list-creation.service.ts (1)

Line range hint 1-162: Compliance with coding guidelines confirmed.

This file adheres to the coding guidelines for libs/**/*:

  1. It uses TypeScript effectively for defining props and exporting types.
  2. The service is designed to be reusable across different NextJS apps.
  3. There are no apparent issues with tree-shaking or bundling practices.
libs/clients/signature-collection/src/lib/signature-collection.service.ts (2)

419-419: Confirm logic for detecting invalid signatures.

The assignment const noInvalidSignature = !signatures?.find((s) => !s.valid) relies on the assumption that if signatures is undefined or empty, there are no invalid signatures. Ensure this aligns with the intended logic.

Run the following script to test the behavior when signatures is undefined or empty:

#!/bin/bash
# Description: Verify noInvalidSignature logic when signatures are undefined or empty.

# Expected: noInvalidSignature should be true when signatures is undefined or an empty array.

echo "Testing with signatures undefined:"
node -e "
  const signatures = undefined;
  const noInvalidSignature = !signatures?.find((s) => !s.valid);
  console.log('noInvalidSignature (undefined):', noInvalidSignature);
"

echo "Testing with signatures empty array:"
node -e "
  const signatures = [];
  const noInvalidSignature = !signatures?.find((s) => !s.valid);
  console.log('noInvalidSignature (empty array):', noInvalidSignature);
"

This script will confirm that noInvalidSignature evaluates to true when signatures is undefined or empty.


372-374: Handle potential parsing errors of candidate ID.

The parseInt(id) function may return NaN if id is not a valid number string, which could cause frambodIDDelete to fail.

Run the following script to verify that all candidate IDs are valid numeric strings:

This script searches for instances where candidate.id is used and extracts the IDs to ensure they are numeric.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 16, 2024

Datadog Report

All test runs ffddea5 🔗

5 Total Test Services: 0 Failed, 5 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.04%), 10 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.69s 1 no change Link
application-system-api 0 0 0 120 2 2m 50.46s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 21.31s 1 no change Link
application-ui-shell 0 0 0 74 0 33.12s 1 no change Link
judicial-system-web 0 0 0 338 0 1m 4.17s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • clients-signature-collection - jest 21.96% (-0.04%) - Details

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 36.72%. Comparing base (775afb3) to head (a62ab1d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...collection/src/lib/signature-collection.service.ts 0.00% 6 Missing ⚠️
...st-creation/parliamentary-list-creation.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16425   +/-   ##
=======================================
  Coverage   36.72%   36.72%           
=======================================
  Files        6809     6809           
  Lines      141163   141134   -29     
  Branches    40246    40235   -11     
=======================================
- Hits        51844    51835    -9     
+ Misses      89319    89299   -20     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.41% <0.00%> (-0.01%) ⬇️
application-template-api-modules 27.89% <0.00%> (+0.01%) ⬆️
application-ui-shell 21.35% <ø> (ø)
judicial-system-api 18.36% <ø> (ø)
judicial-system-backend 55.15% <ø> (ø)
judicial-system-formatters 79.25% <ø> (ø)
judicial-system-web 27.91% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...iamentary-list-creation/src/dataProviders/index.ts 100.00% <ø> (ø)
...tion/parliamentary-list-creation/src/lib/errors.ts 100.00% <ø> (ø)
...st-creation/parliamentary-list-creation.service.ts 29.03% <0.00%> (+1.33%) ⬆️
...collection/src/lib/signature-collection.service.ts 6.78% <0.00%> (-0.16%) ⬇️

... and 9 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 775afb3...a62ab1d. Read the comment docs.

….service.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@alexdiljar alexdiljar dismissed coderabbitai[bot]’s stale review October 16, 2024 13:09

Minor suggestions, need to merge for release asap

@alexdiljar alexdiljar changed the title fix: remove candidate if all lists removed fix(signature-colletion): remove candidate if all lists removed Oct 16, 2024
@island-is island-is deleted a comment from coderabbitai bot Oct 16, 2024
@island-is island-is deleted a comment from coderabbitai bot Oct 16, 2024
@alexdiljar alexdiljar added the high priority VIP-Kodiak PR label Oct 16, 2024
@kodiakhq kodiakhq bot merged commit 4a5ebba into main Oct 16, 2024
44 checks passed
@kodiakhq kodiakhq bot deleted the fix/SignatureCollectionTestingIntensive branch October 16, 2024 14:33
kksteini pushed a commit that referenced this pull request Oct 16, 2024
* fix: remove candidate if all lists removed

* fix: remove candidate if all lists removed make sure has candidate id

* chore: nx format:write update dirty files

* Update libs/clients/signature-collection/src/lib/signature-collection.service.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
kodiakhq bot added a commit that referenced this pull request Oct 16, 2024
* fix(signature-colletion): remove candidate if all lists removed (#16425)

* fix: remove candidate if all lists removed

* fix: remove candidate if all lists removed make sure has candidate id

* chore: nx format:write update dirty files

* Update libs/clients/signature-collection/src/lib/signature-collection.service.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(signature-collections): fixes 16.10 (#16423)

* fix(signature-collections): fixes 16.10

* tweak

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(signature-collection): sc fixes 16.10 (#16428)

* fix(signature-collection): updating card

* cleanup

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

---------

Co-authored-by: Alex Diljar Birkisbur Hellsing <42963845+alexdiljar@users.noreply.github.com>
Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: albinagu <47886428+albinagu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass high priority VIP-Kodiak PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants