@@ -169,7 +169,29 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
169169 )
170170 |> post ( "/api/event" , params )
171171
172- assert get_event ( "headless-chrome-test.com" ) == nil
172+ refute get_event ( "headless-chrome-test.com" )
173+ end
174+
175+ test "Headless Chrome is not ignored on staging environment" , % { conn: conn } do
176+ initial_env = Application . get_env ( :plausible , :system_environment )
177+ Application . put_env ( :plausible , :system_environment , "staging" )
178+
179+ params = % {
180+ name: "pageview" ,
181+ url: "http://www.example.com/" ,
182+ domain: "headless-chrome-stg-test.com"
183+ }
184+
185+ conn
186+ |> put_req_header (
187+ "user-agent" ,
188+ "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/85.0.4183.83 Safari/537.36"
189+ )
190+ |> post ( "/api/event" , params )
191+
192+ assert get_event ( "headless-chrome-stg-test.com" )
193+
194+ Application . put_env ( :plausible , :system_environment , initial_env )
173195 end
174196
175197 test "parses user_agent" , % { conn: conn } do
@@ -476,11 +498,11 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
476498 url: "http://gigride.live/" ,
477499 domain: "special-props-test.com" ,
478500 props: % {
479- campaign_id: 8 ,
501+ campaign_id: "vendor-8" ,
480502 company_id: 10 ,
481503 job_id: 12 ,
482504 page_id: 15 ,
483- product_id: 11 ,
505+ product_id: "vendor-11" ,
484506 site_id: 9 ,
485507 careers_application_form_uuid: "313a26c2-741c-421c-9a6b-f39c02c8d35c"
486508 }
@@ -491,8 +513,8 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
491513
492514 event = get_event ( "special-props-test.com" )
493515
494- assert Map . get ( event , :campaign_id ) == 8
495- assert Map . get ( event , :product_id ) == 11
516+ assert Map . get ( event , :campaign_id ) == "vendor-8"
517+ assert Map . get ( event , :product_id ) == "vendor-11"
496518 assert Map . get ( event , :company_id ) == 10
497519 assert Map . get ( event , :job_id ) == 12
498520 assert Map . get ( event , :page_id ) == 15
@@ -878,9 +900,7 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
878900 |> post ( "/api/event" , params )
879901
880902 assert json_response ( conn , 400 ) == % {
881- "errors" => % {
882- "hostname" => [ "can't be blank" ]
883- }
903+ "errors" => % { "request" => "Unable to process request" }
884904 }
885905 end
886906
@@ -897,9 +917,7 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
897917 |> post ( "/api/event" , params )
898918
899919 assert json_response ( conn , 400 ) == % {
900- "errors" => % {
901- "domain" => [ "can't be blank" ]
902- }
920+ "errors" => % { "request" => "Unable to process request" }
903921 }
904922 end
905923 end
@@ -1077,11 +1095,12 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
10771095 assert pageview . hostname == "liipgellkffekalgefpjolodblggkmjg"
10781096 end
10791097
1080- describe "GET /api/health" do
1081- test "returns 200 OK" , % { conn: conn } do
1082- conn = get ( conn , "/api/health" )
1098+ # /api/health path is disabled in PlausibleWeb.Router module
1099+ # describe "GET /api/health" do
1100+ # test "returns 200 OK", %{conn: conn} do
1101+ # conn = get(conn, "/api/health")
10831102
1084- assert conn . status == 200
1085- end
1086- end
1103+ # assert conn.status == 200
1104+ # end
1105+ # end
10871106end
0 commit comments