-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
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: prodduring 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() == :testblock
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
# ...
endDebug 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
Metadata
Metadata
Assignees
Labels
No labels