no id returned; fix #492

This commit is contained in:
qdequele 2020-03-04 15:58:36 +01:00 committed by Quentin de Quelen
parent 54c675e195
commit 041eed2a06
2 changed files with 42 additions and 3 deletions

View File

@ -1,4 +1,5 @@
use serde_json::json;
use assert_json_diff::assert_json_eq;
mod common;
@ -467,3 +468,33 @@ fn create_index_failed() {
assert_eq!(res_value.as_object().unwrap().len(), 1);
assert_eq!(message, "invalid data");
}
#[test]
fn create_index_with_identifier() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"identifier": "id",
});
let (_response, status_code) = server.create_index(body);
assert_eq!(status_code, 201);
let body = json!([{
"id": 123,
"text": "The mask"
}]);
server.add_or_replace_multiple_documents(body.clone());
let (response, _status_code) = server.get_document(123);
let expect = json!({
"id": 123,
"text": "The mask"
});
assert_json_eq!(response, expect, ordered: false);
}

View File

@ -21,13 +21,21 @@ impl Schema {
let mut fields_map = FieldsMap::default();
let field_id = fields_map.insert(name).unwrap();
let mut displayed = HashSet::new();
let mut indexed = Vec::new();
let mut indexed_map = HashMap::new();
displayed.insert(field_id);
indexed.push(field_id);
indexed_map.insert(field_id, 0.into());
Schema {
fields_map,
identifier: field_id,
ranked: HashSet::new(),
displayed: HashSet::new(),
indexed: Vec::new(),
indexed_map: HashMap::new(),
displayed,
indexed,
indexed_map,
accept_new_fields: true,
}
}