stack/apps/backend
BilalG1 f146ff21f1
fix ungrouped include by default (#924)
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

<!-- RECURSEML_SUMMARY:START -->
## High-level PR Summary
This PR fixes a bug where ungrouped offers with `include-by-default`
pricing were not being automatically included in subscription lists. The
fix ensures that ungrouped default offers are now properly added to the
subscriptions array when no explicit database subscription exists for
them, matching the existing behavior for grouped offers. Additionally,
it adds validation to prevent multiple `include-by-default` offers from
being configured within the same group.

⏱️ Estimated Review Time: 15-30 minutes

<details>
<summary>💡 Review Order Suggestion</summary>

| Order | File Path |
|-------|-----------|
| 1 | `apps/backend/src/lib/payments.tsx` |
| 2 | `apps/backend/src/lib/payments.test.tsx` |
</details>



[![Need help? Join our
Discord](https://img.shields.io/badge/Need%20help%3F%20Join%20our%20Discord-5865F2?style=plastic&logo=discord&logoColor=white)](https://discord.gg/n3SsVDAW6U)

<!-- RECURSEML_SUMMARY:END -->
<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Fixes bug to include ungrouped `include-by-default` offers in
subscriptions and adds validation for multiple offers in the same group.
> 
>   - **Behavior**:
> - Fixes bug in `getSubscriptions()` in `payments.tsx` to include
ungrouped `include-by-default` offers in subscriptions when no explicit
subscription exists.
> - Adds validation in `getSubscriptions()` to prevent multiple
`include-by-default` offers in the same group.
>   - **Tests**:
> - Adds test cases in `payments.test.tsx` to verify inclusion of
ungrouped `include-by-default` offers and validation of multiple offers
in the same group.
>   - **Misc**:
> - Updates import in `payments.test.tsx` to include `getSubscriptions`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for 565acc31cb. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* New Features
* Subscriptions now automatically include eligible “include-by-default”
items even when they aren’t tied to a catalog, granting access without
requiring an explicit subscription.
* Consistent handling of catalog-level default items when no prior
subscriptions exist.

* Improvements
* Expanded subscriptions data to ensure all applicable default products
are surfaced to users.

* Tests
* Added comprehensive tests for default-inclusion behavior and edge
cases to improve reliability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-10-07 09:19:40 -07:00
..
prisma Rename offer to product, offer group to product catalog (#914) 2025-10-04 02:28:28 -07:00
scripts Rename offer to product, offer group to product catalog (#914) 2025-10-04 02:28:28 -07:00
src fix ungrouped include by default (#924) 2025-10-07 09:19:40 -07:00
.env encrypt neon connection strings, update connections route (#879) 2025-09-09 21:35:07 +00:00
.env.development Workflow queue 2025-09-03 13:31:40 -07:00
.eslintrc.cjs tsup for stack-shared (#647) 2025-04-28 21:26:52 -07:00
.gitignore Migrations toolkit (#409) 2025-02-01 17:46:21 -08:00
CHANGELOG.md chore: update package versions 2025-09-26 23:16:39 -05:00
LICENSE Split backend and dashboard (#83) 2024-06-18 15:49:31 +02:00
next.config.mjs Fix STACK-SERVER-QP 2025-02-17 11:12:34 -08:00
package.json Update import-in-the-middle 2025-10-03 16:24:04 -07:00
sentry.client.config.ts JS lib docs (#444) 2025-02-20 00:48:05 +01:00
tsconfig.json In-source unit tests (#429) 2025-02-14 11:47:52 -08:00
vitest.config.ts Auto migration (#526) 2025-07-24 02:38:37 +02:00