Fix conversation context topic fallback

This commit is contained in:
richjohnrambo
2026-09-03 11:47:45 +08:00
parent 2e4e1f0df3
commit 871e0ba735
2 changed files with 69 additions and 1 deletions
+33
View File
@@ -5736,6 +5736,39 @@ func TestServeIMConversationContextAcceptsUserTopic(t *testing.T) {
}
}
func TestServeIMConversationContextAcceptsFriendListTopicFallback(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
expectIMBearer(t, ctrl, "token-1", 7, 1)
oldRelations := store.Relations
peer := types.Uid(2)
legacyTopic := types.Uid(2).P2PName(types.Uid(3))
store.Relations = &testRelationsStore{friends: []types.FriendListItem{{
Friendship: types.Friendship{
TenantID: 7,
UserID: types.Uid(1),
PeerID: peer,
Status: types.RelationshipFriend,
Topic: legacyTopic,
},
}}}
defer func() { store.Relations = oldRelations }()
req := httptest.NewRequest(http.MethodGet, "/v1/im/conversations/"+legacyTopic+"/context", nil)
req.Header.Set("Authorization", "Bearer token-1")
rec := httptest.NewRecorder()
serveIMConversationContext(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)
if data["topic"] != legacyTopic || data["peer_user_id"] != peer.UserId() {
t.Fatalf("unexpected context response: %#v", data)
}
}
func TestNormalizeP2PConversationTopicParsesTinodeTopic(t *testing.T) {
user := types.Uid(1)
peer := types.Uid(2)