11// Feishu tests cover app registration plugin behavior.
22import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime" ;
33import { afterEach , describe , expect , it , vi } from "vitest" ;
4- import { beginAppRegistration , pollAppRegistration } from "./app-registration.js" ;
4+ import { beginAppRegistration , pollAppRegistration , printQrCode } from "./app-registration.js" ;
55
6- const { fetchWithSsrFGuardMock } = vi . hoisted ( ( ) => ( {
6+ const { fetchWithSsrFGuardMock, renderQrTerminalMock } = vi . hoisted ( ( ) => ( {
77 fetchWithSsrFGuardMock : vi . fn ( ) ,
8+ renderQrTerminalMock : vi . fn ( async ( ) => "terminal-qr" ) ,
89} ) ) ;
910
1011vi . mock ( "openclaw/plugin-sdk/ssrf-runtime" , ( ) => ( {
1112 fetchWithSsrFGuard : fetchWithSsrFGuardMock ,
1213} ) ) ;
1314
15+ vi . mock ( "./qr-terminal.js" , ( ) => ( {
16+ renderQrTerminal : renderQrTerminalMock ,
17+ } ) ) ;
18+
1419function mockFeishuJson ( payload : unknown ) {
1520 fetchWithSsrFGuardMock . mockResolvedValueOnce ( {
1621 response : new Response ( JSON . stringify ( payload ) , { status : 200 } ) ,
@@ -23,6 +28,7 @@ describe("Feishu app registration", () => {
2328 vi . useRealTimers ( ) ;
2429 vi . restoreAllMocks ( ) ;
2530 fetchWithSsrFGuardMock . mockReset ( ) ;
31+ renderQrTerminalMock . mockClear ( ) ;
2632 } ) ;
2733
2834 it ( "defaults unsafe begin polling lifetimes from provider responses" , async ( ) => {
@@ -59,4 +65,16 @@ describe("Feishu app registration", () => {
5965 await vi . runOnlyPendingTimersAsync ( ) ;
6066 await expect ( poll ) . resolves . toEqual ( { status : "timeout" } ) ;
6167 } ) ;
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+ } ) ;
6280} ) ;
0 commit comments