File size: 1,311 Bytes
eb3f11e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | /**
* Shared assertions for channel send config derivation.
*/
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,
},
},
};
}
|