chore: fix broken test.
This commit is contained in:
parent
57d008a33d
commit
c429ccb64f
1 changed files with 20 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
||||||
|
import * as ssrf from "../infra/net/ssrf.js";
|
||||||
import { MEDIA_GROUP_TIMEOUT_MS } from "./bot-updates.js";
|
import { MEDIA_GROUP_TIMEOUT_MS } from "./bot-updates.js";
|
||||||
|
|
||||||
const useSpy = vi.fn();
|
const useSpy = vi.fn();
|
||||||
|
|
@ -10,6 +11,7 @@ const sendChatActionSpy = vi.fn();
|
||||||
const cacheStickerSpy = vi.fn();
|
const cacheStickerSpy = vi.fn();
|
||||||
const getCachedStickerSpy = vi.fn();
|
const getCachedStickerSpy = vi.fn();
|
||||||
const describeStickerImageSpy = vi.fn();
|
const describeStickerImageSpy = vi.fn();
|
||||||
|
const ssrfResolveSpy = vi.spyOn(ssrf, "resolvePinnedHostname");
|
||||||
|
|
||||||
type ApiStub = {
|
type ApiStub = {
|
||||||
config: { use: (arg: unknown) => void };
|
config: { use: (arg: unknown) => void };
|
||||||
|
|
@ -26,6 +28,15 @@ const apiStub: ApiStub = {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
resetInboundDedupe();
|
resetInboundDedupe();
|
||||||
|
ssrfResolveSpy.mockImplementation(async (hostname) => {
|
||||||
|
const normalized = hostname.trim().toLowerCase().replace(/\.$/, "");
|
||||||
|
const addresses = ["93.184.216.34"];
|
||||||
|
return {
|
||||||
|
hostname: normalized,
|
||||||
|
addresses,
|
||||||
|
lookup: ssrf.createPinnedLookup({ hostname: normalized, addresses }),
|
||||||
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
vi.mock("grammy", () => ({
|
vi.mock("grammy", () => ({
|
||||||
|
|
@ -156,7 +167,10 @@ describe("telegram inbound media", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(runtimeError).not.toHaveBeenCalled();
|
expect(runtimeError).not.toHaveBeenCalled();
|
||||||
expect(fetchSpy).toHaveBeenCalledWith("https://api.telegram.org/file/bottok/photos/1.jpg");
|
expect(fetchSpy).toHaveBeenCalledWith(
|
||||||
|
"https://api.telegram.org/file/bottok/photos/1.jpg",
|
||||||
|
expect.any(Object),
|
||||||
|
);
|
||||||
expect(replySpy).toHaveBeenCalledTimes(1);
|
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||||
const payload = replySpy.mock.calls[0][0];
|
const payload = replySpy.mock.calls[0][0];
|
||||||
expect(payload.Body).toContain("<media:image>");
|
expect(payload.Body).toContain("<media:image>");
|
||||||
|
|
@ -211,7 +225,10 @@ describe("telegram inbound media", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(runtimeError).not.toHaveBeenCalled();
|
expect(runtimeError).not.toHaveBeenCalled();
|
||||||
expect(proxyFetch).toHaveBeenCalledWith("https://api.telegram.org/file/bottok/photos/2.jpg");
|
expect(proxyFetch).toHaveBeenCalledWith(
|
||||||
|
"https://api.telegram.org/file/bottok/photos/2.jpg",
|
||||||
|
expect.any(Object),
|
||||||
|
);
|
||||||
|
|
||||||
globalFetchSpy.mockRestore();
|
globalFetchSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
@ -484,6 +501,7 @@ describe("telegram stickers", () => {
|
||||||
expect(runtimeError).not.toHaveBeenCalled();
|
expect(runtimeError).not.toHaveBeenCalled();
|
||||||
expect(fetchSpy).toHaveBeenCalledWith(
|
expect(fetchSpy).toHaveBeenCalledWith(
|
||||||
"https://api.telegram.org/file/bottok/stickers/sticker.webp",
|
"https://api.telegram.org/file/bottok/stickers/sticker.webp",
|
||||||
|
expect.any(Object),
|
||||||
);
|
);
|
||||||
expect(replySpy).toHaveBeenCalledTimes(1);
|
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||||
const payload = replySpy.mock.calls[0][0];
|
const payload = replySpy.mock.calls[0][0];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue