Problem
When running tests, the Algoliax library is making real Algolia API calls instead of using the mock server. This happens because the library is being compiled in production mode (prod) even during test execution.
Current Behavior
- Library sends requests to
https://.algolia.net/1/indexes/... during tests
- Expected to use mock server URLs (
http://localhost:8002/...) in test environment
- Added debug logging shows
Compiling in environment: prod during compilation
Expected Behavior
- Library should compile in test mode when running tests
- Should use mock server URLs in test environment as defined in the
if Mix.env() == :test block
Technical Details
The issue appears to be in the compilation process. The environment check in lib/algoliax/routes.ex is not working as expected:
if Mix.env() == :test do
defp url_read do
port = System.get_env("SLACK_MOCK_API_PORT", "8002")
"http://localhost:#{port}/{{application_id}}/read"
end
# ...
else
defp url_read do
"https://{{application_id}}-dsn.algolia.net/1/indexes"
end
# ...
end
Debug Attempt
I added debug logging in lib/algoliax/routes.ex to verify the compilation environment:
IO.puts("=== Algoliax.Routes Compilation ===")
IO.puts "Compiling in environment: #{Mix.env()}"
IO.puts "Time: #{DateTime.utc_now()}"
The output confirmed the issue:
=== Algoliax.Routes Compilation ===
Compiling in environment: prod
Steps to Reproduce
- Add a test that uses Algoliax
- Run the test
- Observe that requests are being sent to real Algolia endpoints instead of the mock server
Environment
- Elixir version: 1.16.1
- Erlang version: 26.2
- Algoliax version: 0.10.0
Problem
When running tests, the Algoliax library is making real Algolia API calls instead of using the mock server. This happens because the library is being compiled in production mode (
prod) even during test execution.Current Behavior
https://.algolia.net/1/indexes/...during testshttp://localhost:8002/...) in test environmentCompiling in environment: prodduring compilationExpected Behavior
if Mix.env() == :testblockTechnical Details
The issue appears to be in the compilation process. The environment check in
lib/algoliax/routes.exis not working as expected:Debug Attempt
I added debug logging in
lib/algoliax/routes.exto verify the compilation environment:The output confirmed the issue:
Steps to Reproduce
Environment