Fix added_by not saving on adding country rules (#3835)

* Fix `added_by` not saving on adding country rules

* Format

* Remove dupe attr
This commit is contained in:
hq1 2024-02-27 12:36:16 +01:00 committed by GitHub
parent 518cdb3307
commit f1b6a672d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -176,7 +176,8 @@ defmodule PlausibleWeb.Live.Shields.CountryRules do
case Shields.add_country_rule(
socket.assigns.site.id,
Map.put(params, "added_by", "#{user.name} <#{user.email}>")
params,
added_by: user
) do
{:ok, rule} ->
country_rules = [rule | socket.assigns.country_rules]

View File

@ -83,7 +83,7 @@ defmodule PlausibleWeb.Live.Shields.CountriesTest do
assert submit_button(html, ~s/form[phx-submit="save-country-rule"]/)
end
test "submitting a valid country saves it", %{conn: conn, site: site} do
test "submitting a valid country saves it", %{conn: conn, site: site, user: user} do
lv = get_liveview(conn, site)
lv
@ -96,7 +96,14 @@ defmodule PlausibleWeb.Live.Shields.CountriesTest do
assert html =~ "Estonia"
assert [%{country_code: "EE"}] = Shields.list_country_rules(site)
added_by = "#{user.name} <#{user.email}>"
assert [%{id: id, country_code: "EE", added_by: ^added_by}] =
Shields.list_country_rules(site)
tooltip = text_of_attr(html, "#country-#{id}", "title")
assert tooltip =~ "Added at #{Date.utc_today()}"
assert tooltip =~ "by #{added_by}"
end
test "clicking Remove deletes the rule", %{conn: conn, site: site} do