add loose search order test
@@ -414,6 +414,67 @@ fn exact_match_on_queries_with_sort() {
assert_eq!(json.crates[3].name, "other_sort");
}
+#[test]
+fn loose_search_order() {
+ let (app, anon, user) = TestApp::init().with_user();
+ let user = user.as_model();
+
+ let ordered = app.db(|conn| {
+ // exact match should be first
+ let one = CrateBuilder::new("temp", user.id)
+ .readme("readme")
+ .description("description")
+ .keyword("kw1")
+ .expect_build(conn);
+ // file shouldn't match at all
+ CrateBuilder::new("file", user.id)
+ .readme("readme")
+ .description("description")
+ .keyword("kw1")
+ .expect_build(conn);
+ // temp_udp should match second
+ let two = CrateBuilder::new("temp_utp", user.id)
+ .readme("readme")
+ .description("description")
+ .keyword("kw1")
+ .expect_build(conn);
+ // evalrs should match 3rd because of readme
+ let three = CrateBuilder::new("evalrs", user.id)
+ .readme(r#"$ echo 'println!("Hello World!")' | evalrs
+ Compiling evalrs_temp v0.0.0 (file:///tmp/evalrs_temp.daiPxHtjV2VR)
+ Finished debug [unoptimized + debuginfo] target(s) in 0.51 secs
+ Running `target\debug\evalrs_temp.exe`
+Hello World!"#)
+ .description("description")
+ .keyword("kw1")
+ .expect_build(conn);
+ // tempfile should appear 4th
+ let four = CrateBuilder::new("tempfile", user.id)
+ .readme("readme")
+ .description("description")
+ .keyword("kw1")
+ .expect_build(conn);
+ // mkstemp should appear 5th
+ let five = CrateBuilder::new("mkstemp", user.id)
+ .readme("readme")
+ .description("description")
+ .keyword("kw1")
+ .expect_build(conn);
+ vec![one, two, three, four, five]
+ });
+ let search_temp = anon.search("q=temp");
+ assert_eq!(search_temp.meta.total, 5);
+ assert_eq!(search_temp.crates.len(), 5);
+ for (lhs, rhs) in search_temp.crates.iter().zip(ordered) {
+ assert_eq!(lhs.name, rhs.name);
+ }
+ let search_file = anon.search("q=file");
+ assert_eq!(search_file.meta.total, 2);
+ assert_eq!(search_file.crates.len(), 2);
+ assert_eq!(&search_file.crates[0].name, "file");
+ assert_eq!(&search_file.crates[1].name, "tempfile");
+}
+
#[test]
fn show() {
let (app, anon, user) = TestApp::init().with_user();
