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

chore(signature-collection): Swap out old endpoints for new ones #16260

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

juni-haukur
Copy link
Member

@juni-haukur juni-haukur commented Oct 3, 2024

...

Attach a link to issue if relevant

What

Specify what you're trying to achieve

Why

Specify why you need to achieve this

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Introduced several new API endpoints for managing lists and recommendations.
    • Enhanced capabilities to toggle list statuses and extend deadlines.
  • Bug Fixes

    • Updated endpoint descriptions for clarity and accuracy.
  • Refactor

    • Consolidated API interactions under a unified admin API structure.
    • Updated method names and request/response handling for better consistency.
  • Tests

    • Modified test cases to align with new DTO structures and API changes.

@juni-haukur juni-haukur requested a review from a team as a code owner October 3, 2024 14:49
Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

Walkthrough

The pull request introduces significant changes to the OpenAPI specification of the MedmaeliRestAPI, including the addition of new endpoints, updates to existing endpoint descriptions, and modifications to request and response schemas. Additionally, the SignatureCollectionAdminClientService has been refactored to replace API calls with a unified adminApi. The test suite has also been updated to accommodate a new data transfer object (DTO) and to reflect changes in API call mocks.

Changes

File Path Change Summary
libs/clients/signature-collection/src/clientConfig.json Updated OpenAPI specification with new endpoints and modified descriptions and schemas.
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts Refactored API calls to use adminApi, updated method names, and enhanced error handling.
libs/clients/signature-collection/src/lib/signature-collection.service.spec.ts Introduced FrambodDTO, updated test cases to reflect new DTO and API call changes.
libs/clients/signature-collection/src/lib/signature-collection.service.ts Renamed variables, updated method calls, and simplified error handling in the SignatureCollectionClientService.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • albinagu

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.

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: 13

🧹 Outside diff range and nitpick comments (8)
libs/clients/signature-collection/src/clientConfig.json (4)

180-181: Improved endpoint description, but consider clarifying the shouldToggle parameter.

The updated summary and description provide better context for the endpoint's functionality. However, there are a few points to consider:

  1. The description mentions "Hægt að opna aftur fyrir úrvinnslu," but it's not clear how this relates to the shouldToggle parameter.
  2. The shouldToggle parameter's description states it's "Optional. Sjálfkrafa true," which might be confusing. Consider clarifying if it means the default value is true.

Consider updating the description to explicitly mention how the shouldToggle parameter affects the action, especially when set to false.

Also applies to: 184-189


302-302: Improved endpoint description, but consider enhancing the response details.

The updates to this endpoint are beneficial:

  1. The summary now clearly explains the purpose of the endpoint.
  2. The ID parameter description is more specific.
  3. A description for the request body has been added.

These changes improve the API's clarity. However, to further enhance the documentation:

Consider adding a description for the response body in the "responses" section. This could include details about the structure of the returned MedmaeliDTO objects and any potential error responses.

Also applies to: 307-307, 313-313


453-453: New comparison endpoint added, but consider enhancing the documentation.

The new /Admin/Medmaelasofnun/{ID}/Compare endpoint is a useful addition:

  1. It provides a way to compare recommendations across an entire collection.
  2. The summary clearly states the purpose of the endpoint.

However, there are opportunities to improve the documentation:

  1. Consider adding a more detailed description of how the comparison works and what criteria are used.
  2. Clarify the format of the kennitala strings in the request body (e.g., any specific format requirements).
  3. Provide more information about the structure of the MedmaeliDTO objects returned in the response.
  4. Include details about possible error responses and their meanings.

These additions would make the API more user-friendly and reduce potential misunderstandings.

Also applies to: 458-458, 464-464


Line range hint 1-2500: Overall improvements to the API, with some suggestions for further enhancement.

The changes to the MedmaeliRestAPI specification bring several improvements:

  1. New endpoints have been added, expanding the API's functionality.
  2. Existing endpoint descriptions have been clarified and enhanced.
  3. New parameters have been introduced to provide more flexibility.

