Skip to content

Commit 26a7503

Browse files
Merge pull request #15 from Flagsmith/release/1.0.1
Release 1.0.1
2 parents 932a59a + b342d7c commit 26a7503

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

.github/workflows/test_format_dialyze.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [ main ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ main, release/** ]
88

99
jobs:
1010
build:

lib/flagsmith_client_analytics_processor.ex

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ defmodule Flagsmith.Client.Analytics.Processor do
2828
#################################
2929

3030
@doc """
31-
Given a `t:Flagsmith.Schemas.Features.FeatureState.t/0` or
31+
Given a `t:Flagsmith.Schemas.Features.FeatureState.t/0` or
3232
`t:Flagsmith.Schemas.Features.Feature.t/0` or `t:Flagsmith.Schemas.Flag.t/0` and an
3333
`t:Flagsmith.Schemas.Environment.t/0` or `t:Flagsmith.Configuration.t/0` add or
34-
increment the call count for feature id to be reported to the analytics endpoint.
34+
increment the call count for feature name to be reported to the analytics endpoint.
3535
If `:enable_analytics` in the configuration value of the environment isn't true
3636
it's a no op and returns (:noop), otherwise if the feature/flag doesn't have an
3737
id it returns an error.
@@ -55,7 +55,7 @@ defmodule Flagsmith.Client.Analytics.Processor do
5555
to_track,
5656
%Configuration{enable_analytics: true} = config
5757
) do
58-
case extract_feature_id(to_track) do
58+
case extract_feature_name(to_track) do
5959
id when is_binary(id) or is_integer(id) ->
6060
do_track(id, config)
6161

@@ -66,11 +66,11 @@ defmodule Flagsmith.Client.Analytics.Processor do
6666

6767
def track(_, _), do: :noop
6868

69-
defp extract_feature_id(feature) do
69+
defp extract_feature_name(feature) do
7070
case feature do
71-
%Schemas.Features.FeatureState{feature: %{id: id}} -> id
72-
%Schemas.Features.Feature{id: id} -> id
73-
%Schemas.Flag{feature_id: id} -> id
71+
%Schemas.Features.FeatureState{feature: %{name: name}} -> name
72+
%Schemas.Features.Feature{name: name} -> name
73+
%Schemas.Flag{feature_name: name} -> name
7474
_ -> :invalid_feature
7575
end
7676
end
@@ -111,7 +111,7 @@ defmodule Flagsmith.Client.Analytics.Processor do
111111
end
112112

113113
@doc """
114-
Starts and links a gen_server represented by this module, using a
114+
Starts and links a gen_server represented by this module, using a
115115
`t:Flagsmith.Configuration.t/0` as the basis to derive its registration name and
116116
inner details.
117117
"""
@@ -133,7 +133,7 @@ defmodule Flagsmith.Client.Analytics.Processor do
133133
end
134134

135135
#################################
136-
########### Statem Implementation / Internal
136+
########### Statem Implementation / Internal
137137
#################################
138138

139139
@doc false
@@ -200,10 +200,10 @@ defmodule Flagsmith.Client.Analytics.Processor do
200200
def handle_event({:timeout, :dump}, nil, _, _data),
201201
do: {:keep_state_and_data, [{:next_event, :internal, :dump}]}
202202

203-
# a cast for tracking a feature_id simply sets or updates that feature id track
203+
# a cast for tracking a feature_name simply sets or updates that feature name track
204204
# in the tracking map
205-
def handle_event(:cast, {:track, feature_id}, _, %{tracking: tracking} = data) do
206-
new_tracking = Map.update(tracking, feature_id, 1, &(&1 + 1))
205+
def handle_event(:cast, {:track, feature_name}, _, %{tracking: tracking} = data) do
206+
new_tracking = Map.update(tracking, feature_name, 1, &(&1 + 1))
207207
{:keep_state, %{data | tracking: new_tracking}, []}
208208
end
209209

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ defmodule FlagsmithEngine.MixProject do
44
def project do
55
[
66
app: :flagsmith_engine,
7-
version: "1.0.0",
7+
version: "1.0.1",
88
elixir: "~> 1.12",
99
start_permanent: Mix.env() == :prod,
1010
deps: deps(),
1111
elixirc_paths: elixirc_paths(Mix.env()),
12-
# DIALYZER
12+
# DIALYZER
1313
dialyzer: [
1414
plt_file: {:no_warn, "priv/plts/#{Mix.env()}/dialyzer.plt"}
1515
],

test/flagsmith_analytics_processor_test.exs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Flagsmith.Client.Analytics.Processor.Test do
1111
@api_url Flagsmith.Configuration.default_url()
1212
@api_paths Flagsmith.Configuration.api_paths()
1313

14-
# setup Mox to verify any expectations
14+
# setup Mox to verify any expectations
1515
setup :verify_on_exit!
1616

1717
# we start the supervisor as a supervised process so it's shut down on every test
@@ -77,7 +77,7 @@ defmodule Flagsmith.Client.Analytics.Processor.Test do
7777
:ok
7878
end
7979

80-
test "dosn't start if enable_analytics is false", %{config: config} do
80+
test "doesn't start if enable_analytics is false", %{config: config} do
8181
config = %{config | enable_analytics: false}
8282
{:ok, environment} = Flagsmith.Client.get_environment(config)
8383

@@ -105,21 +105,21 @@ defmodule Flagsmith.Client.Analytics.Processor.Test do
105105
{:ok, environment} = Flagsmith.Client.get_environment(config)
106106

107107
# get a flag from that environment
108-
assert %Schemas.Flag{feature_id: id, enabled: true} =
109-
Flagsmith.Client.get_flag(environment, "secret_button")
108+
feature_name_1 = "secret_button"
109+
assert %Schemas.Flag{enabled: true} = Flagsmith.Client.get_flag(environment, feature_name_1)
110110

111111
# assert that now there's a processor for the environment key we've been using
112112
pid = Flagsmith.Client.Analytics.Processor.whereis("test_key")
113113
assert is_pid(pid)
114114

115115
# assert it's tracking correctly:
116-
# - the tracking map should have 1 key being the id of the flag we retrieved
116+
# - the tracking map should have 1 key being the name of the flag we retrieved
117117
# with the value being 1
118118
assert {:on,
119119
%Flagsmith.Client.Analytics.Processor{
120120
configuration: ^config,
121121
dump: 60_000,
122-
tracking: %{^id => 1} = tracking_map_1
122+
tracking: %{^feature_name_1 => 1} = tracking_map_1
123123
}} = :sys.get_state(pid)
124124

125125
# assert there's only 1 key on the tracking map
@@ -129,32 +129,34 @@ defmodule Flagsmith.Client.Analytics.Processor.Test do
129129
assert Flagsmith.Client.is_feature_enabled(environment, "secret_button")
130130

131131
# assert that the processor is still alive and that now the tracking for
132-
# that feature id is at 2
132+
# that feature name is at 2
133133
assert {:on,
134134
%Flagsmith.Client.Analytics.Processor{
135135
configuration: ^config,
136136
dump: 60_000,
137-
tracking: %{^id => 2} = tracking_map_2
137+
tracking: %{^feature_name_1 => 2} = tracking_map_2
138138
}} = :sys.get_state(pid)
139139

140140
# assert there's still only 1 key on the tracking map
141141
assert map_size(tracking_map_2) == 1
142142

143143
# assert other features track correctly too
144144
# get another flag from that environment
145-
assert %Schemas.Flag{feature_id: id_2, enabled: false} =
146-
Flagsmith.Client.get_flag(environment, "header_size")
145+
feature_name_2 = "header_size"
146+
147+
assert %Schemas.Flag{enabled: false} =
148+
Flagsmith.Client.get_flag(environment, feature_name_2)
147149

148-
refute Flagsmith.Client.is_feature_enabled(environment, "header_size")
150+
refute Flagsmith.Client.is_feature_enabled(environment, feature_name_2)
149151

150152
# assert that the processor is still alive and that now the tracking for
151-
# the previous feature id is still at 2, and for the new one, id_2, is at
153+
# the previous feature is still at 2, and for the new one, is at
152154
# 2 too
153155
assert {:on,
154156
%Flagsmith.Client.Analytics.Processor{
155157
configuration: ^config,
156158
dump: 60_000,
157-
tracking: %{^id => 2, ^id_2 => 2} = tracking_map_3
159+
tracking: %{^feature_name_1 => 2, ^feature_name_2 => 2} = tracking_map_3
158160
}} = :sys.get_state(pid)
159161

160162
# assert there's now 2 keys on the tracking map
@@ -172,13 +174,16 @@ defmodule Flagsmith.Client.Analytics.Processor.Test do
172174
# change the dump timeout
173175
assert :ok = :gen_statem.call(pid, {:update_dump_rate, 1})
174176

177+
# use an example feature name that we know exists
178+
feature_name = "secret_button"
179+
175180
# we need to set an additional expectation since it will call the analytics
176181
# endpoint
177182

178183
expect(Tesla.Adapter.Mock, :call, fn tesla_env, _options ->
179184
assert_request(
180185
tesla_env,
181-
body: "{\"17985\":1}",
186+
body: "{\"#{feature_name}\":1}",
182187
query: [],
183188
headers: [{@environment_header, "test_key"}],
184189
url: Path.join([@api_url, @api_paths.analytics]) <> "/",
@@ -196,7 +201,7 @@ defmodule Flagsmith.Client.Analytics.Processor.Test do
196201
# attempts to dump, meaning this inadvertently tests that after a dump the
197202
# tracking map is effectively empty
198203

199-
assert Flagsmith.Client.is_feature_enabled(environment, "secret_button")
204+
assert Flagsmith.Client.is_feature_enabled(environment, feature_name)
200205

201206
assert Flagsmith.Test.Helpers.wait_until(
202207
fn ->

0 commit comments

Comments
 (0)