Skip to main content

max / makenotwork

2.0 KB · 72 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!(
14 resp.status.is_client_error() || resp.status.is_redirection(),
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!(
33 resp.status.is_success(),
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
46 .client
47 .put_form("/api/users/me/preferences", "")
48 .await;
49 assert!(
50 resp.status.is_success(),
51 "Disable all preferences should succeed: {} {}",
52 resp.status, resp.text
53 );
54 }
55
56 #[tokio::test]
57 async fn preferences_partial_update() {
58 let mut h = TestHarness::new().await;
59 let _user_id = h.signup("prefpart", "prefpart@test.com", "password123").await;
60
61 // Only enable sale notifications
62 let resp = h
63 .client
64 .put_form("/api/users/me/preferences", "notify_sale=on")
65 .await;
66 assert!(
67 resp.status.is_success(),
68 "Partial preferences update should succeed: {} {}",
69 resp.status, resp.text
70 );
71 }
72