From f1b6a672d45dfedf8271c6ce78fa1f95e865c4cb Mon Sep 17 00:00:00 2001 From: hq1 Date: Tue, 27 Feb 2024 12:36:16 +0100 Subject: [PATCH] Fix `added_by` not saving on adding country rules (#3835) * Fix `added_by` not saving on adding country rules * Format * Remove dupe attr --- lib/plausible_web/live/shields/country_rules.ex | 3 ++- test/plausible_web/live/shields/countries_test.exs | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/plausible_web/live/shields/country_rules.ex b/lib/plausible_web/live/shields/country_rules.ex index 895b49d3e..4b3c8533d 100644 --- a/lib/plausible_web/live/shields/country_rules.ex +++ b/lib/plausible_web/live/shields/country_rules.ex @@ -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] diff --git a/test/plausible_web/live/shields/countries_test.exs b/test/plausible_web/live/shields/countries_test.exs index bd9a31944..7495dc051 100644 --- a/test/plausible_web/live/shields/countries_test.exs +++ b/test/plausible_web/live/shields/countries_test.exs @@ -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