test: share send cfg threading helpers

This commit is contained in:
Peter Steinberger
2026-03-14 02:02:56 +00:00
parent 55ebdce9c3
commit 74e50d3be3
4 changed files with 99 additions and 40 deletions

View File

@@ -0,0 +1,65 @@
import { expect } from "vitest";
type MockFn = (...args: never[]) => unknown;
type CfgThreadingAssertion<TCfg> = {
loadConfig: MockFn;
resolveAccount: MockFn;
cfg: TCfg;
accountId?: string;
};
type SendRuntimeState = {
loadConfig: MockFn;
resolveMarkdownTableMode: MockFn;
convertMarkdownTables: MockFn;
record: MockFn;
};
export function expectProvidedCfgSkipsRuntimeLoad<TCfg>({
loadConfig,
resolveAccount,
cfg,
accountId,
}: CfgThreadingAssertion<TCfg>): void {
expect(loadConfig).not.toHaveBeenCalled();
expect(resolveAccount).toHaveBeenCalledWith({
cfg,
accountId,
});
}
export function expectRuntimeCfgFallback<TCfg>({
loadConfig,
resolveAccount,
cfg,
accountId,
}: CfgThreadingAssertion<TCfg>): void {
expect(loadConfig).toHaveBeenCalledTimes(1);
expect(resolveAccount).toHaveBeenCalledWith({
cfg,
accountId,
});
}
export function createSendCfgThreadingRuntime({
loadConfig,
resolveMarkdownTableMode,
convertMarkdownTables,
record,
}: SendRuntimeState) {
return {
config: {
loadConfig,
},
channel: {
text: {
resolveMarkdownTableMode,
convertMarkdownTables,
},
activity: {
record,
},
},
};
}