mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 08:41:00 +00:00
Add tests
This commit is contained in:
@ -424,7 +424,9 @@ InvalidRenderTemplateInline , InvalidRequest , BAD_REQU
|
|||||||
InvalidRenderInput , InvalidRequest , BAD_REQUEST ;
|
InvalidRenderInput , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidRenderInputDocumentId , InvalidRequest , BAD_REQUEST ;
|
InvalidRenderInputDocumentId , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidRenderInputInline , InvalidRequest , BAD_REQUEST ;
|
InvalidRenderInputInline , InvalidRequest , BAD_REQUEST ;
|
||||||
RenderDocumentNotFound , InvalidRequest , NOT_FOUND
|
RenderDocumentNotFound , InvalidRequest , NOT_FOUND ;
|
||||||
|
TemplateParsingError , InvalidRequest , BAD_REQUEST ;
|
||||||
|
TemplateRenderingError , InvalidRequest , BAD_REQUEST
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ErrorCode for JoinError {
|
impl ErrorCode for JoinError {
|
||||||
|
@ -311,11 +311,11 @@ impl From<RenderError> for ResponseError {
|
|||||||
),
|
),
|
||||||
TemplateParsing(err) => ResponseError::from_msg(
|
TemplateParsing(err) => ResponseError::from_msg(
|
||||||
format!("Error parsing template: {}", err.parsing_error("input")),
|
format!("Error parsing template: {}", err.parsing_error("input")),
|
||||||
Code::InvalidRenderTemplate,
|
Code::TemplateParsingError,
|
||||||
),
|
),
|
||||||
TemplateRendering(err) => ResponseError::from_msg(
|
TemplateRendering(err) => ResponseError::from_msg(
|
||||||
format!("Error rendering template: {}", err.rendering_error("input")),
|
format!("Error rendering template: {}", err.rendering_error("input")),
|
||||||
Code::InvalidRenderTemplate,
|
Code::TemplateRenderingError,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,3 +330,80 @@ async fn retrieve_document_template() {
|
|||||||
}
|
}
|
||||||
"#);
|
"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn render_document_kefir() {
|
||||||
|
let index = shared_index_for_fragments().await;
|
||||||
|
|
||||||
|
let (value, code) =
|
||||||
|
index.render(json! {{
|
||||||
|
"template": { "id": "embedders.rest.indexingFragments.basic" },
|
||||||
|
"input": { "documentId": "0" },
|
||||||
|
}}).await;
|
||||||
|
snapshot!(code, @"200 OK");
|
||||||
|
snapshot!(value, @r#"
|
||||||
|
{
|
||||||
|
"template": "{{ doc.name }} is a dog",
|
||||||
|
"rendered": "kefir is a dog"
|
||||||
|
}
|
||||||
|
"#);
|
||||||
|
|
||||||
|
let (value, code) =
|
||||||
|
index.render(json! {{
|
||||||
|
"template": { "id": "embedders.rest.indexingFragments.withBreed" },
|
||||||
|
"input": { "documentId": "0" },
|
||||||
|
}}).await;
|
||||||
|
snapshot!(code, @"400 Bad Request");
|
||||||
|
snapshot!(value, @r#"
|
||||||
|
{
|
||||||
|
"message": "Error rendering template: error while rendering template: liquid: Unknown index\n with:\n variable=doc\n requested index=breed\n available indexes=id, name\n",
|
||||||
|
"code": "template_rendering_error",
|
||||||
|
"type": "invalid_request",
|
||||||
|
"link": "https://docs.meilisearch.com/errors#template_rendering_error"
|
||||||
|
}
|
||||||
|
"#);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn render_inline_document_iko() {
|
||||||
|
let index = shared_index_for_fragments().await;
|
||||||
|
|
||||||
|
let (value, code) =
|
||||||
|
index.render(json! {{
|
||||||
|
"template": { "id": "embedders.rest.indexingFragments.basic" },
|
||||||
|
"input": { "inline": { "doc": { "name": "iko", "breed": "jack russell" } } },
|
||||||
|
}}).await;
|
||||||
|
snapshot!(code, @"200 OK");
|
||||||
|
snapshot!(value, @r#"
|
||||||
|
{
|
||||||
|
"template": "{{ doc.name }} is a dog",
|
||||||
|
"rendered": "iko is a dog"
|
||||||
|
}
|
||||||
|
"#);
|
||||||
|
|
||||||
|
let (value, code) =
|
||||||
|
index.render(json! {{
|
||||||
|
"template": { "id": "embedders.rest.indexingFragments.withBreed" },
|
||||||
|
"input": { "inline": { "doc": { "name": "iko", "breed": "jack russell" } } },
|
||||||
|
}}).await;
|
||||||
|
snapshot!(code, @"200 OK");
|
||||||
|
snapshot!(value, @r#"
|
||||||
|
{
|
||||||
|
"template": "{{ doc.name }} is a {{ doc.breed }}",
|
||||||
|
"rendered": "iko is a jack russell"
|
||||||
|
}
|
||||||
|
"#);
|
||||||
|
|
||||||
|
let (value, code) =
|
||||||
|
index.render(json! {{
|
||||||
|
"template": { "id": "embedders.rest.searchFragments.justBreed" },
|
||||||
|
"input": { "inline": { "media": { "name": "iko", "breed": "jack russell" } } },
|
||||||
|
}}).await;
|
||||||
|
snapshot!(code, @"200 OK");
|
||||||
|
snapshot!(value, @r#"
|
||||||
|
{
|
||||||
|
"template": "It's a {{ media.breed }}",
|
||||||
|
"rendered": "It's a jack russell"
|
||||||
|
}
|
||||||
|
"#);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user