Bug because of Lewis' initial misunderstanding
+63
crates/tranquil-pds/tests/actor.rs
+63
crates/tranquil-pds/tests/actor.rs
···
74
74
assert_eq!(adult_pref.unwrap()["enabled"], true);
75
75
}
76
76
77
+
#[tokio::test]
78
+
async fn test_put_preferences_multiple_same_type() {
79
+
let client = client();
80
+
let base = base_url().await;
81
+
let (token, _did) = create_account_and_login(&client).await;
82
+
let prefs = json!({
83
+
"preferences": [
84
+
{
85
+
"$type": "app.bsky.actor.defs#adultContentPref",
86
+
"enabled": false
87
+
},
88
+
{
89
+
"$type": "app.bsky.actor.defs#contentLabelPref",
90
+
"label": "dogs",
91
+
"visibility": "show"
92
+
},
93
+
{
94
+
"$type": "app.bsky.actor.defs#contentLabelPref",
95
+
"label": "cats",
96
+
"visibility": "warn"
97
+
}
98
+
]
99
+
});
100
+
let resp = client
101
+
.post(format!("{}/xrpc/app.bsky.actor.putPreferences", base))
102
+
.header("Authorization", format!("Bearer {}", token))
103
+
.json(&prefs)
104
+
.send()
105
+
.await
106
+
.unwrap();
107
+
assert_eq!(resp.status(), 200);
108
+
let resp = client
109
+
.get(format!("{}/xrpc/app.bsky.actor.getPreferences", base))
110
+
.header("Authorization", format!("Bearer {}", token))
111
+
.send()
112
+
.await
113
+
.unwrap();
114
+
assert_eq!(resp.status(), 200);
115
+
let body: Value = resp.json().await.unwrap();
116
+
let prefs_arr = body["preferences"].as_array().unwrap();
117
+
assert_eq!(prefs_arr.len(), 3);
118
+
let adult_pref = prefs_arr
119
+
.iter()
120
+
.find(|p| p.get("$type").and_then(|t| t.as_str()) == Some("app.bsky.actor.defs#adultContentPref"));
121
+
assert!(adult_pref.is_some());
122
+
assert_eq!(adult_pref.unwrap()["enabled"], false);
123
+
let content_label_prefs: Vec<&Value> = prefs_arr
124
+
.iter()
125
+
.filter(|p| p.get("$type").and_then(|t| t.as_str()) == Some("app.bsky.actor.defs#contentLabelPref"))
126
+
.collect();
127
+
assert_eq!(content_label_prefs.len(), 2);
128
+
let dogs_pref = content_label_prefs
129
+
.iter()
130
+
.find(|p| p.get("label").and_then(|l| l.as_str()) == Some("dogs"));
131
+
assert!(dogs_pref.is_some());
132
+
assert_eq!(dogs_pref.unwrap()["visibility"], "show");
133
+
let cats_pref = content_label_prefs
134
+
.iter()
135
+
.find(|p| p.get("label").and_then(|l| l.as_str()) == Some("cats"));
136
+
assert!(cats_pref.is_some());
137
+
assert_eq!(cats_pref.unwrap()["visibility"], "warn");
138
+
}
139
+
77
140
#[tokio::test]
78
141
async fn test_put_preferences_no_auth() {
79
142
let client = client();
+1
migrations/20260121_preferences_allow_duplicate_types.sql
+1
migrations/20260121_preferences_allow_duplicate_types.sql
···
1
+
ALTER TABLE account_preferences DROP CONSTRAINT IF EXISTS account_preferences_user_id_name_key;