Skip to content

Limit 20 privs per purchase#993

Merged
isabeleliassen merged 1 commit intocsg-org:developmentfrom
InspiringApps:feat/limit-privilege-purchase-size
Aug 11, 2025
Merged

Limit 20 privs per purchase#993
isabeleliassen merged 1 commit intocsg-org:developmentfrom
InspiringApps:feat/limit-privilege-purchase-size

Conversation

@jusdino
Copy link
Copy Markdown
Contributor

@jusdino jusdino commented Aug 6, 2025

Requirements List

  • Set privilege purchase jurisdiction limit to 20

Testing List

  • Code review

Closes #714

Summary by CodeRabbit

  • New Features

    • Updated the maximum number of jurisdictions that can be selected per privilege purchase to 20.
  • Documentation

    • Added detailed explanation for the new limit to clarify its purpose for users.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 6, 2025

Walkthrough

The maximum allowed number of jurisdictions in the selectedJurisdictions array for privilege purchases was reduced from 100 to 20 in both the backend API model and its corresponding JSON schema. This change enforces a business rule to avoid exceeding Authorize.net's transaction line item limits.

Changes

Cohort / File(s) Change Summary
API Model Limit Update
backend/compact-connect/stacks/api_stack/v1_api/api_model.py
Reduced selectedJurisdictions array max_length from 100 to 20, with explanatory comment added.
Schema Update
backend/compact-connect/tests/resources/snapshots/PURCHASE_PRIVILEGE_REQUEST_SCHEMA.json
Updated JSON schema to set the maximum array length for selectedJurisdictions to 20 (was 100).

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant AuthorizeNet

    Client->>API: POST /purchase-privileges (selectedJurisdictions: [up to 20])
    API->>API: Validate selectedJurisdictions.length <= 20
    API->>AuthorizeNet: Create transaction (line items: privileges + fees)
    AuthorizeNet-->>API: Transaction result
    API-->>Client: Response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~6 minutes

Assessment against linked issues

