



























@@ -118,4 +118,97 @@ describe("readSlackMessages", () => {
118118hasMore: false,
119119});
120120});
121+122+it("passes Slack timestamp strings through to history bounds", async () => {
123+const client = createClient();
124+125+await readSlackMessages("C1", {
126+ client,
127+before: "1712345678.654321",
128+after: "1712340000.000001",
129+token: "xoxb-test",
130+});
131+132+expect(client.conversations.history).toHaveBeenCalledWith({
133+channel: "C1",
134+limit: undefined,
135+latest: "1712345678.654321",
136+oldest: "1712340000.000001",
137+});
138+});
139+140+it("converts ISO date strings to epoch seconds for history bounds", async () => {
141+const client = createClient();
142+143+await readSlackMessages("C1", {
144+ client,
145+before: "2024-04-05T12:34:56.000Z",
146+after: "2024-04-05T00:00:00.000Z",
147+token: "xoxb-test",
148+});
149+150+expect(client.conversations.history).toHaveBeenCalledWith({
151+channel: "C1",
152+limit: undefined,
153+latest: "1712320496",
154+oldest: "1712275200",
155+});
156+});
157+158+it("converts ISO date strings with offsets to epoch seconds for history bounds", async () => {
159+const client = createClient();
160+161+await readSlackMessages("C1", {
162+ client,
163+before: "2024-04-05T12:34:56+03:00",
164+after: "2024-04-05T12:34:56.789+03:00",
165+token: "xoxb-test",
166+});
167+168+expect(client.conversations.history).toHaveBeenCalledWith({
169+channel: "C1",
170+limit: undefined,
171+latest: "1712309696",
172+oldest: "1712309696.789",
173+});
174+});
175+176+it.each(["not-a-timestamp", "2024-02-30T00:00:00.000Z", "04/05/2024", "2024-04-05T12:34:56"])(
177+"rejects invalid history bound %s with a clear timestamp error",
178+async (before) => {
179+const client = createClient();
180+181+await expect(
182+readSlackMessages("C1", {
183+ client,
184+ before,
185+token: "xoxb-test",
186+}),
187+).rejects.toThrow(
188+`Invalid Slack read before timestamp "${before}": expected a Slack timestamp or ISO-8601 date string`,
189+);
190+expect(client.conversations.history).not.toHaveBeenCalled();
191+},
192+);
193+194+it("normalizes ISO date strings and Slack timestamp strings for thread reply bounds", async () => {
195+const client = createClient();
196+197+await readSlackMessages("C1", {
198+ client,
199+threadId: "1712345678.000001",
200+before: "2024-04-05T12:34:56.000Z",
201+after: "1712340000.000001",
202+token: "xoxb-test",
203+});
204+205+expect(client.conversations.replies).toHaveBeenCalledWith({
206+channel: "C1",
207+ts: "1712345678.000001",
208+limit: undefined,
209+latest: "1712320496",
210+oldest: "1712340000.000001",
211+});
212+expect(client.conversations.history).not.toHaveBeenCalled();
213+});
121214});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。