Skip to main content

max / makenotwork

2.0 KB · 75 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,
17 resp.text
18 );
19 }
20
21 #[tokio::test]
22 async fn preferences_enable_all() {
23 let mut h = TestHarness::new().await;
24 let _user_id = h.signup("prefall", "prefall@test.com", "password123").await;
25
26 let resp = h
27 .client
28 .put_form(
29 "/api/users/me/preferences",
30 "notify_sale=on&notify_follower=on&notify_release=on&login_notification_enabled=on",
31 )
32 .await;
33 assert!(
34 resp.status.is_success(),
35 "Enable all preferences should succeed: {} {}",
36 resp.status,
37 resp.text
38 );
39 }
40
41 #[tokio::test]
42 async fn preferences_disable_all() {
43 let mut h = TestHarness::new().await;
44 let _user_id = h.signup("prefdis", "prefdis@test.com", "password123").await;
45
46 // Omitting all fields = all false (HTML checkbox behavior)
47 let resp = h.client.put_form("/api/users/me/preferences", "").await;
48 assert!(
49 resp.status.is_success(),
50 "Disable all preferences should succeed: {} {}",
51 resp.status,
52 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
60 .signup("prefpart", "prefpart@test.com", "password123")
61 .await;
62
63 // Only enable sale notifications
64 let resp = h
65 .client
66 .put_form("/api/users/me/preferences", "notify_sale=on")
67 .await;
68 assert!(
69 resp.status.is_success(),
70 "Partial preferences update should succeed: {} {}",
71 resp.status,
72 resp.text
73 );
74 }
75