towerops/test/towerops/query_helpers_test.exs
Graham McIntire 0c8bb35ef7 add query_helpers tests and fix all credo issues (#56)
- add tests for QueryHelpers.sanitize_like/1 (%, _, \ escaping)
- fix nesting depth in store_check_result, handle_check_state_change,
  graphql check resolver, checks controller, and ping executor
- fix cyclomatic complexity in build_check_protobuf by extracting
  check_type_config/2 function clauses
- fix formatting in api_docs_html template

Reviewed-on: graham/towerops-web#56
2026-03-17 10:43:57 -05:00

31 lines
888 B
Elixir

defmodule Towerops.QueryHelpersTest do
use ExUnit.Case, async: true
alias Towerops.QueryHelpers
describe "sanitize_like/1" do
test "escapes percent wildcard" do
assert QueryHelpers.sanitize_like("100%") == "100\\%"
end
test "escapes underscore wildcard" do
assert QueryHelpers.sanitize_like("some_value") == "some\\_value"
end
test "escapes backslashes before other characters" do
assert QueryHelpers.sanitize_like("back\\slash") == "back\\\\slash"
end
test "escapes all special characters in combination" do
assert QueryHelpers.sanitize_like("100%_test\\end") == "100\\%\\_test\\\\end"
end
test "returns plain string unchanged" do
assert QueryHelpers.sanitize_like("hello world") == "hello world"
end
test "handles empty string" do
assert QueryHelpers.sanitize_like("") == ""
end
end
end