These changes will likely improve the usability and understanding of the API for consumers. However, there are some general suggestions for further improvement:

  1. Consistency: Ensure that all endpoints follow the same pattern for parameter descriptions, response details, and error handling.
  2. Error Responses: Consider adding more detailed error response descriptions for each endpoint, especially for the new ones.
  3. Authentication and Authorization: While the API uses bearer token authentication, consider documenting any specific authorization requirements for different endpoints, especially the admin ones.
  4. Versioning: As the API evolves, consider implementing and documenting a versioning strategy to manage future changes without breaking existing integrations.
  5. Rate Limiting: If applicable, add information about any rate limiting applied to the API endpoints.

Implementing these suggestions would further enhance the robustness and user-friendliness of the API documentation.

libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (4)

Line range hint 135-154: Add error handling for creating lists in createListsAdmin.

The API call to adminFrambodPost lacks error handling. Enclose it in a try-catch block to manage exceptions and handle cases where the API call may fail.

Apply this diff to add error handling:

+    try {
      const candidacy = await this.getApiWithAuth(
        this.adminApi,
        auth,
      ).adminFrambodPost({
        frambodRequestDTO: {
          sofnunID: parseInt(id),
          kennitala: owner.nationalId,
          simi: owner.phone,
          netfang: owner.email,
          medmaelalistar: filteredAreas.map((area) => ({
            svaediID: parseInt(area.id),
            listiNafn: `${owner.name} - ${area.name}`,
          })),
        },
      })
      return {
        slug: getSlug(
          candidacy.id ?? '',
          candidacy.medmaelasofnun?.kosningTegund ?? '',
        ),
      }
+    } catch (error) {
+      // Handle the error appropriately
+      throw new Error('Failed to create lists: ' + error.message)
+    }

Line range hint 324-332: Add error handling for the API call in getAreaSummaryReport.

Although a try-catch block is present, returning an empty AreaSummaryReport could mask underlying issues. Consider logging the error or providing more informative feedback.


Line range hint 339-350: Add error handling for signatureLookup.

Wrap the API call to adminMedmaelasofnunIDComparePost in a try-catch block to handle potential errors and ensure consistent error management.


Line range hint 356-364: Add error handling for the API call in lockList.

Enclose the API call to adminMedmaelalistiIDLockListPatch within a try-catch block to manage possible exceptions and provide meaningful feedback.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7b20920 and 2787baf.

