-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49a49a8
commit d3670fa
Showing
3 changed files
with
479 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.