jaeyson / ex_typesense

Typesense client for Elixir with support for importing your Ecto schemas.
https://hexdocs.pm/ex_typesense
MIT License
29 stars 11 forks source link

ExTypesense.Connection.new doesn't work with MIX_ENV=test #26

Closed rodesousa closed 3 months ago

rodesousa commented 3 months ago

elixir version: 1.15.4 ex_typesense version: 0.4

I configure ex typesense into runtime.exs. But when I run test all of data from ExTypesense.Connection.new is nil I put the configuration into test.exs but no effect

Screenshot from 2024-06-24 15-29-49 Screenshot from 2024-06-24 15-30-25

jaeyson commented 3 months ago

Hi @rodesousa :wave:

I missed that part. Thanks for letting me know!

jaeyson commented 3 months ago

@rodesousa kindly check this PR #30. Let me know if this fixes your issue.

Problem

Setting the credentials dynamically won't work since the Connection module by default is a struct (hence, compile time).

This also affects the test files of the library, since it relies on explicit connection string. Leaving it blank will throw an error.

To reproduce:

  1. open shell in test env: MIX_ENV=test iex -S mix
  2. put env in application:
    Application.put_all_env(
    ex_typesense: [
    api_key: "xyz",
    host: "localhost",
    port: 8108,
    scheme: "http"
    ]
    )
  3. run ExTypesense.Connection.new
  4. The Connection struct field values returns nil.

Workaround

Since the problem came from making the connection a struct, it defeats the purpose of making it dynamic (runtime). So we have to change it from struct to map.

rodesousa commented 3 months ago

@jaeyson It works ! :)