📒 Files selected for processing (4)
  • libs/clients/signature-collection/src/clientConfig.json (5 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (11 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection.service.spec.ts (5 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection.service.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/clients/signature-collection/src/clientConfig.json (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-admin.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/clients/signature-collection/src/lib/signature-collection.service.spec.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 (16)
libs/clients/signature-collection/src/clientConfig.json (1)

261-262: Improved endpoint description and parameter clarity.

The updates to this endpoint are beneficial:

  1. The summary now clearly states the purpose of the endpoint.
  2. The description provides important context about when the endpoint can be used.
  3. The newEndDate parameter description is more precise.

These changes enhance the API's usability and help prevent misuse of the endpoint.

Also applies to: 267-267, 274-274

libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (2)

10-16: Imports are correctly updated.

The addition of getSlug to the imports from ./types/list.dto is appropriate and aligns with its usage within the code.


303-306: Proper error handling implemented in removeCandidate.

Wrapping the API call in a try-catch block effectively manages potential errors.

libs/clients/signature-collection/src/lib/signature-collection.service.spec.ts (6)

10-10: LGTM!

The import of FrambodDTO is correct and necessary for usage in the code.


267-268: LGTM!

The test correctly mocks frambodApi.frambodPost to return the expected candidacy object.


272-272: LGTM!

The mock for getApiWithAuth correctly returns frambodApi on the second call.


300-301: LGTM!

The test correctly mocks frambodApi.frambodIDDelete to resolve successfully.


350-350: LGTM!

The test correctly mocks listarApi.medmaelalistarIDMedmaeliPost to return the expected response.


267-268: Verify that all API method updates are applied consistently throughout the codebase

Given the method signature updates outlined in the pull request, ensure that all occurrences of the old API methods have been replaced with the new ones. This includes:

  • medmaelalistarAddListarPostframbodPost
  • medmaeliIDRemoveMedmaeliUserPostmedmaeliIDDelete
  • medmaelalistarIDAddMedmaeliPostmedmaelalistarIDMedmaeliPost

Run the following script to check for any remaining references to the old methods:

Also applies to: 300-301, 350-350, 396-396

✅ Verification successful

Please run the following script to verify that all old API method references have been removed:


All old API method references have been successfully removed from the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining references to old API methods.

# Test: Search for old method names in the codebase.
rg --type typescript 'medmaelalistarAddListarPost|medmaeliIDRemoveMedmaeliUserPost|medmaelalistarIDAddMedmaeliPost'

Length of output: 152


Script:

#!/bin/bash
# Description: Search for any remaining references to old API methods in TypeScript files.

rg 'medmaelalistarAddListarPost|medmaeliIDRemoveMedmaeliUserPost|medmaelalistarIDAddMedmaeliPost' --glob '*.ts' --glob '*.tsx'

Length of output: 128

libs/clients/signature-collection/src/lib/signature-collection.service.ts (7)

139-142: Validate candidacy properties before using them

Ensure that candidacy.id and candidacy.medmaelasofnun?.kosningTegund are not undefined or null to prevent potential runtime errors.

Consider adding validation checks before returning the slug.


123-142: Confirm API endpoint and request structure

The change to use frambodPost and the new request structure appears appropriate. Ensure that this aligns with the updated API specifications.


264-266: Update to new API method looks correct

The switch to medmaelalistarIDMedmaeliPost seems consistent with the API changes.


312-314: Change to delete signature using medmaeliIDDelete is appropriate

The update aligns with the new endpoint for removing signatures.


334-337: Removal of candidacy using frambodIDDelete is correct

This change correctly updates the method for deleting a candidacy.


127-127: ⚠️ Potential issue

Specify radix parameter in parseInt to ensure correct number parsing

When using parseInt, it's best practice to specify the radix to avoid unexpected results due to different number formats.

Apply this diff to fix the issue:

-        sofnunID: parseInt(id),
+        sofnunID: parseInt(id, 10),

Likely invalid or redundant comment.


134-134: ⚠️ Potential issue

Specify radix parameter in parseInt when parsing area.id

To ensure consistent parsing of numerical strings, explicitly specify the radix.

Apply this diff to fix the issue:

-              svaediID: parseInt(area.id),
+              svaediID: parseInt(area.id, 10),

Likely invalid or redundant comment.

@datadog-island-is
Copy link

Datadog Report

All test runs 04ca256 🔗

4 Total Test Services: 0 Failed, 4 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.06%), 1 increased (+0.01%), 8 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 3.26s 1 no change Link
application-system-api 0 0 0 120 2 3m 30.06s 1 no change Link
application-template-api-modules 0 0 0 135 0 2m 6.2s 1 increased (+0.01%) Link
application-ui-shell 0 0 0 74 0 37.32s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • clients-signature-collection - jest 22% (-0.06%) - Details

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 6.66667% with 14 lines in your changes missing coverage. Please review.

Project coverage is 36.93%. Comparing base (f522e6f) to head (728b6c2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tion/src/lib/signature-collection-admin.service.ts 10.00% 9 Missing ⚠️
...collection/src/lib/signature-collection.service.ts 0.00% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16260   +/-   ##
=======================================
  Coverage   36.92%   36.93%           
=======================================
  Files        6781     6781           
  Lines      140030   139997   -33     
  Branches    39815    39803   -12     
=======================================
- Hits        51705    51703    -2     
+ Misses      88325    88294   -31     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.63% <6.66%> (ø)
application-template-api-modules 24.40% <ø> (+0.01%) ⬆️
application-ui-shell 21.29% <ø> (ø)

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

Files with missing lines Coverage Δ
...collection/src/lib/signature-collection.service.ts 6.97% <0.00%> (+0.03%) ⬆️
...tion/src/lib/signature-collection-admin.service.ts 12.68% <10.00%> (-0.10%) ⬇️

... and 4 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 f522e6f...728b6c2. Read the comment docs.

@albinagu albinagu added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants