mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 16:06:16 +00:00
test(discord): stabilize model picker timeout assertions
This commit is contained in:
@@ -44,6 +44,21 @@ function createModelsProviderData(entries: Record<string, string[]>): ModelsProv
|
||||
return createBaseModelsProviderData(entries, { defaultProviderOrder: "sorted" });
|
||||
}
|
||||
|
||||
async function waitForCondition(
|
||||
predicate: () => boolean,
|
||||
opts?: { attempts?: number; delayMs?: number },
|
||||
): Promise<void> {
|
||||
const attempts = opts?.attempts ?? 50;
|
||||
const delayMs = opts?.delayMs ?? 0;
|
||||
for (let index = 0; index < attempts; index += 1) {
|
||||
if (predicate()) {
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
||||
}
|
||||
throw new Error("condition not met");
|
||||
}
|
||||
|
||||
function createModelPickerContext(): ModelPickerContext {
|
||||
const cfg = {
|
||||
channels: {
|
||||
@@ -317,7 +332,7 @@ describe("Discord model picker interactions", () => {
|
||||
await button.run(submitInteraction as unknown as PickerButtonInteraction, submitData);
|
||||
|
||||
expect(withTimeoutSpy).toHaveBeenCalledTimes(1);
|
||||
expect(dispatchSpy).toHaveBeenCalledTimes(1);
|
||||
await waitForCondition(() => dispatchSpy.mock.calls.length === 1);
|
||||
expect(submitInteraction.followUp).toHaveBeenCalledTimes(1);
|
||||
const followUpPayload = submitInteraction.followUp.mock.calls[0]?.[0] as {
|
||||
components?: Array<{ components?: Array<{ content?: string }> }>;
|
||||
|
||||
Reference in New Issue
Block a user