Skip to content

fix: create phone templates on import instead of skipping when they have no ID - #1457

Merged
harshithRai merged 8 commits into
masterfrom
ESD-65720
Aug 12, 2026
Merged

fix: create phone templates on import instead of skipping when they have no ID#1457
harshithRai merged 8 commits into
masterfrom
ESD-65720

Conversation

@harshithRai

@harshithRai harshithRai commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

🔧 Changes

Fixes phone notification template import failing against a newly created tenant.

On a fresh tenant, the Management API returns the default phone templates without an id until they are explicitly created. calcChanges matches assets by type and routes them all to update, but the update (PATCH) endpoint requires a template id. The result was every template being skipped:

warn: Skipping update for phone template type 'otp_verify' as unable to find existing template ID

PhoneTemplatesHandler.processChanges now:

  • Splits the calculated update set into templates whose existing counterpart has an id (→ PATCH) vs. has no id yet (→ POST/create), so new-tenant templates are created instead of skipped.
  • Adds a 409-conflict fallback in createPhoneTemplate: if the template already exists (created between our list and create, or its id wasn't surfaced by list), we re-fetch the list to pick up the id and fall back to an update.
  • Strips read-only create-only fields (channel, customizable, tenant) from the create payload via stripFields(template, this.stripCreateFields), since processChanges is overridden here and doesn't go through the base handler's stripping.
  • Omits content.from from the create/update payload when it is blank. Fresh tenants export from: '', but the API rejects an empty string (minimum 1 char), so it must be dropped rather than sent.

🔬 Testing

Unit tests added in test/tools/auth0/handlers/phoneTemplates.test.ts cover:

  • Creating a template when the existing template has no id (new-tenant case) - POST, not PATCH.
  • Omitting empty content.from from both create and update payloads.
  • Falling back to update when create returns a 409 conflict (re-fetches the list to pick up the id).
  • Stripping read-only fields (channel, customizable, tenant) from the create payload.
  • Existing create / update / delete / no-op paths still pass (14 tests total).

Manually verified end-to-end against a freshly created tenant: export (4 default templates, all from: '') → edit a body → import (all 4 created) → re-import (all 4 updated, idempotent) → re-export confirms the edit persisted.

📝 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)

@codecov-commenter

codecov-commenter commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.43%. Comparing base (8fb037f) to head (c6b078c).

Files with missing lines Patch % Lines
src/tools/auth0/handlers/phoneTemplates.ts 91.17% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1457      +/-   ##
==========================================
+ Coverage   80.40%   80.43%   +0.02%     
==========================================
  Files         163      163              
  Lines        7686     7712      +26     
  Branches     1702     1708       +6     
==========================================
+ Hits         6180     6203      +23     
- Misses        809      810       +1     
- Partials      697      699       +2     

☔ View full report in Codecov by Harness.
📢 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.

@harshithRai
harshithRai marked this pull request as ready for review August 11, 2026 08:20
@harshithRai
harshithRai requested a review from a team as a code owner August 11, 2026 08:20
// `content.from` is optional but the API rejects an empty string. Fresh
// tenants export it as '', so drop it when blank to let the create succeed.
if (createPayload.content && !createPayload.content.from) {
delete createPayload.content.from;

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.

stripFields does a shallow copy of the top-level object, so createPayload.content and template.content point to the same object reference. The delete createPayload.content.from on the next line therefore mutates the original template.content in place.

This is incidentally harmless right now, the 409 fallback calls updatePhoneTemplate(template), which also skips a blank from, so the side effect is correct by accident. But if the fallback path or updatePhoneTemplate's contract changes, this could silently produce wrong behaviour

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 00052f4.. had missed this commit

Comment thread scripts/verify-phone-templates-fix.sh Outdated
@@ -0,0 +1,94 @@
#!/usr/bin/env bash

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.

Do we need this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 00052f4.. had missed this commit

@harshithRai
harshithRai merged commit e282116 into master Aug 12, 2026
9 checks passed
@harshithRai
harshithRai deleted the ESD-65720 branch August 12, 2026 09:08
@harshithRai harshithRai mentioned this pull request Aug 12, 2026
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