Objective Addressed Explanation
Enforce system limit of 20 privileges per transaction in API model and schema (#714)
Ensure privilege purchase endpoint restricts selected jurisdictions to 20 max (#714)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Poem

A rabbit hopped through backend code,
Where privilege limits were bestowed.
No more than twenty, strict and neat,
To keep transactions light and sweet.
With schemas trimmed and models tight,
The system hops along just right! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94c24ff and b6aff42.

📒 Files selected for processing (2)
  • backend/compact-connect/stacks/api_stack/v1_api/api_model.py (1 hunks)
  • backend/compact-connect/tests/resources/snapshots/PURCHASE_PRIVILEGE_REQUEST_SCHEMA.json (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#882
File: backend/compact-connect/lambdas/python/common/cc_common/data_model/compact_configuration_client.py:287-359
Timestamp: 2025-07-08T18:40:24.408Z
Learning: In the CompactConnect codebase, landonshumway-ia prefers to avoid extraneous unit tests when existing test coverage is already sufficient to catch bugs. For the get_privilege_purchase_options method's live-jurisdiction filtering logic, the existing tests in the purchases test suite provide adequate coverage without needing additional edge case tests.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#852
File: backend/compact-connect/stacks/persistent_stack/__init__.py:545-549
Timestamp: 2025-06-09T22:03:03.232Z
Learning: In the CompactConnect codebase, production active_compact_member_jurisdictions configurations are very stable and unlikely to be removed. The vast majority of configuration errors in get_list_of_active_jurisdictions_for_compact_environment() will occur when developers are deploying sandbox environments, so error messages that primarily reference sandbox configuration are appropriate for the typical use case.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#882
File: backend/compact-connect/lambdas/python/migration/compact_configured_states_871/main.py:127-130
Timestamp: 2025-06-26T16:42:00.781Z
Learning: In the compact_configured_states_871 migration, existing jurisdiction configurations that have licenseeRegistrationEnabled: true are migrated with isLive: true for backwards compatibility. This prevents breaking existing live functionality since those states are already operational. The migration preserves the current live state of jurisdictions to maintain service continuity, while new states added after migration can start with isLive: false and be controlled by compact admins.
Learnt from: jusdino
PR: csg-org/CompactConnect#864
File: backend/compact-connect/tests/smoke/encumbrance_smoke_tests.py:256-262
Timestamp: 2025-06-18T21:57:02.978Z
Learning: The `licenseJurisdiction` field is a required field in the provider data API response from the `/v1/providers/users/me` endpoint, so it can be accessed directly without defensive programming checks.
📚 Learning: in the compactconnect codebase, landonshumway-ia prefers to avoid extraneous unit tests when existin...
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#882
File: backend/compact-connect/lambdas/python/common/cc_common/data_model/compact_configuration_client.py:287-359
Timestamp: 2025-07-08T18:40:24.408Z
Learning: In the CompactConnect codebase, landonshumway-ia prefers to avoid extraneous unit tests when existing test coverage is already sufficient to catch bugs. For the get_privilege_purchase_options method's live-jurisdiction filtering logic, the existing tests in the purchases test suite provide adequate coverage without needing additional edge case tests.

Applied to files:

  • backend/compact-connect/stacks/api_stack/v1_api/api_model.py
  • backend/compact-connect/tests/resources/snapshots/PURCHASE_PRIVILEGE_REQUEST_SCHEMA.json
📚 Learning: in the compactconnect codebase, production active_compact_member_jurisdictions configurations are ve...
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#852
File: backend/compact-connect/stacks/persistent_stack/__init__.py:545-549
Timestamp: 2025-06-09T22:03:03.232Z
Learning: In the CompactConnect codebase, production active_compact_member_jurisdictions configurations are very stable and unlikely to be removed. The vast majority of configuration errors in get_list_of_active_jurisdictions_for_compact_environment() will occur when developers are deploying sandbox environments, so error messages that primarily reference sandbox configuration are appropriate for the typical use case.

Applied to files:

  • backend/compact-connect/tests/resources/snapshots/PURCHASE_PRIVILEGE_REQUEST_SCHEMA.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: TestPython
🔇 Additional comments (1)
backend/compact-connect/stacks/api_stack/v1_api/api_model.py (1)

633-639: LGTM! Well-documented business rule implementation.

The change correctly implements the Authorize.net transaction limit constraint by reducing the maximum jurisdictions from 100 to 20. The detailed comment clearly explains the business rationale: each privilege uses one line item, with additional line items for administrative and credit card fees, necessitating a buffer to stay under the 30-item limit.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

Copy link
Copy Markdown
Collaborator

@landonshumway-ia landonshumway-ia left a comment

Choose a reason for hiding this comment

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

This looks good. Do we also want to consider adding a check in the lambda itself should the API gateway request validation ever change? I'm fine shipping this as is if you don't think it's necessary

@jusdino
Copy link
Copy Markdown
Contributor Author

jusdino commented Aug 7, 2025

I'd normally include it in the Marshmallow schema as well but in the case of this endpoint, we aren't using one. We could add it, of course.

@landonshumway-ia
Copy link
Copy Markdown
Collaborator

Makes sense, this is one of the first endpoints I think I implemented for this project, so I just didn't consider adding the Marshmallow schema for it. We can leave it as is for now.

@landonshumway-ia
Copy link
Copy Markdown
Collaborator

@jlkravitz This is ready for your review. Thanks

Copy link
Copy Markdown
Collaborator

@jlkravitz jlkravitz left a comment

Choose a reason for hiding this comment

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

@isabeleliassen good to merge!

@isabeleliassen isabeleliassen merged commit 902b337 into csg-org:development Aug 11, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend - set limit for how many privileges licensee can purchase within a single transaction

4 participants