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(accept-blue): Numerous differen bug fixes, see description #538

Merged
merged 7 commits into from
Nov 21, 2024

Conversation

martijnvdbrug
Copy link
Member

@martijnvdbrug martijnvdbrug commented Nov 21, 2024

Description

Breaking changes

  • DB migration needed: CustomerId is now nullable

Checklist

📌 Always:

  • Set a clear title
  • I have checked my own PR

👍 Most of the time:

  • Added or updated test cases
  • Updated the README

📦 For publishable packages:

  • Increased the version number in package.json
  • Added changes to the CHANGELOG.md

Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request involve modifications to the AcceptBluePlugin class, enhancing its configuration by adding nullable and readonly custom fields for OrderLine and Customer entities. The error handling in the acceptBluePaymentHandler has been improved to return a declined state instead of throwing errors. Additionally, new test cases for the getNrOfBillingCyclesLeft function have been added, and the billing cycle calculation logic has been refined. A new export statement has also been introduced to expand the public API.

Changes

File Path Change Summary
packages/vendure-plugin-accept-blue/src/accept-blue-plugin.ts Updated import statement, modified static init return type, added custom fields with attributes.
packages/vendure-plugin-accept-blue/src/api/accept-blue-handler.ts Enhanced createPayment method with try-catch for error handling.
packages/vendure-plugin-accept-blue/src/index.ts Added export statement for custom-field-types.
packages/vendure-plugin-accept-blue/src/util.spec.ts Introduced a test suite for getNrOfBillingCyclesLeft with multiple test cases.
packages/vendure-plugin-accept-blue/src/util.ts Updated getNrOfBillingCyclesLeft and getDaysBetweenBillingCycles functions for improved logic.
packages/vendure-plugin-accept-blue/vitest.config.js Modified test property to remove specific test file inclusion.

Assessment against linked issues

