Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add search answer lookup test (wip) #2077

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions caluma/caluma_form/tests/test_search_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,49 @@ def _search(q_slugs, f_slugs, word, expect_count):
assert extract_global_id(edges[0]["node"]["id"]) == str(doc_c.id)


@pytest.mark.parametrize(
"answer_value,search_text,lookup,expect_count",
[
# ("foo", "foo", "EXACT_WORD", 1),
# ("foo", "fo", "EXACT_WORD", 0),
# ("foo", "oo", "CONTAINS", 1),
# ("foo", "bar", "CONTAINS", 1),
("foo", '"fo', "STARTSWITH", 1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it works now, but it's wrong. I think we'll need something like KeyTextTransform in the filter to correctly extract it. See the JSONValueFilter.filter() method to see an application of it

# ("foo", "oo", "STARTSWITH", 0),
],
)
def test_search_lookups(
schema_executor, db, answer_factory, answer_value, search_text, lookup, expect_count
):
answer = answer_factory(value=answer_value)

query = """
query ($search: [SearchAnswersFilterType!]) {
allDocuments(filter: [{searchAnswers: $search}]) {
edges {
node {
id
}
}
}
}
"""
variables = {
"search": [
{
"questions": [answer.question.slug],
"value": search_text,
"lookup": lookup,
}
]
}
result = schema_executor(query, variable_values=variables)

assert not result.errors
edges = result.data["allDocuments"]["edges"]
assert len(edges) == expect_count


@pytest.mark.parametrize(
"question_type, search_text",
[
Expand Down
Loading