Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .sampo/changesets/cantankerous-forgemaster-louhi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
hex/posthog: patch
---

Default api_host when omitted
6 changes: 3 additions & 3 deletions lib/posthog/config.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule PostHog.Config do
require Logger

@default_api_host "https://us.i.posthog.com"

@shared_schema [
test_mode: [
type: :boolean,
Expand All @@ -12,7 +14,7 @@ defmodule PostHog.Config do
@configuration_schema [
api_host: [
type: :string,
required: true,
default: @default_api_host,
doc:
"`https://us.i.posthog.com` for US cloud or `https://eu.i.posthog.com` for EU cloud"
],
Expand Down Expand Up @@ -108,8 +110,6 @@ defmodule PostHog.Config do
@compiled_configuration_schema NimbleOptions.new!(@configuration_schema)
@compiled_convenience_schema NimbleOptions.new!(@convenience_schema)

@default_api_host "https://us.i.posthog.com"

@system_global_properties %{
"$lib": "posthog-elixir",
"$lib_version": Mix.Project.config()[:version]
Expand Down
17 changes: 17 additions & 0 deletions test/posthog/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ defmodule PostHog.ConfigTest do
assert config.api_host == "https://eu.i.posthog.com"
end

test "validate defaults a missing api_host" do
expect(PostHog.API.Mock, :client, fn api_key, api_host ->
assert api_key == "project_api_key"
assert api_host == "https://us.i.posthog.com"

%PostHog.API.Client{client: :stub_client, module: PostHog.API.Mock}
end)

assert {:ok, config} =
PostHog.Config.validate(
api_key: "project_api_key",
api_client_module: PostHog.API.Mock
)

assert config.api_host == "https://us.i.posthog.com"
end

test "validate defaults a blank api_host after trimming whitespace" do
expect(PostHog.API.Mock, :client, fn api_key, api_host ->
assert api_key == "project_api_key"
Expand Down
Loading