From 80e01fedd588cbe36d941f9595d4e994cd252401 Mon Sep 17 00:00:00 2001 From: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> Date: Thu, 22 Sep 2022 23:25:24 +0300 Subject: [PATCH] do not show invoices for free subscription (#2249) * do not show invoices for free subscription * use refute instead of negative assert * changed to refute in the other test too --- lib/plausible/billing/paddle_api.ex | 5 +++-- .../templates/auth/user_settings.html.eex | 2 +- .../plausible_web/controllers/auth_controller_test.exs | 10 +++++++++- test/support/paddle_api_mock.ex | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/plausible/billing/paddle_api.ex b/lib/plausible/billing/paddle_api.ex index 5325fd1d2..820a32999 100644 --- a/lib/plausible/billing/paddle_api.ex +++ b/lib/plausible/billing/paddle_api.ex @@ -92,8 +92,9 @@ defmodule Plausible.Billing.PaddleApi do @spec get_invoices(Plausible.Billing.Subscription.t()) :: {:ok, list()} | {:error, :request_failed} - | {:error, :no_subscription} - def get_invoices(nil), do: {:error, :no_subscription} + | {:error, :no_invoices} + def get_invoices(nil), do: {:error, :no_invoices} + def get_invoices(%{paddle_subscription_id: nil}), do: {:error, :no_invoices} def get_invoices(subscription) do config = get_config() diff --git a/lib/plausible_web/templates/auth/user_settings.html.eex b/lib/plausible_web/templates/auth/user_settings.html.eex index 9d1fdc3a9..6e82fb516 100644 --- a/lib/plausible_web/templates/auth/user_settings.html.eex +++ b/lib/plausible_web/templates/auth/user_settings.html.eex @@ -125,7 +125,7 @@ <%= case @invoices do %> - <% {:error, :no_subscription} -> %> + <% {:error, :no_invoices} -> %> <% {:error, :request_failed} -> %>
diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exs index 3db257d4d..2aaa0c482 100644 --- a/test/plausible_web/controllers/auth_controller_test.exs +++ b/test/plausible_web/controllers/auth_controller_test.exs @@ -557,7 +557,15 @@ defmodule PlausibleWeb.AuthControllerTest do test "does not show invoice section for a user with no subscription", %{conn: conn} do conn = get(conn, "/settings") - assert !(html_response(conn, 200) =~ "Invoices") + refute html_response(conn, 200) =~ "Invoices" + end + + test "does not show invoice section for a free subscription", %{conn: conn, user: user} do + Plausible.Billing.Subscription.free(%{user_id: user.id, currency_code: "EUR"}) + |> Repo.insert!() + + conn = get(conn, "/settings") + refute html_response(conn, 200) =~ "Invoices" end end diff --git a/test/support/paddle_api_mock.ex b/test/support/paddle_api_mock.ex index e44cec0ae..a6a7c46b4 100644 --- a/test/support/paddle_api_mock.ex +++ b/test/support/paddle_api_mock.ex @@ -26,7 +26,8 @@ defmodule Plausible.PaddleApi.Mock do }} end - def get_invoices(nil), do: {:error, :no_subscription} + def get_invoices(nil), do: {:error, :no_invoices} + def get_invoices(%{paddle_subscription_id: nil}), do: {:error, :no_invoices} def get_invoices(subscription) do case subscription.paddle_subscription_id do