@@ -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