-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial change feed implementation from #290
- Loading branch information
Showing
18 changed files
with
1,152 additions
and
24 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
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
87 changes: 87 additions & 0 deletions
87
__tests__/functional/change-feed-client-configuration.test.ts
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,87 @@ | ||
import { | ||
StreamToken, | ||
getDefaultHTTPClient, | ||
ChangeFeedClientConfiguration, | ||
ChangeFeedClient, | ||
} from "../../src"; | ||
import { getDefaultHTTPClientOptions } from "../client"; | ||
|
||
const defaultHttpClient = getDefaultHTTPClient(getDefaultHTTPClientOptions()); | ||
const defaultConfig: ChangeFeedClientConfiguration = { | ||
secret: "secret", | ||
long_type: "number", | ||
max_attempts: 3, | ||
max_backoff: 20, | ||
query_timeout_ms: 5000, | ||
httpClient: defaultHttpClient, | ||
}; | ||
const dummyStreamToken = new StreamToken("dummy"); | ||
|
||
describe("ChangeFeedClientConfiguration", () => { | ||
it("can be instantiated directly with a token", () => { | ||
new ChangeFeedClient(dummyStreamToken, defaultConfig); | ||
}); | ||
|
||
it("can be instantiated directly with a lambda", async () => { | ||
new ChangeFeedClient( | ||
() => Promise.resolve(dummyStreamToken), | ||
defaultConfig, | ||
); | ||
}); | ||
|
||
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 ChangeFeedClient(dummyStreamToken, config); | ||
} catch (e: any) { | ||
expect(e).toBeInstanceOf(RangeError); | ||
} | ||
}); | ||
|
||
it.each` | ||
fieldName | ||
${"long_type"} | ||
${"httpClient"} | ||
${"max_backoff"} | ||
${"max_attempts"} | ||
${"query_timeout_ms"} | ||
${"secret"} | ||
`( | ||
"throws a TypeError if $fieldName provided is undefined", | ||
async ({ | ||
fieldName, | ||
}: { | ||
fieldName: keyof ChangeFeedClientConfiguration; | ||
}) => { | ||
expect.assertions(1); | ||
|
||
const config = { ...defaultConfig }; | ||
delete config[fieldName]; | ||
try { | ||
new ChangeFeedClient(dummyStreamToken, config); | ||
} catch (e: any) { | ||
expect(e).toBeInstanceOf(TypeError); | ||
} | ||
}, | ||
); | ||
|
||
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 ChangeFeedClient(dummyStreamToken, config); | ||
} catch (e: any) { | ||
expect(e).toBeInstanceOf(RangeError); | ||
} | ||
}); | ||
|
||
it("throws a TypeError is start_ts and cursor are both provided", async () => { | ||
const config = { ...defaultConfig, start_ts: 1, cursor: "cursor" }; | ||
expect(() => { | ||
new ChangeFeedClient(dummyStreamToken, config); | ||
}).toThrow(TypeError); | ||
}); | ||
}); |
Oops, something went wrong.