fix: 兼容历史收藏源避免列表崩溃
This commit is contained in:
@@ -4964,6 +4964,41 @@ func TestServeIMFavoritesListSupportsRefOnlyAttachment(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeIMFavoritesListKeepsLegacySeedSnapshots(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
expectIMBearer(t, ctrl, "token-1", 7, 42)
|
||||
oldFavorites := store.Favorites
|
||||
oldSubs := store.Subs
|
||||
oldMessages := store.Messages
|
||||
now := time.Date(2026, 9, 9, 9, 0, 0, 0, time.UTC)
|
||||
store.Favorites = &testFavoritesStore{items: []types.FavoriteItem{{
|
||||
TenantID: 7, FavoriteID: "fav_seed_19179719768_text", UserID: 42, ItemType: "text",
|
||||
SourceTopic: "favSeed19179719768", SourceSeq: 7001, Availability: "available", CollectedAt: now,
|
||||
Snapshot: map[string]any{"text": "seed favorite"},
|
||||
}}}
|
||||
store.Subs = mock_store.NewMockSubsPersistenceInterface(ctrl)
|
||||
store.Messages = nil
|
||||
defer func() {
|
||||
store.Favorites = oldFavorites
|
||||
store.Subs = oldSubs
|
||||
store.Messages = oldMessages
|
||||
}()
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/v1/im/favorites?type=all", nil)
|
||||
req.Header.Set("Authorization", "Bearer token-1")
|
||||
rec := httptest.NewRecorder()
|
||||
serveIMFavorites(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status: got %d, want %d; body=%s", rec.Code, http.StatusOK, rec.Body.String())
|
||||
}
|
||||
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
|
||||
items := data["items"].([]any)
|
||||
if len(items) != 1 || items[0].(map[string]any)["favorite_id"] != "fav_seed_19179719768_text" {
|
||||
t.Fatalf("unexpected legacy seed favorite response: %#v", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeIMUserVisibleTopicSelf(t *testing.T) {
|
||||
uid := types.Uid(42)
|
||||
got, ok := normalizeIMUserVisibleTopic(uid, "slf")
|
||||
|
||||
Reference in New Issue
Block a user