Skip to content

Commit

Permalink
[notification hubs] Fix empty registration feed bug (#23121)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpodwysocki committed Sep 6, 2022
1 parent a4367c4 commit 6edc3b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Expand Up @@ -187,7 +187,11 @@ export const registrationDescriptionParser: RegistrationDescriptionParser = {
*/
async parseRegistrationFeed(bodyText: string): Promise<RegistrationDescription[]> {
const xml = await parseXML(bodyText, { includeRoot: true });
const results = [];
const results: RegistrationDescription[] = [];
if (!isDefined(xml.feed.entry)) {
return results;
}

for (const entry of xml.feed.entry) {
delete entry.content["$"];

Expand Down
Expand Up @@ -491,6 +491,14 @@ const REGISTRATION_FEED = `<?xml version="1.0" encoding="utf-8" ?>
</entry>
</feed>`;

const EMPTY_REGISTRATION_FEED = `<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Registrations</title>
<id>https://testns.servicebus.windows.net/testhub/registrations/?api-version=2020-06</id>
<updated>2022-09-06T20:06:33Z</updated>
<link rel="self" href="https://testns.servicebus.windows.net/testhub/registrations/?api-version=2020-06" />
</feed>`;

describe("parseRegistrationFeed", () => {
it("should parse a registration feed", async () => {
const registrations = await registrationDescriptionParser.parseRegistrationFeed(
Expand All @@ -509,6 +517,14 @@ describe("parseRegistrationFeed", () => {
assert.equal(appleRegistration.deviceToken, "{DeviceToken}");
assert.deepEqual(appleRegistration.tags, ["myTag", "myOtherTag"]);
});

it("should parse an empty feed", async () => {
const registrations = await registrationDescriptionParser.parseRegistrationFeed(
EMPTY_REGISTRATION_FEED
);

assert.equal(registrations.length, 0);
});
});

describe("serializeRegistrationDescription", () => {
Expand Down

0 comments on commit 6edc3b5

Please sign in to comment.