Skip to content

Commit b8cd598

Browse files
committed
moar tests
1 parent a8154e7 commit b8cd598

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

test/posthog_test.exs

+24
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,30 @@ defmodule PosthogTest do
1515
}}
1616
end
1717

18+
test "when feature flag has a json payload, will return decoded payload" do
19+
stub_with(:hackney, HackneyStub)
20+
21+
assert Posthog.feature_flag("my-awesome-flag-2", "user_123") ==
22+
{:ok,
23+
%Posthog.FeatureFlag{
24+
enabled: true,
25+
name: "my-awesome-flag-2",
26+
value: %{"color" => "blue", "animal" => "hedgehog"}
27+
}}
28+
end
29+
30+
test "when feature flag does not have a payload, will return flag value" do
31+
stub_with(:hackney, HackneyStub)
32+
33+
assert Posthog.feature_flag("flag-thats-not-on", "user_123") ==
34+
{:ok,
35+
%Posthog.FeatureFlag{
36+
enabled: false,
37+
name: "flag-thats-not-on",
38+
value: nil
39+
}}
40+
end
41+
1842
test "when feature flag does not exist, returns not_found" do
1943
stub_with(:hackney, HackneyStub)
2044

test/support/hackney_stub.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule HackneyStub do
22
@fixtures_dir Path.join(__DIR__, "fixtures")
33

4-
def post("https://app.posthog.com/decide?v=3", _headers, _body) do
4+
def post("https://app.posthog.com/decide?v=3", _headers, _body, _opts) do
55
{:ok, 200, json_fixture!("decide.json"), "decide"}
66
end
77

0 commit comments

Comments
 (0)