fix: create phone templates on import instead of skipping when they have no ID - #1457
Conversation
…t exist on the target tenant
…t exist on the target tenant
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
| // `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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Fixed in commit 00052f4.. had missed this commit
| @@ -0,0 +1,94 @@ | |||
| #!/usr/bin/env bash | |||
There was a problem hiding this comment.
Fixed in commit 00052f4.. had missed this commit
…t exist on the target tenant
🔧 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
iduntil they are explicitly created.calcChangesmatches assets bytypeand routes them all toupdate, but the update (PATCH) endpoint requires a templateid. The result was every template being skipped:PhoneTemplatesHandler.processChangesnow:updateset into templates whose existing counterpart has anid(→ PATCH) vs. has noidyet (→ POST/create), so new-tenant templates are created instead of skipped.createPhoneTemplate: if the template already exists (created between ourlistandcreate, or itsidwasn't surfaced bylist), we re-fetch the list to pick up theidand fall back to an update.channel,customizable,tenant) from the create payload viastripFields(template, this.stripCreateFields), sinceprocessChangesis overridden here and doesn't go through the base handler's stripping.content.fromfrom the create/update payload when it is blank. Fresh tenants exportfrom: '', but the API rejects an empty string (minimum 1char), so it must be dropped rather than sent.🔬 Testing
Unit tests added in
test/tools/auth0/handlers/phoneTemplates.test.tscover:id(new-tenant case) - POST, not PATCH.content.fromfrom both create and update payloads.id).channel,customizable,tenant) from the create payload.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