2020-01-18 19:00:41 +01:00
|
|
|
use std::convert::Into;
|
2020-01-23 11:30:18 +01:00
|
|
|
use std::time::Duration;
|
2020-01-18 19:00:41 +01:00
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
use assert_json_diff::assert_json_eq;
|
2020-01-18 19:00:41 +01:00
|
|
|
use async_std::io::prelude::*;
|
2020-01-23 11:30:18 +01:00
|
|
|
use async_std::task::{block_on, sleep};
|
2020-01-18 19:00:41 +01:00
|
|
|
use http_service::Body;
|
|
|
|
use serde_json::json;
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
2020-01-22 14:30:09 +01:00
|
|
|
// Process:
|
|
|
|
// - Write a full settings update
|
|
|
|
// - Delete all settings
|
|
|
|
// Check:
|
|
|
|
// - Settings are deleted, all fields are null
|
|
|
|
// - POST success repond Status Code 202
|
|
|
|
// - Get success repond Status Code 200
|
|
|
|
// - Delete success repond Status Code 202
|
2020-01-18 19:00:41 +01:00
|
|
|
#[test]
|
2020-01-20 09:52:24 +01:00
|
|
|
fn write_all_and_delete() {
|
2020-01-18 19:00:41 +01:00
|
|
|
let mut server = common::setup_server().unwrap();
|
|
|
|
|
|
|
|
// 1 - Create the index
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
2020-01-23 11:30:18 +01:00
|
|
|
})
|
|
|
|
.to_string()
|
|
|
|
.into_bytes();
|
2020-01-18 19:00:41 +01:00
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::post("/indexes")
|
|
|
|
.body(Body::from(body))
|
|
|
|
.unwrap();
|
2020-01-18 19:00:41 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 201);
|
|
|
|
|
|
|
|
// 2 - Send the settings
|
|
|
|
|
|
|
|
let json = json!({
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingRules": [
|
2020-01-18 19:00:41 +01:00
|
|
|
"_typo",
|
|
|
|
"_words",
|
|
|
|
"_proximity",
|
|
|
|
"_attribute",
|
|
|
|
"_words_position",
|
|
|
|
"_exact",
|
|
|
|
"dsc(release_date)",
|
|
|
|
"dsc(rank)",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingDistinct": "movie_id",
|
|
|
|
"attributeIdentifier": "uid",
|
|
|
|
"attributesSearchable": [
|
2020-01-18 19:00:41 +01:00
|
|
|
"uid",
|
|
|
|
"movie_id",
|
|
|
|
"title",
|
|
|
|
"description",
|
|
|
|
"poster",
|
|
|
|
"release_date",
|
|
|
|
"rank",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"attributesDisplayed": [
|
2020-01-18 19:00:41 +01:00
|
|
|
"title",
|
|
|
|
"description",
|
|
|
|
"poster",
|
|
|
|
"release_date",
|
|
|
|
"rank",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"stopWords": [
|
2020-01-18 19:00:41 +01:00
|
|
|
"the",
|
|
|
|
"a",
|
|
|
|
"an",
|
|
|
|
],
|
|
|
|
"synonyms": {
|
|
|
|
"wolverine": ["xmen", "logan"],
|
|
|
|
"logan": ["wolverine"],
|
2020-01-27 18:27:42 +01:00
|
|
|
},
|
|
|
|
"indexNewFields": false,
|
2020-01-18 19:00:41 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
let body = json.to_string().into_bytes();
|
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::post("/indexes/movies/settings")
|
|
|
|
.body(Body::from(body))
|
|
|
|
.unwrap();
|
2020-01-18 19:00:41 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 202);
|
|
|
|
|
|
|
|
block_on(sleep(Duration::from_secs(1)));
|
|
|
|
|
2020-01-18 19:30:25 +01:00
|
|
|
// 3 - Get all settings and compare to the previous one
|
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::get("/indexes/movies/settings")
|
|
|
|
.body(Body::empty())
|
|
|
|
.unwrap();
|
2020-01-18 19:30:25 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 200);
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
|
|
|
|
let res_value: Value = serde_json::from_slice(&buf).unwrap();
|
|
|
|
|
|
|
|
assert_json_eq!(json, res_value, ordered: false);
|
|
|
|
|
|
|
|
// 4 - Delete all settings
|
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::delete("/indexes/movies/settings")
|
|
|
|
.body(Body::empty())
|
|
|
|
.unwrap();
|
2020-01-18 19:30:25 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 202);
|
|
|
|
|
2020-01-22 14:30:09 +01:00
|
|
|
block_on(sleep(Duration::from_secs(2)));
|
2020-01-18 19:30:25 +01:00
|
|
|
|
|
|
|
// 5 - Get all settings and check if they are empty
|
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::get("/indexes/movies/settings")
|
|
|
|
.body(Body::empty())
|
|
|
|
.unwrap();
|
2020-01-18 19:00:41 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 200);
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
|
|
|
|
let res_value: Value = serde_json::from_slice(&buf).unwrap();
|
|
|
|
|
2020-01-18 19:30:25 +01:00
|
|
|
let json = json!({
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingRules": null,
|
|
|
|
"rankingDistinct": null,
|
|
|
|
"attributeIdentifier": null,
|
|
|
|
"attributesSearchable": null,
|
|
|
|
"attributesDisplayed": null,
|
|
|
|
"stopWords": null,
|
2020-01-18 19:30:25 +01:00
|
|
|
"synonyms": null,
|
2020-01-27 18:27:42 +01:00
|
|
|
"indexNewFields": null,
|
2020-01-18 19:30:25 +01:00
|
|
|
});
|
2020-01-18 19:00:41 +01:00
|
|
|
|
|
|
|
assert_json_eq!(json, res_value, ordered: false);
|
|
|
|
}
|
2020-01-20 09:52:24 +01:00
|
|
|
|
2020-01-22 14:30:09 +01:00
|
|
|
// Process:
|
|
|
|
// - Write a full setting update
|
|
|
|
// - Rewrite an other settings confirmation
|
|
|
|
// Check:
|
|
|
|
// - Settings are overwrited
|
|
|
|
// - Forgotten attributes are deleted
|
|
|
|
// - Null attributes are deleted
|
|
|
|
// - Empty attribute are deleted
|
2020-01-20 09:52:24 +01:00
|
|
|
#[test]
|
|
|
|
fn write_all_and_update() {
|
|
|
|
let mut server = common::setup_server().unwrap();
|
|
|
|
|
|
|
|
// 1 - Create the index
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
2020-01-23 11:30:18 +01:00
|
|
|
})
|
|
|
|
.to_string()
|
|
|
|
.into_bytes();
|
2020-01-20 09:52:24 +01:00
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::post("/indexes")
|
|
|
|
.body(Body::from(body))
|
|
|
|
.unwrap();
|
2020-01-20 09:52:24 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 201);
|
|
|
|
|
|
|
|
// 2 - Send the settings
|
|
|
|
|
|
|
|
let json = json!({
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingRules": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"_typo",
|
|
|
|
"_words",
|
|
|
|
"_proximity",
|
|
|
|
"_attribute",
|
|
|
|
"_words_position",
|
|
|
|
"_exact",
|
|
|
|
"dsc(release_date)",
|
|
|
|
"dsc(rank)",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingDistinct": "movie_id",
|
|
|
|
"attributeIdentifier": "uid",
|
|
|
|
"attributesSearchable": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"uid",
|
|
|
|
"movie_id",
|
|
|
|
"title",
|
|
|
|
"description",
|
|
|
|
"poster",
|
|
|
|
"release_date",
|
|
|
|
"rank",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"attributesDisplayed": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"title",
|
|
|
|
"description",
|
|
|
|
"poster",
|
|
|
|
"release_date",
|
|
|
|
"rank",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"stopWords": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"the",
|
|
|
|
"a",
|
|
|
|
"an",
|
|
|
|
],
|
|
|
|
"synonyms": {
|
|
|
|
"wolverine": ["xmen", "logan"],
|
|
|
|
"logan": ["wolverine"],
|
2020-01-27 18:27:42 +01:00
|
|
|
},
|
|
|
|
"indexNewFields": false,
|
2020-01-20 09:52:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
let body = json.to_string().into_bytes();
|
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::post("/indexes/movies/settings")
|
|
|
|
.body(Body::from(body))
|
|
|
|
.unwrap();
|
2020-01-20 09:52:24 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 202);
|
|
|
|
|
|
|
|
block_on(sleep(Duration::from_secs(1)));
|
|
|
|
|
|
|
|
// 3 - Get all settings and compare to the previous one
|
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::get("/indexes/movies/settings")
|
|
|
|
.body(Body::empty())
|
|
|
|
.unwrap();
|
2020-01-20 09:52:24 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 200);
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
|
|
|
|
let res_value: Value = serde_json::from_slice(&buf).unwrap();
|
|
|
|
|
|
|
|
assert_json_eq!(json, res_value, ordered: false);
|
|
|
|
|
|
|
|
// 4 - Update all settings
|
|
|
|
|
|
|
|
let json_update = json!({
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingRules": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"_typo",
|
|
|
|
"_words",
|
|
|
|
"_proximity",
|
|
|
|
"_attribute",
|
|
|
|
"_words_position",
|
|
|
|
"_exact",
|
|
|
|
"dsc(release_date)",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"attributeIdentifier": "uid",
|
|
|
|
"attributesSearchable": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"title",
|
|
|
|
"description",
|
|
|
|
"uid",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"attributesDisplayed": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"title",
|
|
|
|
"description",
|
|
|
|
"release_date",
|
|
|
|
"rank",
|
|
|
|
"poster",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"stopWords": [
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
|
|
|
"synonyms": {
|
|
|
|
"wolverine": ["xmen", "logan"],
|
|
|
|
"logan": ["wolverine", "xmen"],
|
2020-01-27 18:27:42 +01:00
|
|
|
},
|
|
|
|
"indexNewFields": false,
|
2020-01-20 09:52:24 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
let body_update = json_update.to_string().into_bytes();
|
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::post("/indexes/movies/settings")
|
|
|
|
.body(Body::from(body_update))
|
|
|
|
.unwrap();
|
2020-01-20 09:52:24 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 202);
|
|
|
|
|
|
|
|
block_on(sleep(Duration::from_secs(1)));
|
|
|
|
|
|
|
|
// 5 - Get all settings and check if the content is the same of (4)
|
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::get("/indexes/movies/settings")
|
|
|
|
.body(Body::empty())
|
|
|
|
.unwrap();
|
2020-01-20 09:52:24 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 200);
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
|
|
|
|
let res_value: Value = serde_json::from_slice(&buf).unwrap();
|
|
|
|
|
|
|
|
let res_expected = json!({
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingRules": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"_typo",
|
|
|
|
"_words",
|
|
|
|
"_proximity",
|
|
|
|
"_attribute",
|
|
|
|
"_words_position",
|
|
|
|
"_exact",
|
|
|
|
"dsc(release_date)",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingDistinct": null,
|
|
|
|
"attributeIdentifier": "uid",
|
|
|
|
"attributesSearchable": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"title",
|
|
|
|
"description",
|
|
|
|
"uid",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"attributesDisplayed": [
|
2020-01-20 09:52:24 +01:00
|
|
|
"title",
|
|
|
|
"description",
|
|
|
|
"release_date",
|
|
|
|
"rank",
|
|
|
|
"poster",
|
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"stopWords": null,
|
2020-01-20 09:52:24 +01:00
|
|
|
"synonyms": {
|
|
|
|
"wolverine": ["xmen", "logan"],
|
|
|
|
"logan": ["wolverine", "xmen"],
|
2020-01-27 08:52:36 +01:00
|
|
|
},
|
2020-01-27 18:27:42 +01:00
|
|
|
"indexNewFields": false
|
2020-01-20 09:52:24 +01:00
|
|
|
});
|
|
|
|
|
2020-01-21 12:03:48 +01:00
|
|
|
assert_json_eq!(res_expected, res_value, ordered: false);
|
2020-01-20 09:52:24 +01:00
|
|
|
}
|