Skip to content

feat(condo): DOMA-13327 webhook after subscription activation#7699

Open
nomerdvadcatpyat wants to merge 4 commits into
mainfrom
feat/condo/DOMA-13327/webhook-after-activate-subscription
Open

feat(condo): DOMA-13327 webhook after subscription activation#7699
nomerdvadcatpyat wants to merge 4 commits into
mainfrom
feat/condo/DOMA-13327/webhook-after-activate-subscription

Conversation

@nomerdvadcatpyat
Copy link
Copy Markdown
Member

@nomerdvadcatpyat nomerdvadcatpyat commented Jun 4, 2026

Summary by CodeRabbit

  • New Features

    • Subscription activation now triggers webhook notifications to configured endpoints, including invoice payment details and organization information.
  • Chores

    • Updated infrastructure dependencies.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 997330b4-d8d1-4b83-be97-1fb02bc75b63

📥 Commits

Reviewing files that changed from the base of the PR and between 9cd8178 and e5561ce.

📒 Files selected for processing (3)
  • apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.js
  • apps/condo/schema.graphql
  • apps/condo/schema.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/condo/schema.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/condo/schema.graphql
  • apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.js

📝 Walkthrough

Walkthrough

This PR adds a subscription activation webhook capability: when a subscription context is marked DONE, it conditionally enqueues a subscription.activated webhook with invoice and organization/user metadata. Supporting changes define the webhook event constant, update GraphQL and TypeScript schema documentation, and bump the helm submodule reference.

Changes

Subscription Activation Webhook

Layer / File(s) Summary
Webhook contracts and schema/docs
apps/condo/domains/common/constants/webhooks.js, apps/condo/schema.graphql, apps/condo/schema.ts
WEBHOOK_EVENT_SUBSCRIPTION_ACTIVATED constant is defined and exported; GraphQL and TypeScript webhook field documentation are updated to list subscription.activated as a supported custom event alongside payment.status.updated.
Activation service: imports and enqueue logic
apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.js
After SubscriptionContext status is set to DONE, the service conditionally reads webhook URL and secret from config; when both are set, it fetches the payer Organization and optional createdBy User, builds a payload from invoice payment fields and metadata, and enqueues it via queueWebhookPayload; enqueue errors are caught and logged without failing the mutation.

Helm Submodule Update

Layer / File(s) Summary
Helm submodule SHA bump
.helm
The tracked .helm submodule commit reference is updated to a newer revision.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

👶 small, ✋🙂 Review please

Suggested reviewers

  • Alexander-Turkin

Poem

🐰 A webhook springs to life so bright,
When subscriptions bloom and dance just right!
From constants born to schemas blessed,
The activation tale is manifest.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a webhook triggered after subscription activation, which matches the core functionality across all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/condo/DOMA-13327/webhook-after-activate-subscription

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f7b0758c0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

