Skip to content

Commit

Permalink
commit the new files
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpaterson committed Mar 20, 2024
1 parent 49a49a8 commit d3670fa
Show file tree
Hide file tree
Showing 3 changed files with 479 additions and 0 deletions.
71 changes: 71 additions & 0 deletions __tests__/functional/stream-client-configuration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
StreamClient,
StreamToken,
getDefaultHTTPClient,
StreamClientConfiguration,
} from "../../src";
import { getDefaultHTTPClientOptions } from "../client";

const defaultHttpClient = getDefaultHTTPClient(getDefaultHTTPClientOptions());
const defaultConfig: StreamClientConfiguration = {
secret: "secret",
long_type: "number",
max_attempts: 3,
max_backoff: 20,
httpStreamClient: defaultHttpClient,
};
const dummyStreamToken = new StreamToken("dummy");

describe("StreamClientConfiguration", () => {
it("can be instantiated directly with a token", () => {
new StreamClient(dummyStreamToken, defaultConfig);
});

it("can be instantiated directly with a lambda", async () => {
new StreamClient(() => Promise.resolve(dummyStreamToken), defaultConfig);
});

it.each`
fieldName
${"long_type"}
${"httpStreamClient"}
${"max_backoff"}
${"max_attempts"}
${"secret"}
`(
"throws a TypeError if $fieldName provided is undefined",
async ({ fieldName }: { fieldName: keyof StreamClientConfiguration }) => {
expect.assertions(1);

const config = { ...defaultConfig };
delete config[fieldName];
try {
new StreamClient(dummyStreamToken, config);
} catch (e: any) {
expect(e).toBeInstanceOf(TypeError);
}
}
);

it("throws a RangeError if 'max_backoff' is less than or equal to zero", async () => {
expect.assertions(1);

const config = { ...defaultConfig, max_backoff: 0 };
try {
new StreamClient(dummyStreamToken, config);
} catch (e: any) {
expect(e).toBeInstanceOf(RangeError);
}
});

it("throws a RangeError if 'max_attempts' is less than or equal to zero", async () => {
expect.assertions(1);

const config = { ...defaultConfig, max_attempts: 0 };
try {
new StreamClient(dummyStreamToken, config);
} catch (e: any) {
expect(e).toBeInstanceOf(RangeError);
}
});
});
Loading

0 comments on commit d3670fa

Please sign in to comment.