it("falls back to name matching when numeric channel name is not a valid ID", async () => { const res = await resolveGuild111Entry2024({
channelLookup: () => new Response("not found", { status: 404 }),
});
it("does not fall back to name matching when channel lookup returns 403", async () => { const res = await resolveGuild111Entry2024({
channelLookup: () => new Response("Missing Access", { status: 403 }),
});
expectUnresolved1112024(res);
});
it("does not fall back to name matching when channel payload is malformed", async () => { const res = await resolveGuild111Entry2024({
channelLookup: () => jsonResponse({ id: "2024", name: "unknown", type: 0 }),
guildChannels: [{ id: "c1", name: "2024", guild_id: "111", type: 0 }],
});
expectUnresolved1112024(res);
});
it("resolves guild: prefixed id as guild (not channel)", async () => { const fetcher = withFetchPreconnect(async (input: RequestInfo | URL) => { const url = urlToString(input); if (url.endsWith("/users/@me/guilds")) { return jsonResponse([{ id: "111222333444555666", name: "Guild One" }]);
} // Should never be called — if it is, the ID was misrouted as a channel if (url.includes("/channels/")) { thrownew Error("guild id was incorrectly routed to /channels/");
} returnnew Response("not found", { status: 404 });
});
it("bare numeric guild id is misrouted as channel id (regression)", async () => { // Demonstrates why provider.ts must prefix guild-only entries with "guild:" // In reality, Discord returns 404 when a guild ID is sent to /channels/<guildId>, // which causes fetchDiscord to throw and the entire resolver to crash. const fetcher = withFetchPreconnect(async (input: RequestInfo | URL) => { const url = urlToString(input); if (url.endsWith("/users/@me/guilds")) { return jsonResponse([{ id: "999", name: "My Server" }]);
} // Guild ID hitting /channels/ returns 404 — just like real Discord if (url.includes("/channels/")) { returnnew Response(JSON.stringify({ message: "Unknown Channel" }), { status: 404 });
} returnnew Response("not found", { status: 404 });
});
// Without the guild: prefix, a bare numeric string hits /channels/999 → 404 → unresolved const res = await resolveDiscordChannelAllowlist({
token: "test",
entries: ["999"],
fetcher,
});
expect(res[0]?.resolved).toBe(false);
expect(res[0]?.channelId).toBe("999");
expect(res[0]?.guildId).toBeUndefined();
// With the guild: prefix, it correctly resolves as a guild (never hits /channels/) const res2 = await resolveDiscordChannelAllowlist({
token: "test",
entries: ["guild:999"],
fetcher,
});
expect(res2[0]?.resolved).toBe(true);
expect(res2[0]?.guildId).toBe("999");
expect(res2[0]?.channelId).toBeUndefined();
});
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.