|
1 | 1 | // Feishu tests cover app registration plugin behavior. |
2 | 2 | import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime"; |
3 | 3 | import { afterEach, describe, expect, it, vi } from "vitest"; |
4 | | -import { beginAppRegistration, pollAppRegistration } from "./app-registration.js"; |
| 4 | +import { beginAppRegistration, pollAppRegistration, printQrCode } from "./app-registration.js"; |
5 | 5 | |
6 | | -const { fetchWithSsrFGuardMock } = vi.hoisted(() => ({ |
| 6 | +const { fetchWithSsrFGuardMock, renderQrTerminalMock } = vi.hoisted(() => ({ |
7 | 7 | fetchWithSsrFGuardMock: vi.fn(), |
| 8 | +renderQrTerminalMock: vi.fn(async () => "terminal-qr"), |
8 | 9 | })); |
9 | 10 | |
10 | 11 | vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({ |
11 | 12 | fetchWithSsrFGuard: fetchWithSsrFGuardMock, |
12 | 13 | })); |
13 | 14 | |
| 15 | +vi.mock("./qr-terminal.js", () => ({ |
| 16 | +renderQrTerminal: renderQrTerminalMock, |
| 17 | +})); |
| 18 | + |
14 | 19 | function mockFeishuJson(payload: unknown) { |
15 | 20 | fetchWithSsrFGuardMock.mockResolvedValueOnce({ |
16 | 21 | response: new Response(JSON.stringify(payload), { status: 200 }), |
@@ -23,6 +28,7 @@ describe("Feishu app registration", () => {
|
23 | 28 | vi.useRealTimers(); |
24 | 29 | vi.restoreAllMocks(); |
25 | 30 | fetchWithSsrFGuardMock.mockReset(); |
| 31 | +renderQrTerminalMock.mockClear(); |
26 | 32 | }); |
27 | 33 | |
28 | 34 | it("defaults unsafe begin polling lifetimes from provider responses", async () => { |
@@ -59,4 +65,16 @@ describe("Feishu app registration", () => {
|
59 | 65 | await vi.runOnlyPendingTimersAsync(); |
60 | 66 | await expect(poll).resolves.toEqual({ status: "timeout" }); |
61 | 67 | }); |
| 68 | + |
| 69 | +it("prints scan-to-create QR codes with compact terminal rendering", async () => { |
| 70 | +const writeSpy = vi.spyOn(process.stdout, "write").mockImplementation(() => true); |
| 71 | + |
| 72 | +await printQrCode("https://accounts.feishu.cn/verify?device_code=long-device-code"); |
| 73 | + |
| 74 | +expect(renderQrTerminalMock).toHaveBeenCalledWith( |
| 75 | +"https://accounts.feishu.cn/verify?device_code=long-device-code", |
| 76 | +{ small: true }, |
| 77 | +); |
| 78 | +expect(writeSpy).toHaveBeenCalledWith("terminal-qr\n"); |
| 79 | +}); |
62 | 80 | }); |