fix: address code review findings
This commit is contained in:
@@ -19,9 +19,8 @@ import (
|
||||
|
||||
func flushRedisForTest(t *testing.T, client *redis.Client) {
|
||||
// Clear preference-related keys from Redis to ensure test isolation
|
||||
// The keyString sanitization prepends "unknown:" and replaces ":" with "_colon_"
|
||||
// Actual keys look like: "unknown:prefs_colon_saved_city_colon_testuser1"
|
||||
keys, err := client.Keys(context.Background(), "unknown:prefs*").Result()
|
||||
// Actual keys look like: "prefs:saved_city:testuser1" and "prefs:search_history:testuser1"
|
||||
keys, err := client.Keys(context.Background(), "prefs:saved_city:*").Result()
|
||||
if err != nil {
|
||||
t.Logf("warning: could not flush preference keys: %v", err)
|
||||
return
|
||||
@@ -32,7 +31,7 @@ func flushRedisForTest(t *testing.T, client *redis.Client) {
|
||||
}
|
||||
}
|
||||
// Also delete search_history keys
|
||||
keys2, err := client.Keys(context.Background(), "unknown:search_history*").Result()
|
||||
keys2, err := client.Keys(context.Background(), "prefs:search_history:*").Result()
|
||||
if err != nil {
|
||||
t.Logf("warning: could not flush search history keys: %v", err)
|
||||
return
|
||||
@@ -765,7 +764,7 @@ func TestUserPreferences(t *testing.T) {
|
||||
flushRedisForTest(t, h.Redis)
|
||||
|
||||
// Add a saved city
|
||||
addReq := httptest.NewRequest("POST", "/v1/preferences/saved-cities?user_id=testuser2", strings.NewReader(`{"city_code":"c1","name":"Moscow"}`,))
|
||||
addReq := httptest.NewRequest("POST", "/v1/preferences/saved-cities?user_id=testuser2", strings.NewReader(`{"city_code":"c1","name":"Moscow"}`))
|
||||
addReq.Header.Set("Content-Type", "application/json")
|
||||
addRR := httptest.NewRecorder()
|
||||
AddSavedCity(h, addRR, addReq)
|
||||
|
||||
Reference in New Issue
Block a user