Skip to content

Commit

Permalink
[Service Bus] Error message when messageId is number with decimal poi…
Browse files Browse the repository at this point in the history
…nts (#1301)
  • Loading branch information
ramya-rao-a authored Feb 20, 2019
1 parent a1c7b8e commit 0008d33
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/@azure/servicebus/data-plane/lib/serviceBusMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ export interface SendableMessageInfo {
body: any;
/**
* @property {string | number | Buffer} [messageId] The message identifier is an
* application-defined value that uniquely identifies the message and its payload. The identifier
* is a free-form string and can reflect a GUID or an identifier derived from the application
* context. If enabled, the {@link https://docs.microsoft.com/azure/service-bus-messaging/duplicate-detection duplicate detection}
* identifies and removes second and further submissions of messages with the same MessageId.
* application-defined value that uniquely identifies the message and its payload.
*
* Note: Numbers that are not whole integers are not allowed.
*/
messageId?: string | number | Buffer;
/**
Expand Down Expand Up @@ -311,6 +310,14 @@ export module SendableMessageInfo {
throw new Error("'messageId' must be of type 'string' | 'number' | Buffer.");
}

if (
msg.messageId &&
typeof msg.messageId === "number" &&
Math.floor(msg.messageId) !== msg.messageId
) {
throw new Error("'messageId must be a whole integer. Decimal points are not allowed.");
}

if (
msg.messageId != undefined &&
typeof msg.messageId === "string" &&
Expand Down
43 changes: 43 additions & 0 deletions packages/@azure/servicebus/data-plane/test/sendSchedule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,46 @@ describe("Cancel multiple Scheduled messages", function(): void {
await testCancelScheduleMessages(true);
});
});

describe("Message validations", function(): void {
afterEach(async () => {
await afterEachTest();
});

it("MessageId validations", async function(): Promise<void> {
await beforeEachTest(ClientType.PartitionedQueue, ClientType.PartitionedQueue);
const sender = senderClient.getSender();
let errorMessageIdDecimal = false;
await sender.send({ body: "", messageId: 1.5 }).catch((err) => {
errorMessageIdDecimal =
err &&
err.message === "'messageId must be a whole integer. Decimal points are not allowed.";
});

should.equal(
errorMessageIdDecimal,
true,
"Error not thrown when messageId is not a whole number"
);

let errorMessageIdLongString = false;
await sender
.send({
body: "",
messageId:
"A very very very very very very very very very very very very very very very very very very very very very very very very very long string."
})
.catch((err) => {
errorMessageIdLongString =
err &&
err.message ===
"Length of 'messageId' of type 'string' cannot be greater than 128 characters.";
});

should.equal(
errorMessageIdLongString,
true,
"Error not thrown when messageId is not a whole number"
);
});
});

0 comments on commit 0008d33

Please sign in to comment.