Skip to content
Closed
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
19 changes: 19 additions & 0 deletions lib/posthog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ defmodule PostHog do
@spec config(supervisor_name()) :: PostHog.Config.config()
def config(name \\ __MODULE__), do: PostHog.Registry.config(name)

@doc """
Returns whether a named `PostHog` supervisor is enabled.

A supervisor is disabled when it was started without a configured API key. In
disabled mode, capture calls become no-ops.

## Examples

Check the default `PostHog` instance:

PostHog.enabled?()

Check a named instance:

PostHog.enabled?(MyPostHog)
"""
@spec enabled?(supervisor_name()) :: boolean()
def enabled?(name \\ __MODULE__), do: config(name).enabled

@doc false
def bare_capture(event, distinct_id, %{} = properties),
do: bare_capture(__MODULE__, event, distinct_id, properties)
Expand Down
11 changes: 11 additions & 0 deletions test/posthog_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ defmodule PostHogTest do
end
end

describe "enabled?/1" do
test "returns true when the PostHog instance has an API key" do
assert PostHog.enabled?()
end

@tag config: [api_key: "", supervisor_name: DisabledPostHog]
test "returns false when the PostHog instance has no API key" do
refute PostHog.enabled?(DisabledPostHog)
end
end
Comment on lines +24 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Prefer parameterised tests

The two tests inside enabled?/1 exercise the same function with different inputs (enabled with a key, disabled without), making them a natural fit for parameterisation. The current split into separate tests with different @tag config: annotations duplicates the structural boilerplate. A single table-driven loop over {config, supervisor_name, expected} tuples would express the same idea more concisely and satisfy the project's "OnceAndOnlyOnce" guideline.

Context Used: Do not attempt to comment on incorrect alphabetica... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: test/posthog_test.exs
Line: 24-33

Comment:
**Prefer parameterised tests**

The two tests inside `enabled?/1` exercise the same function with different inputs (enabled with a key, disabled without), making them a natural fit for parameterisation. The current split into separate tests with different `@tag config:` annotations duplicates the structural boilerplate. A single table-driven loop over `{config, supervisor_name, expected}` tuples would express the same idea more concisely and satisfy the project's "OnceAndOnlyOnce" guideline.

**Context Used:** Do not attempt to comment on incorrect alphabetica... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


describe "bare_capture/4" do
test "simple call" do
PostHog.bare_capture("case tested", "distinct_id")
Expand Down
Loading