2020-01-22 12:16:53 +03:00
|
|
|
defmodule PlausibleWeb.UnsubscribeControllerTest do
|
2022-12-26 16:20:29 +03:00
|
|
|
use PlausibleWeb.ConnCase, async: true
|
2020-01-22 12:16:53 +03:00
|
|
|
use Plausible.Repo
|
|
|
|
|
2023-11-29 13:04:54 +03:00
|
|
|
setup {PlausibleWeb.FirstLaunchPlug.Test, :skip}
|
|
|
|
|
2020-01-22 12:16:53 +03:00
|
|
|
describe "GET /sites/:website/weekly-report/unsubscribe" do
|
|
|
|
test "removes a recipient from the weekly report without them having to log in", %{conn: conn} do
|
|
|
|
site = insert(:site)
|
|
|
|
insert(:weekly_report, site: site, recipients: ["recipient@email.com"])
|
|
|
|
|
2020-06-08 10:35:13 +03:00
|
|
|
conn =
|
|
|
|
get(conn, "/sites/#{site.domain}/weekly-report/unsubscribe?email=recipient@email.com")
|
2020-01-22 12:16:53 +03:00
|
|
|
|
|
|
|
assert html_response(conn, 200) =~ "Unsubscribe successful"
|
|
|
|
|
|
|
|
report = Repo.get_by(Plausible.Site.WeeklyReport, site_id: site.id)
|
|
|
|
assert report.recipients == []
|
|
|
|
end
|
2021-05-03 16:56:46 +03:00
|
|
|
|
|
|
|
test "renders success if site or weekly report does not exist in the database", %{conn: conn} do
|
|
|
|
conn =
|
|
|
|
get(conn, "/sites/nonexistent.com/weekly-report/unsubscribe?email=recipient@email.com")
|
|
|
|
|
|
|
|
assert html_response(conn, 200) =~ "Unsubscribe successful"
|
|
|
|
end
|
2020-01-22 12:16:53 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /sites/:website/monthly-report/unsubscribe" do
|
|
|
|
test "removes a recipient from the weekly report without them having to log in", %{conn: conn} do
|
|
|
|
site = insert(:site)
|
|
|
|
insert(:monthly_report, site: site, recipients: ["recipient@email.com"])
|
|
|
|
|
2020-06-08 10:35:13 +03:00
|
|
|
conn =
|
|
|
|
get(conn, "/sites/#{site.domain}/monthly-report/unsubscribe?email=recipient@email.com")
|
2020-01-22 12:16:53 +03:00
|
|
|
|
|
|
|
assert html_response(conn, 200) =~ "Unsubscribe successful"
|
|
|
|
|
|
|
|
report = Repo.get_by(Plausible.Site.MonthlyReport, site_id: site.id)
|
|
|
|
assert report.recipients == []
|
|
|
|
end
|
2021-05-03 16:56:46 +03:00
|
|
|
|
|
|
|
test "renders success if site or weekly report does not exist in the database", %{conn: conn} do
|
|
|
|
conn =
|
|
|
|
get(conn, "/sites/nonexistent.com/monthly-report/unsubscribe?email=recipient@email.com")
|
|
|
|
|
|
|
|
assert html_response(conn, 200) =~ "Unsubscribe successful"
|
|
|
|
end
|
2020-01-22 12:16:53 +03:00
|
|
|
end
|
|
|
|
end
|