@@ -4,7 +4,6 @@ defmodule PlausibleWeb.Live.ChangeDomainV2Test do
44
55 import Phoenix.LiveViewTest
66 import Plausible.TestUtils
7- import ExUnit.CaptureLog
87 import Plausible.Test.Support.HTML
98
109 on_ee do
@@ -88,7 +87,7 @@ defmodule PlausibleWeb.Live.ChangeDomainV2Test do
8887 end
8988
9089 original_domain = site . domain
91- new_domain = "new-example.com "
90+ new_domain = "new. #{ site . domain } "
9291 { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
9392
9493 lv
@@ -111,14 +110,14 @@ defmodule PlausibleWeb.Live.ChangeDomainV2Test do
111110 end
112111
113112 original_domain = site . domain
114- new_domain = "new-example.com "
113+ new_domain = "new. #{ site . domain } "
115114 { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
116115
117116 lv
118117 |> element ( "form" )
119118 |> render_submit ( % { site: % { domain: new_domain } } )
120119
121- assert_patch ( lv , "/#{ new_domain } /change-domain-v2/success" )
120+ assert_patch ( lv , "/#{ URI . encode_www_form ( new_domain ) } /change-domain-v2/success" )
122121
123122 html = render_async ( lv , 500 )
124123 assert html =~ "Domain Changed Successfully"
@@ -164,14 +163,14 @@ defmodule PlausibleWeb.Live.ChangeDomainV2Test do
164163 "wordpressPlugin" => true
165164 } )
166165
167- new_domain = "new-example.com "
166+ new_domain = "new. #{ site . domain } "
168167 { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
169168
170169 lv
171170 |> element ( "form" )
172171 |> render_submit ( % { site: % { domain: new_domain } } )
173172
174- assert_patch ( lv , "/#{ new_domain } /change-domain-v2/success" )
173+ assert_patch ( lv , "/#{ URI . encode_www_form ( new_domain ) } /change-domain-v2/success" )
175174
176175 html = render_async ( lv , 500 )
177176 assert html =~ "<i>must</i>"
@@ -197,14 +196,14 @@ defmodule PlausibleWeb.Live.ChangeDomainV2Test do
197196 "wordpressPlugin" => false
198197 } )
199198
200- new_domain = "new-example.com "
199+ new_domain = "new. #{ site . domain } "
201200 { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
202201
203202 lv
204203 |> element ( "form" )
205204 |> render_submit ( % { site: % { domain: new_domain } } )
206205
207- assert_patch ( lv , "/#{ new_domain } /change-domain-v2/success" )
206+ assert_patch ( lv , "/#{ URI . encode_www_form ( new_domain ) } /change-domain-v2/success" )
208207
209208 html = render_async ( lv , 500 )
210209 assert html =~ "<i>must</i>"
@@ -228,14 +227,14 @@ defmodule PlausibleWeb.Live.ChangeDomainV2Test do
228227 "wordpressPlugin" => false
229228 } )
230229
231- new_domain = "new-example.com "
230+ new_domain = "new. #{ site . domain } "
232231 { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
233232
234233 lv
235234 |> element ( "form" )
236235 |> render_submit ( % { site: % { domain: new_domain } } )
237236
238- assert_patch ( lv , "/#{ new_domain } /change-domain-v2/success" )
237+ assert_patch ( lv , "/#{ URI . encode_www_form ( new_domain ) } /change-domain-v2/success" )
239238
240239 html = render_async ( lv , 500 )
241240 refute html =~ "Additional Steps Required"
@@ -258,14 +257,14 @@ defmodule PlausibleWeb.Live.ChangeDomainV2Test do
258257 "wordpressPlugin" => false
259258 } )
260259
261- new_domain = "new-example.com "
260+ new_domain = "new. #{ site . domain } "
262261 { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
263262
264263 lv
265264 |> element ( "form" )
266265 |> render_submit ( % { site: % { domain: new_domain } } )
267266
268- assert_patch ( lv , "/#{ new_domain } /change-domain-v2/success" )
267+ assert_patch ( lv , "/#{ URI . encode_www_form ( new_domain ) } /change-domain-v2/success" )
269268
270269 html = render_async ( lv , 500 )
271270 assert html =~ "<i>must</i>"
@@ -279,41 +278,78 @@ defmodule PlausibleWeb.Live.ChangeDomainV2Test do
279278 )
280279 end
281280
282- @ tag :ee_only
281+ @ tag ee_only: true , capture_log: true
282+ test "ratelimit is respected: browserless request isn't made and the notice is generic" , % {
283+ conn: conn ,
284+ site: site
285+ } do
286+ new_domain = "new.#{ site . domain } "
287+
288+ # exceed the rate limit for site detection
289+ Plausible.RateLimit . check_rate (
290+ Plausible.RateLimit ,
291+ "site_detection:#{ new_domain } " ,
292+ :timer . minutes ( 60 ) ,
293+ 1 ,
294+ 100
295+ )
296+
297+ # stub won't be used, if it were used, the output would be different
298+ stub_detection_result ( % {
299+ "v1Detected" => false ,
300+ "gtmLikely" => false ,
301+ "wordpressLikely" => false ,
302+ "wordpressPlugin" => false
303+ } )
304+
305+ { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
306+
307+ lv
308+ |> element ( "form" )
309+ |> render_submit ( % { site: % { domain: new_domain } } )
310+
311+ assert_patch ( lv , "/#{ URI . encode_www_form ( new_domain ) } /change-domain-v2/success" )
312+
313+ html = render_async ( lv , 500 )
314+ assert html =~ "Additional Steps Required"
315+ assert html =~ "<i>must</i>"
316+ assert html =~ "also update the site"
317+ assert html =~ "Plausible Installation"
318+ end
319+
320+ @ tag ee_only: true , capture_log: true
283321 test "success page handles detection error gracefully" , % { conn: conn , site: site } do
284322 stub_detection_error ( )
285323
286- capture_log ( fn ->
287- new_domain = "new-example.com"
288- { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
324+ new_domain = "new.#{ site . domain } "
325+ { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
289326
290- lv
291- |> element ( "form" )
292- |> render_submit ( % { site: % { domain: new_domain } } )
327+ lv
328+ |> element ( "form" )
329+ |> render_submit ( % { site: % { domain: new_domain } } )
293330
294- assert_patch ( lv , "/#{ new_domain } /change-domain-v2/success" )
331+ assert_patch ( lv , "/#{ URI . encode_www_form ( new_domain ) } /change-domain-v2/success" )
295332
296- html = render_async ( lv , 500 )
297- assert html =~ "Additional Steps Required"
298- assert html =~ "<i>must</i>"
299- assert html =~ "also update the site"
300- assert html =~ "Plausible Installation"
301- end )
333+ html = render_async ( lv , 500 )
334+ assert html =~ "Additional Steps Required"
335+ assert html =~ "<i>must</i>"
336+ assert html =~ "also update the site"
337+ assert html =~ "Plausible Installation"
302338 end
303339
304340 @ tag :ce_build_only
305341 test "success page shows generic v1 notice for CE" , % {
306342 conn: conn ,
307343 site: site
308344 } do
309- new_domain = "new-example.com "
345+ new_domain = "new. #{ site . domain } "
310346 { :ok , lv , _html } = live ( conn , "/#{ site . domain } /change-domain-v2" )
311347
312348 lv
313349 |> element ( "form" )
314350 |> render_submit ( % { site: % { domain: new_domain } } )
315351
316- assert_patch ( lv , "/#{ new_domain } /change-domain-v2/success" )
352+ assert_patch ( lv , "/#{ URI . encode_www_form ( new_domain ) } /change-domain-v2/success" )
317353
318354 html = render_async ( lv , 500 )
319355 notice = text_of_element ( html , "div[data-testid='ce-generic-notice']" )
0 commit comments