feat(slack): add draft preview cleanup lifecycle

This commit is contained in:
Colin
2026-02-16 16:07:00 -05:00
committed by Peter Steinberger
parent dfd5a79631
commit 087edec93f
3 changed files with 83 additions and 2 deletions

View File

@@ -103,4 +103,54 @@ describe("createSlackDraftStream", () => {
expect(edit).not.toHaveBeenCalled();
expect(warn).toHaveBeenCalledTimes(1);
});
it("clear removes preview message when one exists", async () => {
const send = vi.fn(async () => ({
channelId: "C123",
messageId: "111.222",
}));
const edit = vi.fn(async () => {});
const remove = vi.fn(async () => {});
const stream = createSlackDraftStream({
target: "channel:C123",
token: "xoxb-test",
throttleMs: 250,
send,
edit,
remove,
});
stream.update("hello");
await stream.flush();
await stream.clear();
expect(remove).toHaveBeenCalledTimes(1);
expect(remove).toHaveBeenCalledWith("C123", "111.222", {
token: "xoxb-test",
accountId: undefined,
});
expect(stream.messageId()).toBeUndefined();
expect(stream.channelId()).toBeUndefined();
});
it("clear is a no-op when no preview message exists", async () => {
const send = vi.fn(async () => ({
channelId: "C123",
messageId: "111.222",
}));
const edit = vi.fn(async () => {});
const remove = vi.fn(async () => {});
const stream = createSlackDraftStream({
target: "channel:C123",
token: "xoxb-test",
throttleMs: 250,
send,
edit,
remove,
});
await stream.clear();
expect(remove).not.toHaveBeenCalled();
});
});