Objective Addressed Explanation
Accept Blue can accidently end up in an unwanted auto renew scenario (#532)
acceptBlueCustomerId should be nullable (#531)
acceptBlueCustomerId should be a readonly hidden customField (#519)
Accept Blue payment handler should return Declined instead of throwing (#493)

Possibly related PRs

Warning

Rate limit exceeded

@martijnvdbrug has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 50 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 9961b96 and 29b1c5c.


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@martijnvdbrug martijnvdbrug marked this pull request as ready for review November 21, 2024 14:09
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: 3

🧹 Outside diff range and nitpick comments (1)
packages/vendure-plugin-accept-blue/src/accept-blue-plugin.ts (1)

53-54: Breaking change: Database migration required

The changes correctly implement the nullable and readonly flags for acceptBlueCustomerId as requested in issues #531 and #519. However, making the field nullable requires a database migration.

Please ensure you:

  1. Create a migration script
  2. Document the breaking change in the changelog
  3. Update the version number according to semver
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 05022f0 and 529ae1c.

⛔ Files ignored due to path filters (1)
  • packages/vendure-plugin-accept-blue/package.json is excluded by !**/*.json
📒 Files selected for processing (6)
  • packages/vendure-plugin-accept-blue/src/accept-blue-plugin.ts (3 hunks)
  • packages/vendure-plugin-accept-blue/src/api/accept-blue-handler.ts (2 hunks)
  • packages/vendure-plugin-accept-blue/src/index.ts (1 hunks)
  • packages/vendure-plugin-accept-blue/src/util.spec.ts (1 hunks)
  • packages/vendure-plugin-accept-blue/src/util.ts (2 hunks)
  • packages/vendure-plugin-accept-blue/vitest.config.js (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/vendure-plugin-accept-blue/src/index.ts (1)
Learnt from: martijnvdbrug
PR: Pinelab-studio/pinelab-vendure-plugins#458
File: packages/vendure-plugin-accept-blue/src/index.ts:2-2
Timestamp: 2024-11-12T08:32:12.721Z
Learning: Exports in index files are always allowed because these are publishable packages.
🔇 Additional comments (8)
packages/vendure-plugin-accept-blue/vitest.config.js (1)

5-5: Verify test discovery after removing include pattern

The empty test configuration will now discover tests throughout the project. Let's verify all tests are still being picked up.

✅ Verification successful

Empty test config is fine, all test files are discoverable

The empty test configuration test: {} works correctly as it allows Vitest to discover all test files in the project. The search results confirm that both test files for the accept-blue plugin are discoverable:

  • ./packages/vendure-plugin-accept-blue/src/util.spec.ts
  • ./packages/vendure-plugin-accept-blue/test/accept-blue.spec.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test file locations and ensure they're discoverable

# Find all test files
echo "Test files in the project:"
fd -e ts -e js --full-path . -x echo {} | grep -E "spec\.(ts|js)$"

# Check if vitest can discover these files
vitest --list

Length of output: 2703

packages/vendure-plugin-accept-blue/src/index.ts (1)

10-10: LGTM! Export aligns with PR objectives.

The new export for custom field types matches the requirements for making customer.customerId nullable and readonly.

packages/vendure-plugin-accept-blue/src/accept-blue-plugin.ts (3)

1-1: LGTM!

The Type import is correctly added to support the init method's return type.


64-64: LGTM!

The return type change to Type<AcceptBluePlugin> is more accurate and type-safe.


48-49: Verify the necessity of OrderLine field changes

The changes to make acceptBlueSubscriptionIds nullable and readonly weren't mentioned in the PR objectives. Please confirm if these changes are intentional and necessary.

✅ Verification successful

Field changes are intentional and necessary

The changes to make acceptBlueSubscriptionIds nullable and readonly are justified based on the codebase analysis:

  • The field is only written once in accept-blue-service.ts when setting subscription IDs
  • It's primarily used for reading subscription data as shown in multiple query operations
  • The CHANGELOG indicates this field was recently refactored from subscriptionIds specifically to avoid conflicts
  • The field can be null as evidenced by the null coalescing operator in the service: orderLine.customFields.acceptBlueSubscriptionIds ?? []
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if these fields are used elsewhere in the codebase
rg "acceptBlueSubscriptionIds" -B 2 -A 2

Length of output: 6588

packages/vendure-plugin-accept-blue/src/util.ts (3)

126-128: LGTM! This fixes the subscription counting issue.

The change from Math.floor to Math.ceil correctly addresses issue #532 by preventing subscriptions from being treated as ongoing when they should end.


134-135: LGTM! Daily frequency support added.

Simple and correct implementation for daily billing cycles.


151-151: LGTM! Added TypeScript safety comment.

The eslint comment helps prevent runtime errors while maintaining type safety.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 529ae1c and b217c98.

📒 Files selected for processing (1)
  • packages/vendure-plugin-accept-blue/CHANGELOG.md (1 hunks)

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

🧹 Outside diff range and nitpick comments (1)
packages/vendure-plugin-accept-blue/test/accept-blue.spec.ts (1)

193-202: Consider adding test cleanup

The test correctly sets up the mock customerId, but it should clean up the test data after completion to prevent potential interference with other tests.

Add this cleanup step after the test:

  it('Gets saved payment methods for logged in customer', async () => {
    // ... existing test code ...
+   // Clean up after test
+   afterEach(async () => {
+     await server.app
+       .get(DataSource)
+       .getRepository(Customer)
+       .update(
+         { id: 1 },
+         {
+           customFields: { acceptBlueCustomerId: null },
+         }
+       );
+   });
  });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b217c98 and 9961b96.

📒 Files selected for processing (1)
  • packages/vendure-plugin-accept-blue/test/accept-blue.spec.ts (3 hunks)

@martijnvdbrug martijnvdbrug merged commit 709d0bf into main Nov 21, 2024
2 checks passed
@martijnvdbrug martijnvdbrug deleted the accept-blue-fixes-november branch November 21, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant