Skip to content

fix: organization creation response handling and add ID validation#1365

Merged
kushalshit27 merged 4 commits intomasterfrom
DXCDT-1598-issue-1353
Apr 20, 2026
Merged

fix: organization creation response handling and add ID validation#1365
kushalshit27 merged 4 commits intomasterfrom
DXCDT-1598-issue-1353

Conversation

@kushalshit27
Copy link
Copy Markdown
Contributor

🔧 Changes

Root cause:
After the node-auth0 v4→v5 upgrade, client.organizations.create() changed from returning { data: org } to returning org directly. The organizations handler was the only one still destructuring { data: created }, causing created to be undefined — hence TypeError: Cannot read properties of undefined (reading 'id') when it tried to use created.id to add connections.

Fixed:

  • OrganizationsHandler.createOrganization() to correctly extract the created organization from the API response. The client method now returns the organization object directly instead of a nested { data } structure.
  • Added error handling to validate that the organization ID is present in the response before proceeding with connection/grant associations. If the ID is missing, an error is logged and the response is returned early to prevent downstream failures.

📚 References

🔬 Testing

  • Existing unit tests in test/tools/auth0/handlers/organizations.tests.js have been updated to verify the corrected response structure from the organizations client.
  • Three test cases now mock the organizations.create() response as the unwrapped data object, consistent with the implementation change.

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

- src/tools/auth0/handlers/organizations.ts: Add error handling for missing organization ID on creation.
- src/tools/auth0/handlers/organizations.ts: Refactor to use createdId for connection and grant associations.
- test/tools/auth0/handlers/organizations.tests.js: Simplify promise resolution in test cases.
@kushalshit27 kushalshit27 changed the title feat: organization creation response handling and add ID validation fix: organization creation response handling and add ID validation Apr 17, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.08%. Comparing base (d12a2ff) to head (7c6b41e).

Files with missing lines Patch % Lines
src/tools/auth0/handlers/organizations.ts 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1365      +/-   ##
==========================================
- Coverage   80.10%   80.08%   -0.03%     
==========================================
  Files         152      152              
  Lines        6213     6216       +3     
  Branches     1290     1291       +1     
==========================================
+ Hits         4977     4978       +1     
- Misses        702      703       +1     
- Partials      534      535       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kushalshit27 kushalshit27 marked this pull request as ready for review April 20, 2026 04:12
@kushalshit27 kushalshit27 requested a review from a team as a code owner April 20, 2026 04:12

if (!created.id) {
log.error(
`Organization "${organization.name}" was created but the response did not include an ID. Skipping connection/grant association.`
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.

Instead of silently returning here, should we not throw the error?
As the current behaviour creates partial state(org exists, connection missing) with no error propagation

- src/tools/auth0/handlers/organizations.ts: Replace log error with throw for missing organization ID
…tion

- test/tools/auth0/handlers/organizations.tests.js: throw error in create method when deleting organizations
- test/tools/auth0/handlers/organizations.tests.js: update stage function to handle empty organizations array
@kushalshit27 kushalshit27 merged commit 2df9a76 into master Apr 20, 2026
9 checks passed
@kushalshit27 kushalshit27 deleted the DXCDT-1598-issue-1353 branch April 20, 2026 05:54
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.

3 participants