diff --git a/sdk/notificationhubs/notification-hubs/CHANGELOG.md b/sdk/notificationhubs/notification-hubs/CHANGELOG.md index 2b968e581716..1225d9855c56 100644 --- a/sdk/notificationhubs/notification-hubs/CHANGELOG.md +++ b/sdk/notificationhubs/notification-hubs/CHANGELOG.md @@ -1,14 +1,10 @@ # Release History -## 2.0.2 (Unreleased) - -### Features Added - -### Breaking Changes +## 2.0.2 (2025-10-07) ### Bugs Fixed -### Other Changes +- Properly handle single-element headers of template registrations [PR #36114](https://github.com/Azure/azure-sdk-for-js/pull/36114). ## 2.0.0 (2024-10-14) diff --git a/sdk/notificationhubs/notification-hubs/src/serializers/registrationSerializer.ts b/sdk/notificationhubs/notification-hubs/src/serializers/registrationSerializer.ts index 09c3b400861f..1572f06edb92 100644 --- a/sdk/notificationhubs/notification-hubs/src/serializers/registrationSerializer.ts +++ b/sdk/notificationhubs/notification-hubs/src/serializers/registrationSerializer.ts @@ -502,14 +502,14 @@ export const registrationDescriptionParser: RegistrationDescriptionParser = { }; function getHeadersOrUndefined( - value?: { Header: string; Value: string }[], + value?: { Header: string; Value: string }[] | { Header: string; Value: string }, ): Record | undefined { if (!isDefined(value)) { return undefined; } const headerObj: Record = {}; - for (const { Header, Value } of value) { + for (const { Header, Value } of Array.isArray(value) ? value : [value]) { headerObj[Header] = Value; } diff --git a/sdk/notificationhubs/notification-hubs/test/internal/unit/registrationSerializer.spec.ts b/sdk/notificationhubs/notification-hubs/test/internal/unit/registrationSerializer.spec.ts index 3d9d3ccc3f36..2a61a37a82d1 100644 --- a/sdk/notificationhubs/notification-hubs/test/internal/unit/registrationSerializer.spec.ts +++ b/sdk/notificationhubs/notification-hubs/test/internal/unit/registrationSerializer.spec.ts @@ -101,6 +101,24 @@ const APPLE_TEMPLATE_REGISTRATION = ` `; +const APPLE_TEMPLATE_REGISTRATION_SINGLE_APNSHEADER = ` + + + + myTag,myOtherTag + {Registration Id} + {DeviceToken} + + + +
apns-priority
+ 10 +
+
+
+
+
`; + const BAIDU_REGISTRATION = ` @@ -337,6 +355,19 @@ describe("parseRegistrationEntry", () => { assert.equal(registration.apnsHeaders!["apns-expiration"], "0"); }); + it("should parse an apple template registration description with single apns header", async () => { + const registration = (await registrationDescriptionParser.parseRegistrationEntry( + APPLE_TEMPLATE_REGISTRATION_SINGLE_APNSHEADER, + )) as AppleTemplateRegistrationDescription; + + assert.equal(registration.kind, "AppleTemplate"); + assert.equal(registration.registrationId, "{Registration Id}"); + assert.equal(registration.deviceToken, "{DeviceToken}"); + assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]); + assert.equal(registration.bodyTemplate, "{Template for the body}"); + assert.equal(registration.apnsHeaders!["apns-priority"], "10"); + }); + it("should parse an Baidu registration description", async () => { const registration = (await registrationDescriptionParser.parseRegistrationEntry( BAIDU_REGISTRATION,