Fixes missing plugin/datapack in search (#829)

* fixes datapack/plugin issue

* fixes level

* server side searching; org projects

* total hits

* total hits fixes

---------

Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Wyatt Verchere
2024-01-07 13:36:26 -08:00
committed by GitHub
parent aee9b6a951
commit c3448033de
13 changed files with 217 additions and 337 deletions

View File

@@ -20,6 +20,7 @@ pub async fn setup_search_projects(test_env: &TestEnvironment<ApiV3>) -> Arc<Has
// Test setup and dummy data
let api = &test_env.api;
let test_name = test_env.db.database_name.clone();
let zeta_organization_id = &test_env.dummy.organization_zeta.organization_id;
// Add dummy projects of various categories for searchability
let mut project_creation_futures = vec![];
@@ -184,6 +185,20 @@ pub async fn setup_search_projects(test_env: &TestEnvironment<ApiV3>) -> Arc<Has
Some(modify_json),
));
// Test project 9 (organization)
// This project gets added to the Zeta organization automatically
let id = 9;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/organization_id", "value": zeta_organization_id },
]))
.unwrap();
project_creation_futures.push(create_async_future(
id,
USER_USER_PAT,
false,
Some(modify_json),
));
// Await all project creation
// Returns a mapping of:
// project id -> test id

View File

@@ -27,11 +27,14 @@ async fn search_projects() {
// 1. vec of search facets
// 2. expected project ids to be returned by this search
let pairs = vec![
(json!([["categories:fabric"]]), vec![0, 1, 2, 3, 4, 5, 6, 7]),
(
json!([["categories:fabric"]]),
vec![0, 1, 2, 3, 4, 5, 6, 7, 9],
),
(json!([["categories:forge"]]), vec![7]),
(
json!([["categories:fabric", "categories:forge"]]),
vec![0, 1, 2, 3, 4, 5, 6, 7],
vec![0, 1, 2, 3, 4, 5, 6, 7, 9],
),
(json!([["categories:fabric"], ["categories:forge"]]), vec![]),
(
@@ -42,12 +45,12 @@ async fn search_projects() {
vec![1, 2, 3, 4],
),
(json!([["project_types:modpack"]]), vec![4]),
(json!([["client_only:true"]]), vec![0, 2, 3, 7]),
(json!([["client_only:true"]]), vec![0, 2, 3, 7, 9]),
(json!([["server_only:true"]]), vec![0, 2, 3, 6, 7]),
(json!([["open_source:true"]]), vec![0, 1, 2, 4, 5, 6, 7]),
(json!([["license:MIT"]]), vec![1, 2, 4]),
(json!([["open_source:true"]]), vec![0, 1, 2, 4, 5, 6, 7, 9]),
(json!([["license:MIT"]]), vec![1, 2, 4, 9]),
(json!([[r#"name:'Mysterious Project'"#]]), vec![2, 3]),
(json!([["author:user"]]), vec![0, 1, 2, 4, 5, 7]),
(json!([["author:user"]]), vec![0, 1, 2, 4, 5, 7, 9]), // Organization test '9' is included here as user is owner of org
(json!([["game_versions:1.20.5"]]), vec![4, 5]),
// bug fix
(
@@ -98,10 +101,12 @@ async fn search_projects() {
.into_iter()
.map(|p| id_conversion[&p.id.0])
.collect();
let num_hits = projects.total_hits;
expected_project_ids.sort();
found_project_ids.sort();
println!("Facets: {:?}", facets);
assert_eq!(found_project_ids, expected_project_ids);
assert_eq!(num_hits, expected_project_ids.len() as usize);
}
})
.await;

View File

@@ -189,6 +189,20 @@ async fn search_projects() {
Some(modify_json),
));
// Test project 8
// Server side unsupported
let id = 8;
let modify_json = serde_json::from_value(json!([
{ "op": "add", "path": "/server_side", "value": "unsupported" },
]))
.unwrap();
project_creation_futures.push(create_async_future(
id,
USER_USER_PAT,
false,
Some(modify_json),
));
// Await all project creation
// Returns a mapping of:
// project id -> test id
@@ -226,11 +240,14 @@ async fn search_projects() {
]),
vec![],
),
(json!([["categories:fabric"]]), vec![0, 1, 2, 3, 4, 5, 6, 7]),
(
json!([["categories:fabric"]]),
vec![0, 1, 2, 3, 4, 5, 6, 7, 8],
),
(json!([["categories:forge"]]), vec![7]),
(
json!([["categories:fabric", "categories:forge"]]),
vec![0, 1, 2, 3, 4, 5, 6, 7],
vec![0, 1, 2, 3, 4, 5, 6, 7, 8],
),
(json!([["categories:fabric"], ["categories:forge"]]), vec![]),
(
@@ -243,12 +260,12 @@ async fn search_projects() {
(json!([["project_types:modpack"]]), vec![4]),
// Formerly included 7, but with v2 changes, this is no longer the case.
// This is because we assume client_side/server_side with subsequent versions.
(json!([["client_side:required"]]), vec![0, 2, 3]),
(json!([["client_side:required"]]), vec![0, 2, 3, 8]),
(json!([["server_side:required"]]), vec![0, 2, 3, 6, 7]),
(json!([["open_source:true"]]), vec![0, 1, 2, 4, 5, 6, 7]),
(json!([["license:MIT"]]), vec![1, 2, 4]),
(json!([["open_source:true"]]), vec![0, 1, 2, 4, 5, 6, 7, 8]),
(json!([["license:MIT"]]), vec![1, 2, 4, 8]),
(json!([[r#"title:'Mysterious Project'"#]]), vec![2, 3]),
(json!([["author:user"]]), vec![0, 1, 2, 4, 5, 7]),
(json!([["author:user"]]), vec![0, 1, 2, 4, 5, 7, 8]),
(json!([["versions:1.20.5"]]), vec![4, 5]),
// bug fix
(
@@ -275,6 +292,12 @@ async fn search_projects() {
]),
vec![4],
),
(
json!([["client_side:optional"], ["server_side:optional"]]),
vec![1, 4, 5],
),
(json!([["server_side:optional"]]), vec![1, 4, 5]),
(json!([["server_side:unsupported"]]), vec![8]),
];
// TODO: Untested:
@@ -313,7 +336,7 @@ async fn search_projects() {
})
.await;
// A couple additional tests for the saerch type returned, making sure it is properly translated back
// A couple additional tests for the search type returned, making sure it is properly translated back
let client_side_required = api
.search_deserialized(
Some(&format!("\"&{test_name}\"")),
@@ -347,6 +370,18 @@ async fn search_projects() {
assert_eq!(hit.client_side, "unsupported".to_string());
}
let client_side_optional_server_side_optional = api
.search_deserialized(
Some(&format!("\"&{test_name}\"")),
Some(json!([["client_side:optional"], ["server_side:optional"]])),
USER_USER_PAT,
)
.await;
for hit in client_side_optional_server_side_optional.hits {
assert_eq!(hit.client_side, "optional".to_string());
assert_eq!(hit.server_side, "optional".to_string());
}
let game_versions = api
.search_deserialized(
Some(&format!("\"&{test_name}\"")),