@@ -312,6 +312,79 @@ func TestRefreshAccountReturnsRefreshFailure(t *testing.T) {
312312 }
313313}
314314
315+ func TestBatchRefreshAccountsReportsCounts (t * testing.T ) {
316+ gin .SetMode (gin .TestMode )
317+
318+ handler := & Handler {
319+ refreshAccount : func (_ context.Context , id int64 ) error {
320+ if id == 8 {
321+ return errors .New ("upstream unavailable" )
322+ }
323+ return nil
324+ },
325+ }
326+
327+ recorder := httptest .NewRecorder ()
328+ ctx , _ := gin .CreateTestContext (recorder )
329+ ctx .Request = httptest .NewRequest (http .MethodPost , "/api/admin/accounts/batch-refresh" , strings .NewReader (`{"ids":[7,8,7,0]}` ))
330+
331+ handler .BatchRefreshAccounts (ctx )
332+
333+ if recorder .Code != http .StatusOK {
334+ t .Fatalf ("status = %d, want %d" , recorder .Code , http .StatusOK )
335+ }
336+
337+ var payload map [string ]any
338+ if err := json .Unmarshal (recorder .Body .Bytes (), & payload ); err != nil {
339+ t .Fatalf ("decode response: %v" , err )
340+ }
341+ if got := payload ["success" ]; got != float64 (1 ) {
342+ t .Fatalf ("success = %v, want 1" , got )
343+ }
344+ if got := payload ["failed" ]; got != float64 (1 ) {
345+ t .Fatalf ("failed = %v, want 1" , got )
346+ }
347+ }
348+
349+ func TestBatchRefreshAccountsStreamsProgress (t * testing.T ) {
350+ gin .SetMode (gin .TestMode )
351+
352+ handler := & Handler {
353+ refreshAccount : func (_ context.Context , id int64 ) error {
354+ if id == 8 {
355+ return errors .New ("账号 8 不存在" )
356+ }
357+ return nil
358+ },
359+ }
360+
361+ recorder := httptest .NewRecorder ()
362+ ctx , _ := gin .CreateTestContext (recorder )
363+ ctx .Request = httptest .NewRequest (http .MethodPost , "/api/admin/accounts/batch-refresh?stream=true" , strings .NewReader (`{"ids":[7,8]}` ))
364+
365+ handler .BatchRefreshAccounts (ctx )
366+
367+ if recorder .Code != http .StatusOK {
368+ t .Fatalf ("status = %d, want %d" , recorder .Code , http .StatusOK )
369+ }
370+ if got := recorder .Header ().Get ("Content-Type" ); ! strings .Contains (got , "text/event-stream" ) {
371+ t .Fatalf ("content-type = %q, want event-stream" , got )
372+ }
373+ body := recorder .Body .String ()
374+ for _ , want := range []string {
375+ `"type":"start"` ,
376+ `"type":"progress"` ,
377+ `"type":"complete"` ,
378+ `"action":"batch_refresh"` ,
379+ `"success":1` ,
380+ `"failed":1` ,
381+ } {
382+ if ! strings .Contains (body , want ) {
383+ t .Fatalf ("stream body missing %s:\n %s" , want , body )
384+ }
385+ }
386+ }
387+
315388func TestResetAccountStatusSyncsPlanMetadata (t * testing.T ) {
316389 gin .SetMode (gin .TestMode )
317390
0 commit comments