@@ -60,6 +60,8 @@ vi.mock("../../deps.js", () => ({
|
60 | 60 | |
61 | 61 | const { createMessageCliHelpers } = await import("./helpers.js"); |
62 | 62 | |
| 63 | +const NON_NEGATIVE_INTEGER_FLAGS = new Set(["--delete-days", "--duration-min"]); |
| 64 | + |
63 | 65 | const baseSendOptions = { |
64 | 66 | channel: "discord", |
65 | 67 | target: "123", |
@@ -365,7 +367,7 @@ describe("runMessageAction", () => {
|
365 | 367 | |
366 | 368 | await expect(runMessageAction(action, opts)).rejects.toThrow("exit"); |
367 | 369 | |
368 | | -const kind = flag === "--delete-days" ? "non-negative" : "positive"; |
| 370 | +const kind = NON_NEGATIVE_INTEGER_FLAGS.has(flag) ? "non-negative" : "positive"; |
369 | 371 | expect(errorMock).toHaveBeenCalledWith(`Error: ${flag} must be a ${kind} integer.`); |
370 | 372 | expect(ensurePluginRegistryLoaded).not.toHaveBeenCalled(); |
371 | 373 | expect(messageCommandMock).not.toHaveBeenCalled(); |
@@ -390,7 +392,7 @@ describe("runMessageAction", () => {
|
390 | 392 | }), |
391 | 393 | ).rejects.toThrow("exit"); |
392 | 394 | |
393 | | -const kind = flag === "--delete-days" ? "non-negative" : "positive"; |
| 395 | +const kind = NON_NEGATIVE_INTEGER_FLAGS.has(flag) ? "non-negative" : "positive"; |
394 | 396 | expect(errorMock).toHaveBeenCalledWith(`Error: ${flag} must be a ${kind} integer.`); |
395 | 397 | expect(messageCommandMock).not.toHaveBeenCalled(); |
396 | 398 | expect(exitMock).toHaveBeenCalledWith(1); |
@@ -417,6 +419,27 @@ describe("runMessageAction", () => {
|
417 | 419 | expect(exitMock).toHaveBeenCalledWith(0); |
418 | 420 | }); |
419 | 421 | |
| 422 | +it("allows zero duration-min for clearing Discord timeouts", async () => { |
| 423 | +const runMessageAction = createRunMessageAction(); |
| 424 | + |
| 425 | +await expect( |
| 426 | +runMessageAction("timeout", { |
| 427 | +guildId: "g", |
| 428 | +userId: "u", |
| 429 | +durationMin: "0", |
| 430 | +}), |
| 431 | +).rejects.toThrow("exit"); |
| 432 | + |
| 433 | +expect(errorMock).not.toHaveBeenCalled(); |
| 434 | +expectMessageCommandOptions({ |
| 435 | +action: "timeout", |
| 436 | +guildId: "g", |
| 437 | +userId: "u", |
| 438 | +durationMin: "0", |
| 439 | +}); |
| 440 | +expect(exitMock).toHaveBeenCalledWith(0); |
| 441 | +}); |
| 442 | + |
420 | 443 | it("runs gateway_stop hooks before exit when registered", async () => { |
421 | 444 | hasHooksMock.mockReturnValueOnce(true); |
422 | 445 | await runSendAction(); |
|