Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Service Bus] Refactor Invalid param test file #9947

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Changes from all commits
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
286 changes: 73 additions & 213 deletions sdk/servicebus/service-bus/test/invalidParameters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import chaiAsPromised from "chai-as-promised";
chai.use(chaiAsPromised);
import { TestClientType, TestMessage } from "./utils/testUtils";
import { ServiceBusClientForTests, createServiceBusClientForTests } from "./utils/testutils2";
import { Receiver } from "../src/receivers/receiver";
import { Sender } from "../src/sender";
import { SessionReceiver } from "../src/receivers/sessionReceiver";
import { ReceivedMessageWithLock } from "../src/serviceBusMessage";
import { ServiceBusClient } from '../src';

describe("invalid parameters", () => {
let serviceBusClient: ServiceBusClientForTests;
Expand All @@ -24,170 +24,6 @@ describe("invalid parameters", () => {
return serviceBusClient.test.after();
});

describe("Invalid parameters in Sender/ReceiverClients for PartitionedQueue", function(): void {
let receiver: Receiver<ReceivedMessageWithLock>;

// Since, the below tests never actually make use of any AMQP links, there is no need to create
// new sender/receiver clients before each test. Doing it once for each describe block.
before(async () => {
const entityNames = await serviceBusClient.test.createTestEntities(
TestClientType.PartitionedQueue
);

receiver = await serviceBusClient.test.getPeekLockReceiver(entityNames);
});

after(async () => {
await serviceBusClient.test.afterEach();
});

it("Peek: Invalid maxMessageCount for Queue", async function(): Promise<void> {
const peekedMessages = await receiver.peekMessages(-100);
should.equal(peekedMessages.length, 0);
});

it("Peek: Wrong type maxMessageCount for Queue", async function(): Promise<void> {
let caughtError: Error | undefined;
try {
// @ts-expect-error
await receiver.peekMessages("somestring");
} catch (error) {
caughtError = error;
}
should.equal(caughtError && caughtError.name, "TypeError");
should.equal(
caughtError && caughtError.message,
`The parameter "maxMessageCount" should be of type "number"`
);
});

it("PeekBySequenceNumber: Invalid maxMessageCount for Queue", async function(): Promise<void> {
const peekedMessages = await receiver.peekMessages(-100, {
fromSequenceNumber: Long.ZERO
});
should.equal(peekedMessages.length, 0);
});

it("PeekBySequenceNumber: Wrong type maxMessageCount for Queue", async function(): Promise<
void
> {
let caughtError: Error | undefined;
try {
// @ts-expect-error
await receiver.peekMessages("somestring", {
fromSequenceNumber: Long.ZERO
});
} catch (error) {
caughtError = error;
}
should.equal(caughtError && caughtError.name, "TypeError");
should.equal(
caughtError && caughtError.message,
`The parameter "maxMessageCount" should be of type "number"`
);
});

it("PeekBySequenceNumber: Wrong type fromSequenceNumber for Queue", async function(): Promise<
void
> {
let caughtError: Error | undefined;
try {
await receiver.peekMessages(1, { fromSequenceNumber: "somestring" as any });
} catch (error) {
caughtError = error;
}
should.equal(caughtError && caughtError.name, "TypeError");
should.equal(
caughtError && caughtError.message,
`The parameter "fromSequenceNumber" should be of type "Long"`
);
});
});

describe("Invalid parameters in Sender/ReceiverClients for PartitionedSubscription", function(): void {
let subscriptionReceiverClient: Receiver<ReceivedMessageWithLock>;

// Since, the below tests never actually make use of any AMQP links, there is no need to create
// new sender/receiver clients before each test. Doing it once for each describe block.
before(async () => {
const entityNames = await serviceBusClient.test.createTestEntities(
TestClientType.PartitionedSubscription
);

subscriptionReceiverClient = await serviceBusClient.test.getPeekLockReceiver(entityNames);
});

after(() => {
return serviceBusClient.test.afterEach();
});

it("Peek: Invalid maxMessageCount for Subscription", async function(): Promise<void> {
const browsedMessages = await subscriptionReceiverClient.peekMessages(-100);
should.equal(browsedMessages.length, 0);
});

it("Peek: Wrong type maxMessageCount for Subscription", async function(): Promise<void> {
let caughtError: Error | undefined;
try {
// @ts-expect-error
await subscriptionReceiverClient.peekMessages("somestring");
} catch (error) {
caughtError = error;
}
should.equal(caughtError && caughtError.name, "TypeError");
should.equal(
caughtError && caughtError.message,
`The parameter "maxMessageCount" should be of type "number"`
);
});

it("PeekBySequenceNumber: Invalid maxMessageCount for Subscription", async function(): Promise<
void
> {
const browsedMessages = await subscriptionReceiverClient.peekMessages(-100, {
fromSequenceNumber: Long.ZERO
});
should.equal(browsedMessages.length, 0);
});

it("PeekBySequenceNumber: Wrong type maxMessageCount for Subscription", async function(): Promise<
void
> {
let caughtError: Error | undefined;
try {
// @ts-expect-error
await subscriptionReceiverClient.peekMessages("somestring", {
fromSequenceNumber: Long.ZERO
});
} catch (error) {
caughtError = error;
}
should.equal(caughtError && caughtError.name, "TypeError");
should.equal(
caughtError && caughtError.message,
`The parameter "maxMessageCount" should be of type "number"`
);
});

it("PeekBySequenceNumber: Wrong type fromSequenceNumber for Subscription", async function(): Promise<
void
> {
let caughtError: Error | undefined;
try {
await subscriptionReceiverClient.peekMessages(1, {
fromSequenceNumber: "somestring" as any
});
} catch (error) {
caughtError = error;
}
should.equal(caughtError && caughtError.name, "TypeError");
should.equal(
caughtError && caughtError.message,
`The parameter "fromSequenceNumber" should be of type "Long"`
);
});
});

describe("Invalid parameters in SessionReceiver", function(): void {
let sender: Sender;
let receiver: SessionReceiver<ReceivedMessageWithLock>;
Expand Down Expand Up @@ -393,37 +229,15 @@ describe("invalid parameters", () => {
});

describe("Invalid parameters in Receiver", function(): void {
let sender: Sender;
let receiver: Receiver<ReceivedMessageWithLock>;

// Since, the below tests never actually make use of any AMQP links, there is no need to create
// new sender/receiver clients before each test. Doing it once for each describe block.
before(async () => {
const entityNames = await serviceBusClient.test.createTestEntities(
TestClientType.PartitionedQueueWithSessions
);

sender = serviceBusClient.test.addToCleanup(
serviceBusClient.createSender(entityNames.queue!)
);

receiver = await serviceBusClient.test.getPeekLockReceiver(entityNames);

await sender.sendMessages(TestMessage.getSessionSample());
});

after(async () => {
return serviceBusClient.test.afterEach();
});
const mockConnectionString = "Endpoint=sb://test/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=test";
const sbClient = new ServiceBusClient(mockConnectionString);
const receiver = sbClient.createReceiver("dummyQueue", "peekLock");

it("Receiver: Missing ReceiveMode", async function(): Promise<void> {
let errorCaught: string = "";
try {
const { queue } = serviceBusClient.test.getTestEntities(
TestClientType.PartitionedQueueWithSessions
);

await serviceBusClient.createReceiver(queue!, undefined as any);
// @ts-expect-error
sbClient.createReceiver("dummyQueue");
} catch (error) {
errorCaught = error.message;
}
Expand All @@ -437,11 +251,8 @@ describe("invalid parameters", () => {
it("Receiver: Invalid ReceiveMode", async function(): Promise<void> {
let errorCaught: string = "";
try {
const { queue } = serviceBusClient.test.getTestEntities(
TestClientType.PartitionedQueueWithSessions
);

await serviceBusClient.createReceiver(queue!, 123 as any);
// @ts-expect-error
sbClient.createReceiver("dummyQueue", 123);
} catch (error) {
errorCaught = error.message;
}
Expand All @@ -452,6 +263,68 @@ describe("invalid parameters", () => {
);
});

it("Peek: Invalid maxMessageCount for Queue", async function(): Promise<void> {
const peekedMessages = await receiver.peekMessages(-100);
should.equal(peekedMessages.length, 0);
});

it("Peek: Wrong type maxMessageCount for Queue", async function(): Promise<void> {
let caughtError: Error | undefined;
try {
// @ts-expect-error
await receiver.peekMessages("somestring");
} catch (error) {
caughtError = error;
}
should.equal(caughtError && caughtError.name, "TypeError");
should.equal(
caughtError && caughtError.message,
`The parameter "maxMessageCount" should be of type "number"`
);
});

it("PeekBySequenceNumber: Invalid maxMessageCount for Queue", async function(): Promise<void> {
const peekedMessages = await receiver.peekMessages(-100, {
fromSequenceNumber: Long.ZERO
});
should.equal(peekedMessages.length, 0);
});

it("PeekBySequenceNumber: Wrong type maxMessageCount for Queue", async function(): Promise<
void
> {
let caughtError: Error | undefined;
try {
// @ts-expect-error
await receiver.peekMessages("somestring", {
fromSequenceNumber: Long.ZERO
});
} catch (error) {
caughtError = error;
}
should.equal(caughtError && caughtError.name, "TypeError");
should.equal(
caughtError && caughtError.message,
`The parameter "maxMessageCount" should be of type "number"`
);
});

it("PeekBySequenceNumber: Wrong type fromSequenceNumber for Queue", async function(): Promise<
void
> {
let caughtError: Error | undefined;
try {
await receiver.peekMessages(1, { fromSequenceNumber: "somestring" as any });
} catch (error) {
caughtError = error;
}
should.equal(caughtError && caughtError.name, "TypeError");
should.equal(
caughtError && caughtError.message,
`The parameter "fromSequenceNumber" should be of type "Long"`
);
});

it("RegisterMessageHandler: Missing onMessage in Receiver", async function(): Promise<void> {
let caughtError: Error | undefined;
try {
Expand Down Expand Up @@ -523,22 +396,9 @@ describe("invalid parameters", () => {
});

describe("Invalid parameters in Sender", function(): void {
let sender: Sender;

// Since, the below tests never actually make use of any AMQP links, there is no need to create
// new sender/receiver clients before each test. Doing it once for each describe block.
before(async () => {
const { queue } = await serviceBusClient.test.createTestEntities(
TestClientType.PartitionedQueue
);

// const clients = await getSenderReceiverClients(TestClientType.PartitionedQueue, "peekLock");
sender = serviceBusClient.test.addToCleanup(serviceBusClient.createSender(queue!));
});

after(() => {
return serviceBusClient.test.afterEach();
});
const mockConnectionString = "Endpoint=sb://test/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=test";
const sbClient = new ServiceBusClient(mockConnectionString);
const sender = sbClient.createSender("dummyQueue");

it("ScheduledMessages: Missing date in Sender", async function(): Promise<void> {
let caughtError: Error | undefined;
Expand Down