Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> | undefined {
if (!isDefined(value)) {
return undefined;
}

const headerObj: Record<string, string> = {};
for (const { Header, Value } of value) {
for (const { Header, Value } of Array.isArray(value) ? value : [value]) {
headerObj[Header] = Value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ const APPLE_TEMPLATE_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
</content>
</entry>`;

const APPLE_TEMPLATE_REGISTRATION_SINGLE_APNSHEADER = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<AppleTemplateRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag,myOtherTag</Tags>
<RegistrationId>{Registration Id}</RegistrationId>
<DeviceToken>{DeviceToken}</DeviceToken>
<BodyTemplate><![CDATA[{Template for the body}]]></BodyTemplate>
<ApnsHeaders>
<ApnsHeader>
<Header>apns-priority</Header>
<Value>10</Value>
</ApnsHeader>
</ApnsHeaders>
</AppleTemplateRegistrationDescription>
</content>
</entry>`;

const BAIDU_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
Expand Down Expand Up @@ -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,
Expand Down