mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-25 22:34:28 +01:00
Add tests
This commit is contained in:
parent
3167411e98
commit
a61b852695
@ -310,6 +310,23 @@ macro_rules! compute_authorized_single_search {
|
|||||||
tenant_token,
|
tenant_token,
|
||||||
key_content
|
key_content
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// federated
|
||||||
|
let (response, code) = server.multi_search(json!({"federation": {}, "queries" : [{"indexUid": "sales", "filter": $filter}]})).await;
|
||||||
|
assert_eq!(
|
||||||
|
200, code,
|
||||||
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
|
response, tenant_token, key_content
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
// same count as the search is federated over a single query
|
||||||
|
$expected_count,
|
||||||
|
response["hits"].as_array().unwrap().len(),
|
||||||
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
|
response,
|
||||||
|
tenant_token,
|
||||||
|
key_content
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -375,6 +392,25 @@ macro_rules! compute_authorized_multiple_search {
|
|||||||
tenant_token,
|
tenant_token,
|
||||||
key_content
|
key_content
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let (response, code) = server.multi_search(json!({"federation": {}, "queries" : [
|
||||||
|
{"indexUid": "sales", "filter": $filter1},
|
||||||
|
{"indexUid": "products", "filter": $filter2},
|
||||||
|
]})).await;
|
||||||
|
assert_eq!(
|
||||||
|
code, 200,
|
||||||
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
|
response, tenant_token, key_content
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
response["hits"].as_array().unwrap().len(),
|
||||||
|
// sum of counts as the search is federated across to queries in different indexes
|
||||||
|
$expected_count1 + $expected_count2,
|
||||||
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
|
response,
|
||||||
|
tenant_token,
|
||||||
|
key_content
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -433,6 +469,24 @@ macro_rules! compute_forbidden_single_search {
|
|||||||
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
response, tenant_token, key_content
|
response, tenant_token, key_content
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let (mut response, code) = server.multi_search(json!({"federation": {}, "queries" : [{"indexUid": "sales"}]})).await;
|
||||||
|
if failed_query_index.is_none() && !response["message"].is_null() {
|
||||||
|
response["message"] = serde_json::json!(null);
|
||||||
|
}
|
||||||
|
assert_eq!(
|
||||||
|
response,
|
||||||
|
invalid_response(failed_query_index),
|
||||||
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
|
response,
|
||||||
|
tenant_token,
|
||||||
|
key_content
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
code, 403,
|
||||||
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
|
response, tenant_token, key_content
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -494,6 +548,27 @@ macro_rules! compute_forbidden_multiple_search {
|
|||||||
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
response, tenant_token, key_content
|
response, tenant_token, key_content
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let (mut response, code) = server.multi_search(json!({"federation": {}, "queries" : [
|
||||||
|
{"indexUid": "sales"},
|
||||||
|
{"indexUid": "products"},
|
||||||
|
]})).await;
|
||||||
|
if failed_query_index.is_none() && !response["message"].is_null() {
|
||||||
|
response["message"] = serde_json::json!(null);
|
||||||
|
}
|
||||||
|
assert_eq!(
|
||||||
|
response,
|
||||||
|
invalid_response(failed_query_index),
|
||||||
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
|
response,
|
||||||
|
tenant_token,
|
||||||
|
key_content
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
code, 403,
|
||||||
|
"{} using tenant_token: {:?} generated with parent_key: {:?}",
|
||||||
|
response, tenant_token, key_content
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -132,6 +132,79 @@ static NESTED_DOCUMENTS: Lazy<Value> = Lazy::new(|| {
|
|||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static FRUITS_DOCUMENTS: Lazy<Value> = Lazy::new(|| {
|
||||||
|
json!([
|
||||||
|
{
|
||||||
|
"name": "Exclusive sale: green apple",
|
||||||
|
"id": "green-apple-boosted",
|
||||||
|
"BOOST": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Pear",
|
||||||
|
"id": "pear",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Red apple gala",
|
||||||
|
"id": "red-apple-gala",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Exclusive sale: Red Tomato",
|
||||||
|
"id": "red-tomatoes-boosted",
|
||||||
|
"BOOST": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Exclusive sale: Red delicious apple",
|
||||||
|
"id": "red-delicious-boosted",
|
||||||
|
"BOOST": true,
|
||||||
|
}
|
||||||
|
])
|
||||||
|
});
|
||||||
|
|
||||||
|
static VECTOR_DOCUMENTS: Lazy<Value> = Lazy::new(|| {
|
||||||
|
json!([
|
||||||
|
{
|
||||||
|
"id": "A",
|
||||||
|
"description": "the dog barks at the cat",
|
||||||
|
"_vectors": {
|
||||||
|
// dimensions [canine, feline, young]
|
||||||
|
"animal": [0.9, 0.8, 0.05],
|
||||||
|
// dimensions [negative/positive, energy]
|
||||||
|
"sentiment": [-0.1, 0.55]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "B",
|
||||||
|
"description": "the kitten scratched the beagle",
|
||||||
|
"_vectors": {
|
||||||
|
// dimensions [canine, feline, young]
|
||||||
|
"animal": [0.8, 0.9, 0.5],
|
||||||
|
// dimensions [negative/positive, energy]
|
||||||
|
"sentiment": [-0.2, 0.65]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "C",
|
||||||
|
"description": "the dog had to stay alone today",
|
||||||
|
"_vectors": {
|
||||||
|
// dimensions [canine, feline, young]
|
||||||
|
"animal": [0.85, 0.02, 0.1],
|
||||||
|
// dimensions [negative/positive, energy]
|
||||||
|
"sentiment": [-1.0, 0.1]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "D",
|
||||||
|
"description": "the little boy pets the puppy",
|
||||||
|
"_vectors": {
|
||||||
|
// dimensions [canine, feline, young]
|
||||||
|
"animal": [0.8, 0.09, 0.8],
|
||||||
|
// dimensions [negative/positive, energy]
|
||||||
|
"sentiment": [0.8, 0.3]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
])
|
||||||
|
});
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn simple_placeholder_search() {
|
async fn simple_placeholder_search() {
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user