await queueWebhookPayload(context, {
url: conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_URL'],
secret: conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_SECRET'],
eventType: 'subscription.activated',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Register subscription activation as a webhook event

When these env vars are configured, this payload still cannot be created because WebhookPayload.eventType validation only accepts custom events passed through WEBHOOK_EVENTS, and Condo currently registers only payment.status.updated in apps/condo/domains/common/constants/webhooks.js. As a result queueWebhookPayload throws INVALID_EVENT_TYPE for subscription.activated, the catch block logs it, and no activation webhook is ever queued.

Useful? React with 👍 / 👎.

try {
const payerOrg = await getById('Organization', invoice.payerOrganization)
const createdByUser = await getById('User', invoice.createdBy)
await queueWebhookPayload(context, {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use an internal context when queueing the webhook

This passes the caller's GraphQL context into queueWebhookPayload, but activateSubscriptionContext explicitly allows support users while WebhookPayload.create is restricted to admins only (canManageWebhookPayloads). In the support-user activation path, creating the payload fails with an access error and is swallowed by the catch block, so the subscription is marked DONE without sending the configured webhook.

Useful? React with 👍 / 👎.

frozenPaymentInfo,
})

if (conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_URL'] && conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_SECRET']) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move to const

if (conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_URL'] && conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_SECRET']) {
try {
const payerOrg = await getById('Organization', invoice.payerOrganization)
const createdByUser = await getById('User', invoice.createdBy)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add checks on empty User and Organization

@AleX83Xpert
Copy link
Copy Markdown
Member

Maybe add a test: subscription activated -> webhook model created?

Copy link
Copy Markdown
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

🧹 Nitpick comments (1)
apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.test.js (1)

174-174: ⚡ Quick win

Avoid hardcoded expired card date in test fixtures

Line 174 uses '12/2025', which is already in the past as of June 4, 2026. This makes tests fragile if expiration validation is added or tightened.

Proposed fix
 const PAYMENT_METHOD = {
     bindingId: faker.datatype.uuid(),
     paymentSystem: 'MasterCard',
     cardNumber: '******4242',
-    expiration: '12/2025',
+    expiration: dayjs().add(2, 'year').format('MM/YYYY'),
     bankName: 'Test Bank',
     bankCountryCode: 'RU',
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.test.js`
at line 174, The test fixture in ActivateSubscriptionContextService.test.js sets
expiration: '12/2025' which is now past; update the fixture used in the test
(the object that contains the expiration property) to produce a valid future
card expiration dynamically (e.g., compute a month/year at least several
months/years ahead from current date) instead of a hardcoded literal so the test
stays valid over time; adjust any helper used to build the payment/card fixture
or the specific test case that references expiration to use this computed value.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.test.js`:
- Around line 244-247: The polling condition for "new context created" currently
includes SUBSCRIPTION_CONTEXT_STATUS.ERROR; remove ERROR from the status_in
array passed to SubscriptionContext.getAll so it only checks
SUBSCRIPTION_CONTEXT_STATUS.CREATED and SUBSCRIPTION_CONTEXT_STATUS.PENDING, and
instead add an explicit check in the wait loop to fail fast if any returned
context has status === SUBSCRIPTION_CONTEXT_STATUS.ERROR (so the test fails
immediately rather than passing and crashing later). Update any related
assertions in ActivateSubscriptionContextService.test to expect this early
failure path if applicable.
- Around line 160-168: In the beforeAll/afterAll hooks around the test suite,
preserve and restore any existing environment values instead of unconditionally
deleting them: save original values of
process.env.SUBSCRIPTION_ACTIVATED_WEBHOOK_URL and
SUBSCRIPTION_ACTIVATED_WEBHOOK_SECRET at the start of beforeAll, set the test
values there, and in afterAll restore the originals (or delete only if the
original was undefined). Update the beforeAll/afterAll blocks referenced in the
test file to use these saved variables so other suites keep their prior env
state.

---

Nitpick comments:
In
`@apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.test.js`:
- Line 174: The test fixture in ActivateSubscriptionContextService.test.js sets
expiration: '12/2025' which is now past; update the fixture used in the test
(the object that contains the expiration property) to produce a valid future
card expiration dynamically (e.g., compute a month/year at least several
months/years ahead from current date) instead of a hardcoded literal so the test
stays valid over time; adjust any helper used to build the payment/card fixture
or the specific test case that references expiration to use this computed value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: df1ffbf8-3acc-42d2-9546-ad1157c1ffcb

📥 Commits

Reviewing files that changed from the base of the PR and between 1945f81 and 5bbebee.

📒 Files selected for processing (4)
  • apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.js
  • apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.test.js
  • apps/condo/schema.graphql
  • apps/condo/schema.ts
✅ Files skipped from review due to trivial changes (2)
  • apps/condo/schema.graphql
  • apps/condo/schema.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.js

Comment thread apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.test.js Outdated
Comment thread apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.test.js Outdated
Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.spec.js (1)

1-28: ⚡ Quick win

Reorder imports to comply with project guidelines.

The import at Line 1 (@app/condo/index) is an internal import and should appear after the @open-condo packages, not before the external packages. As per coding guidelines, import groups must follow: builtin → external → @open-condo → internal.

📦 Proposed fix: reorder imports
-const index = require('`@app/condo/index`')
 const { faker } = require('`@faker-js/faker`')
 const dayjs = require('dayjs')
 
 const { EncryptionManager } = require('`@open-condo/keystone/crypto/EncryptionManager`')
 const { setFakeClientMode, makeLoggedInAdminClient, waitFor } = require('`@open-condo/keystone/test.utils`')
 const { WebhookPayload } = require('`@open-condo/webhooks/schema/utils/testSchema`')
 
+const index = require('`@app/condo/index`')
 const {
     PAYMENT_DONE_STATUS,

As per coding guidelines: "Enforce import order groups: builtin → external → @open-condo → internal → sibling → parent with newlines between groups"

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.spec.js`
around lines 1 - 28, Move the internal import of '`@app/condo/index`' out of the
top and reorder imports to follow project groups: builtin → external →
`@open-condo` → internal; specifically, keep external imports like 'faker' and
'dayjs' first, then all '`@open-condo/`...' imports (e.g. EncryptionManager,
setFakeClientMode, makeLoggedInAdminClient, waitFor, WebhookPayload), and then
place the '`@app/condo/index`' import after the `@open-condo` group; ensure blank
lines separate these import groups and verify related domain imports
(SubscriptionContext, processRecurrentSubscriptionPayments, etc.) remain in the
correct project/internal group.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.spec.js`:
- Around line 1-28: Move the internal import of '`@app/condo/index`' out of the
top and reorder imports to follow project groups: builtin → external →
`@open-condo` → internal; specifically, keep external imports like 'faker' and
'dayjs' first, then all '`@open-condo/`...' imports (e.g. EncryptionManager,
setFakeClientMode, makeLoggedInAdminClient, waitFor, WebhookPayload), and then
place the '`@app/condo/index`' import after the `@open-condo` group; ensure blank
lines separate these import groups and verify related domain imports
(SubscriptionContext, processRecurrentSubscriptionPayments, etc.) remain in the
correct project/internal group.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69840d61-a0c5-411a-9702-13bcb141b55b

📥 Commits

Reviewing files that changed from the base of the PR and between 5bbebee and 9cd8178.

📒 Files selected for processing (1)
  • apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.spec.js

feat(condo): DOMA-13327 added tests

feat(condo): DOMA-13327 added tests

feat(condo): DOMA-13327 added tests
@nomerdvadcatpyat nomerdvadcatpyat force-pushed the feat/condo/DOMA-13327/webhook-after-activate-subscription branch from 9cd8178 to e5561ce Compare June 4, 2026 14:11
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants