Skip to main content

max / makenotwork

1.9 KB · 71 lines History Blame Raw
1 //! Preferences workflow tests: update notification preferences.
2
3 use crate::harness::TestHarness;
4
5 #[tokio::test]
6 async fn preferences_requires_auth() {
7 let mut h = TestHarness::new().await;
8
9 let resp = h
10 .client
11 .put_form("/api/users/me/preferences", "notify_sale=on")
12 .await;
13 assert_eq!(
14 resp.status, 403,
15 "Unauthenticated preferences update should be rejected: {} {}",
16 resp.status, resp.text
17 );
18 }
19
20 #[tokio::test]
21 async fn preferences_enable_all() {
22 let mut h = TestHarness::new().await;
23 let _user_id = h.signup("prefall", "prefall@test.com", "password123").await;
24
25 let resp = h
26 .client
27 .put_form(
28 "/api/users/me/preferences",
29 "notify_sale=on&notify_follower=on&notify_release=on&login_notification_enabled=on",
30 )
31 .await;
32 assert_eq!(
33 resp.status, 200,
34 "Enable all preferences should succeed: {} {}",
35 resp.status, resp.text
36 );
37 }
38
39 #[tokio::test]
40 async fn preferences_disable_all() {
41 let mut h = TestHarness::new().await;
42 let _user_id = h.signup("prefdis", "prefdis@test.com", "password123").await;
43
44 // Omitting all fields = all false (HTML checkbox behavior)
45 let resp = h.client.put_form("/api/users/me/preferences", "").await;
46 assert_eq!(
47 resp.status, 200,
48 "Disable all preferences should succeed: {} {}",
49 resp.status, resp.text
50 );
51 }
52
53 #[tokio::test]
54 async fn preferences_partial_update() {
55 let mut h = TestHarness::new().await;
56 let _user_id = h
57 .signup("prefpart", "prefpart@test.com", "password123")
58 .await;
59
60 // Only enable sale notifications
61 let resp = h
62 .client
63 .put_form("/api/users/me/preferences", "notify_sale=on")
64 .await;
65 assert_eq!(
66 resp.status, 200,
67 "Partial preferences update should succeed: {} {}",
68 resp.status, resp.text
69 );
70 }
71