Skip to main content

max / makenotwork

4.1 KB · 111 lines History Blame Raw
1 use crate::harness::TestHarness;
2
3 #[tokio::test]
4 async fn search_by_thread_title() {
5 let mut h = TestHarness::new().await;
6 let user_id = h.login_as("searchtitle").await;
7 let comm_id = h.create_community("Test", "test").await;
8 let cat_id = h.create_category(comm_id, "General", "general").await;
9 h.add_membership(user_id, comm_id, "member").await;
10
11 h.create_thread_with_post(cat_id, user_id, "Unique Flamingo Discussion", "body text").await;
12 h.create_thread_with_post(cat_id, user_id, "Other Thread", "nothing here").await;
13
14 let resp = h.client.get("/search?q=flamingo").await;
15 assert_eq!(resp.status, 200);
16 assert!(
17 resp.text.contains("Unique Flamingo Discussion"),
18 "Expected thread title in search results. Body: {}",
19 &resp.text
20 );
21 assert!(
22 !resp.text.contains("Other Thread"),
23 "Non-matching thread should not appear"
24 );
25 }
26
27 #[tokio::test]
28 async fn search_body_content_match() {
29 let mut h = TestHarness::new().await;
30 let user_id = h.login_as("searchbody").await;
31 let comm_id = h.create_community("Test", "test").await;
32 let cat_id = h.create_category(comm_id, "General", "general").await;
33 h.add_membership(user_id, comm_id, "member").await;
34
35 h.create_thread_with_post(cat_id, user_id, "Generic Title", "zygomorphic flower patterns").await;
36
37 let resp = h.client.get("/search?q=zygomorphic").await;
38 assert_eq!(resp.status, 200);
39 assert!(
40 resp.text.contains("Generic Title"),
41 "Thread with matching body should appear. Body: {}",
42 &resp.text
43 );
44 }
45
46 #[tokio::test]
47 async fn search_scoped_to_community() {
48 let mut h = TestHarness::new().await;
49 let user_id = h.login_as("searchscoped").await;
50
51 let comm1 = h.create_community("Alpha", "alpha").await;
52 let cat1 = h.create_category(comm1, "General", "general").await;
53 h.add_membership(user_id, comm1, "member").await;
54
55 let comm2 = h.create_community("Beta", "beta").await;
56 let cat2 = h.create_category(comm2, "General", "general").await;
57 h.add_membership(user_id, comm2, "member").await;
58
59 h.create_thread_with_post(cat1, user_id, "Shared Keyword Xylophone", "content").await;
60 h.create_thread_with_post(cat2, user_id, "Shared Keyword Xylophone Two", "content").await;
61
62 // Scoped to alpha
63 let resp = h.client.get("/search?q=xylophone&scope=alpha").await;
64 assert_eq!(resp.status, 200);
65 assert!(resp.text.contains("Shared Keyword Xylophone"), "Alpha result should appear");
66 assert!(!resp.text.contains("Xylophone Two"), "Beta result should NOT appear in scoped search");
67
68 // Global
69 let resp = h.client.get("/search?q=xylophone").await;
70 assert!(resp.text.contains("Xylophone Two"), "Beta result should appear in global search");
71 }
72
73 #[tokio::test]
74 async fn search_empty_query_returns_nothing() {
75 let mut h = TestHarness::new().await;
76 let user_id = h.login_as("searchempty").await;
77 let comm_id = h.create_community("Test", "test").await;
78 let cat_id = h.create_category(comm_id, "General", "general").await;
79 h.add_membership(user_id, comm_id, "member").await;
80
81 h.create_thread_with_post(cat_id, user_id, "Should Not Appear", "content").await;
82
83 let resp = h.client.get("/search?q=").await;
84 assert_eq!(resp.status, 200);
85 assert!(
86 !resp.text.contains("Should Not Appear"),
87 "Empty query should return no results"
88 );
89 }
90
91 #[tokio::test]
92 async fn search_deleted_thread_excluded() {
93 let mut h = TestHarness::new().await;
94 let user_id = h.login_as("searchdeleted").await;
95 let comm_id = h.create_community("Test", "test").await;
96 let cat_id = h.create_category(comm_id, "General", "general").await;
97 h.add_membership(user_id, comm_id, "member").await;
98
99 let thread_id = h.create_thread_with_post(cat_id, user_id, "Ephemeral Jellyfish", "content").await;
100
101 // Soft-delete the thread
102 mt_db::mutations::soft_delete_thread(&h.db, thread_id).await.unwrap();
103
104 let resp = h.client.get("/search?q=jellyfish").await;
105 assert_eq!(resp.status, 200);
106 assert!(
107 !resp.text.contains("Ephemeral Jellyfish"),
108 "Deleted thread should not appear in search"
109 );
110 }
111