Add message counting and date-bounded scrapes
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { SlopbotBackend, type SlopbotFetcher } from "../slopbot/backend.js";
|
||||
import { mapSlopbotMessage } from "../slopbot/backend.js";
|
||||
import { countMessages } from "../slopbot/client.js";
|
||||
|
||||
let failures = 0;
|
||||
|
||||
@@ -138,6 +139,35 @@ void (async () => {
|
||||
assert.equal(mapped.forwarded[0].attachments[0].filename, "clip.webm");
|
||||
});
|
||||
|
||||
await test("countMessages reads guild search totals", async () => {
|
||||
const calls: string[] = [];
|
||||
const rest = {
|
||||
async get(path: string, options?: { query?: URLSearchParams }) {
|
||||
calls.push(`${path}?${options?.query?.toString() ?? ""}`);
|
||||
return { total_results: 7 };
|
||||
}
|
||||
};
|
||||
|
||||
const count = await countMessages(rest, {
|
||||
channelId: "1",
|
||||
guildId: "2",
|
||||
afterId: "100",
|
||||
beforeId: "200"
|
||||
});
|
||||
assert.equal(count, 7);
|
||||
assert.equal(calls[0], "/guilds/2/messages/search?channel_id=1&limit=1&min_id=100&max_id=200");
|
||||
|
||||
const failed = await countMessages(
|
||||
{
|
||||
async get() {
|
||||
throw new Error("nope");
|
||||
}
|
||||
},
|
||||
{ channelId: "1", guildId: "2" }
|
||||
);
|
||||
assert.equal(failed, null);
|
||||
});
|
||||
|
||||
await test("backend pages oldest first and passes before and limit", async () => {
|
||||
const fetcher = new FakeFetcher([
|
||||
[discordMessage({ id: "1002" }), discordMessage({ id: "1001" })],
|
||||
|
||||
Reference in New Issue
Block a user