diff --git a/lib/plausible/google/api.ex b/lib/plausible/google/api.ex index 708850319..3e863c2f8 100644 --- a/lib/plausible/google/api.ex +++ b/lib/plausible/google/api.ex @@ -16,16 +16,14 @@ defmodule Plausible.Google.API do @verified_permission_levels ["siteOwner", "siteFullUser", "siteRestrictedUser"] - def search_console_authorize_url(site_id, redirect_to) do + def search_console_authorize_url(site_id) do "https://accounts.google.com/o/oauth2/v2/auth?client_id=#{client_id()}&redirect_uri=#{redirect_uri()}&prompt=consent&response_type=code&access_type=offline&scope=#{@search_console_scope}&state=" <> - Jason.encode!([site_id, redirect_to]) + Jason.encode!([site_id, "search-console"]) end - def import_authorize_url(site_id, redirect_to, opts \\ []) do - legacy = Keyword.get(opts, :legacy, true) - + def import_authorize_url(site_id) do "https://accounts.google.com/o/oauth2/v2/auth?client_id=#{client_id()}&redirect_uri=#{redirect_uri()}&prompt=consent&response_type=code&access_type=offline&scope=#{@import_scope}&state=" <> - Jason.encode!([site_id, redirect_to, legacy]) + Jason.encode!([site_id, "import"]) end def fetch_access_token!(code) do diff --git a/lib/plausible/imported.ex b/lib/plausible/imported.ex index c5f94e27a..5e7bc1f90 100644 --- a/lib/plausible/imported.ex +++ b/lib/plausible/imported.ex @@ -43,8 +43,14 @@ defmodule Plausible.Imported do @spec tables() :: [String.t()] def tables, do: @table_names - @spec max_complete_imports() :: non_neg_integer() - def max_complete_imports(), do: @max_complete_imports + @spec max_complete_imports(Site.t()) :: non_neg_integer() + def max_complete_imports(site) do + if FunWithFlags.enabled?(:imports_exports, for: site) do + @max_complete_imports + else + 1 + end + end @spec load_import_data(Site.t()) :: Site.t() def load_import_data(%{import_data_loaded: true} = site), do: site diff --git a/lib/plausible_web/components/settings.ex b/lib/plausible_web/components/settings.ex index ade376c1e..ae89d4d44 100644 --- a/lib/plausible_web/components/settings.ex +++ b/lib/plausible_web/components/settings.ex @@ -7,10 +7,5 @@ defmodule PlausibleWeb.Components.Settings do import PlausibleWeb.Components.Generic - alias Plausible.Imported.SiteImport - - require Plausible.Imported.SiteImport - embed_templates("../templates/site/settings_search_console.html") - embed_templates("../templates/site/settings_google_import.html") end diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 7844d5771..1a526c09e 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -697,25 +697,15 @@ defmodule PlausibleWeb.AuthController do end def google_auth_callback(conn, %{"error" => error, "state" => state} = params) do - [site_id, _redirected_to, legacy, _ga4] = - case Jason.decode!(state) do - [site_id, redirect_to] -> - [site_id, redirect_to, true, false] - - [site_id, redirect_to, legacy] -> - [site_id, redirect_to, legacy, false] - - [site_id, redirect_to, legacy, ga4] -> - [site_id, redirect_to, legacy, ga4] - end + [site_id, redirected_to | _] = Jason.decode!(state) site = Repo.get(Plausible.Site, site_id) redirect_route = - if legacy do - Routes.site_path(conn, :settings_integrations, site.domain) - else + if redirected_to == "import" do Routes.site_path(conn, :settings_imports_exports, site.domain) + else + Routes.site_path(conn, :settings_integrations, site.domain) end case error do @@ -750,14 +740,7 @@ defmodule PlausibleWeb.AuthController do def google_auth_callback(conn, %{"code" => code, "state" => state}) do res = Plausible.Google.API.fetch_access_token!(code) - [site_id, redirect_to, legacy] = - case Jason.decode!(state) do - [site_id, redirect_to] -> - [site_id, redirect_to, true] - - [site_id, redirect_to, legacy] -> - [site_id, redirect_to, legacy] - end + [site_id, redirect_to | _] = Jason.decode!(state) site = Repo.get(Plausible.Site, site_id) expires_at = NaiveDateTime.add(NaiveDateTime.utc_now(), res["expires_in"]) @@ -769,8 +752,7 @@ defmodule PlausibleWeb.AuthController do Routes.google_analytics_path(conn, :property_or_view_form, site.domain, access_token: res["access_token"], refresh_token: res["refresh_token"], - expires_at: NaiveDateTime.to_iso8601(expires_at), - legacy: legacy + expires_at: NaiveDateTime.to_iso8601(expires_at) ) ) diff --git a/lib/plausible_web/controllers/google_analytics_controller.ex b/lib/plausible_web/controllers/google_analytics_controller.ex index e98c63242..b498e9263 100644 --- a/lib/plausible_web/controllers/google_analytics_controller.ex +++ b/lib/plausible_web/controllers/google_analytics_controller.ex @@ -16,8 +16,7 @@ defmodule PlausibleWeb.GoogleAnalyticsController do "refresh_token" => refresh_token, "expires_at" => expires_at, "start_date" => start_date, - "end_date" => end_date, - "legacy" => legacy + "end_date" => end_date }) do site = conn.assigns.site @@ -31,7 +30,6 @@ defmodule PlausibleWeb.GoogleAnalyticsController do expires_at: expires_at, start_date: start_date, end_date: end_date, - legacy: legacy, layout: {PlausibleWeb.LayoutView, "focus.html"} ) end @@ -41,24 +39,18 @@ defmodule PlausibleWeb.GoogleAnalyticsController do %{ "access_token" => access_token, "refresh_token" => refresh_token, - "expires_at" => expires_at, - "legacy" => legacy + "expires_at" => expires_at } = params ) do site = conn.assigns.site - redirect_route = - if legacy == "true" do - Routes.site_path(conn, :settings_integrations, site.domain) - else - Routes.site_path(conn, :settings_imports_exports, site.domain) - end + redirect_route = Routes.site_path(conn, :settings_imports_exports, site.domain) result = - if legacy == "true" do - Google.UA.API.list_views(access_token) - else + if FunWithFlags.enabled?(:imports_exports, for: site) do Google.API.list_properties_and_views(access_token) + else + Google.UA.API.list_views(access_token) end error = @@ -84,7 +76,6 @@ defmodule PlausibleWeb.GoogleAnalyticsController do site: conn.assigns.site, properties_and_views: properties_and_views, selected_property_or_view_error: error, - legacy: legacy, layout: {PlausibleWeb.LayoutView, "focus.html"} ) @@ -123,18 +114,12 @@ defmodule PlausibleWeb.GoogleAnalyticsController do "property_or_view" => property_or_view, "access_token" => access_token, "refresh_token" => refresh_token, - "expires_at" => expires_at, - "legacy" => legacy + "expires_at" => expires_at } = params ) do site = conn.assigns.site - redirect_route = - if legacy == "true" do - Routes.site_path(conn, :settings_integrations, site.domain) - else - Routes.site_path(conn, :settings_imports_exports, site.domain) - end + redirect_route = Routes.site_path(conn, :settings_imports_exports, site.domain) with {:ok, api_start_date} <- Google.API.get_analytics_start_date(access_token, property_or_view), @@ -156,15 +141,14 @@ defmodule PlausibleWeb.GoogleAnalyticsController do refresh_token: refresh_token, expires_at: expires_at, start_date: Date.to_iso8601(start_date), - end_date: Date.to_iso8601(end_date), - legacy: legacy + end_date: Date.to_iso8601(end_date) ) ) else {:error, error} when error in [:no_data, :no_time_window] -> params = params - |> Map.take(["access_token", "refresh_token", "expires_at", "legacy"]) + |> Map.take(["access_token", "refresh_token", "expires_at"]) |> Map.put("error", Atom.to_string(error)) property_or_view_form(conn, params) @@ -201,20 +185,14 @@ defmodule PlausibleWeb.GoogleAnalyticsController do "refresh_token" => refresh_token, "expires_at" => expires_at, "start_date" => start_date, - "end_date" => end_date, - "legacy" => legacy + "end_date" => end_date }) do site = conn.assigns.site start_date = Date.from_iso8601!(start_date) end_date = Date.from_iso8601!(end_date) - redirect_route = - if legacy == "true" do - Routes.site_path(conn, :settings_integrations, site.domain) - else - Routes.site_path(conn, :settings_imports_exports, site.domain) - end + redirect_route = Routes.site_path(conn, :settings_imports_exports, site.domain) case Google.API.get_property_or_view(access_token, property_or_view) do {:ok, %{name: property_or_view_name, id: property_or_view}} -> @@ -230,7 +208,6 @@ defmodule PlausibleWeb.GoogleAnalyticsController do start_date: start_date, end_date: end_date, property?: Google.API.property?(property_or_view), - legacy: legacy, layout: {PlausibleWeb.LayoutView, "focus.html"} ) @@ -274,8 +251,7 @@ defmodule PlausibleWeb.GoogleAnalyticsController do "end_date" => end_date, "access_token" => access_token, "refresh_token" => refresh_token, - "expires_at" => expires_at, - "legacy" => legacy + "expires_at" => expires_at }) do site = conn.assigns.site current_user = conn.assigns.current_user @@ -283,12 +259,7 @@ defmodule PlausibleWeb.GoogleAnalyticsController do start_date = Date.from_iso8601!(start_date) end_date = Date.from_iso8601!(end_date) - redirect_route = - if legacy == "true" do - Routes.site_path(conn, :settings_integrations, site.domain) - else - Routes.site_path(conn, :settings_imports_exports, site.domain) - end + redirect_route = Routes.site_path(conn, :settings_imports_exports, site.domain) import_opts = [ label: property_or_view, @@ -296,8 +267,7 @@ defmodule PlausibleWeb.GoogleAnalyticsController do end_date: end_date, access_token: access_token, refresh_token: refresh_token, - token_expires_at: expires_at, - legacy: legacy == "true" + token_expires_at: expires_at ] with {:ok, start_date, end_date} <- Imported.clamp_dates(site, start_date, end_date), diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index d71e9359a..00e093bb9 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -237,22 +237,11 @@ defmodule PlausibleWeb.SiteController do Plausible.Google.API.fetch_verified_properties(site.google_auth) end - legacy_import = Plausible.Imported.get_legacy_import(site) - - imported_pageviews = - if legacy_import do - Plausible.Stats.Clickhouse.imported_pageview_count(site) - else - 0 - end - has_plugins_tokens? = Plausible.Plugins.API.Tokens.any?(site) conn |> render("settings_integrations.html", site: site, - legacy_import: legacy_import, - imported_pageviews: imported_pageviews, has_plugins_tokens?: has_plugins_tokens?, search_console_domains: search_console_domains, dogfood_page_path: "/:dashboard/settings/integrations", @@ -278,18 +267,13 @@ defmodule PlausibleWeb.SiteController do def settings_imports_exports(conn, _params) do site = conn.assigns.site - if FunWithFlags.enabled?(:imports_exports, for: site) do - conn - |> render("settings_imports_exports.html", - site: site, - dogfood_page_path: "/:dashboard/settings/imports-exports", - connect_live_socket: true, - layout: {PlausibleWeb.LayoutView, "site_settings.html"} - ) - else - conn - |> redirect(external: Routes.site_path(conn, :settings, site.domain)) - end + conn + |> render("settings_imports_exports.html", + site: site, + dogfood_page_path: "/:dashboard/settings/imports-exports", + connect_live_socket: true, + layout: {PlausibleWeb.LayoutView, "site_settings.html"} + ) end def update_google_auth(conn, %{"google_auth" => attrs}) do diff --git a/lib/plausible_web/live/imports_exports_settings.ex b/lib/plausible_web/live/imports_exports_settings.ex index c1b83ed72..548ea7edf 100644 --- a/lib/plausible_web/live/imports_exports_settings.ex +++ b/lib/plausible_web/live/imports_exports_settings.ex @@ -35,10 +35,13 @@ defmodule PlausibleWeb.Live.ImportsExportsSettings do |> assign_new(:current_user, fn -> Plausible.Repo.get(Plausible.Auth.User, user_id) end) + |> assign_new(:max_imports, fn %{site: site} -> + Imported.max_complete_imports(site) + end) :ok = Imported.listen() - {:ok, assign(socket, max_imports: Imported.max_complete_imports())} + {:ok, socket} end def render(assigns) do @@ -79,7 +82,7 @@ defmodule PlausibleWeb.Live.ImportsExportsSettings do class="w-36 h-20" theme="bright" disabled={@import_in_progress? or @at_maximum?} - href={Plausible.Google.API.import_authorize_url(@site.id, "import", legacy: false)} + href={Plausible.Google.API.import_authorize_url(@site.id)} > Google Analytics import diff --git a/lib/plausible_web/templates/google_analytics/confirm.html.heex b/lib/plausible_web/templates/google_analytics/confirm.html.heex index c3d37d8db..f8f2eb4b8 100644 --- a/lib/plausible_web/templates/google_analytics/confirm.html.heex +++ b/lib/plausible_web/templates/google_analytics/confirm.html.heex @@ -4,7 +4,6 @@ <%= hidden_input(f, :access_token, value: @access_token) %> <%= hidden_input(f, :refresh_token, value: @refresh_token) %> <%= hidden_input(f, :expires_at, value: @expires_at) %> - <%= hidden_input(f, :legacy, value: @legacy) %>
Stats from this @@ -56,8 +55,7 @@ property_or_view: @selected_property_or_view, access_token: @access_token, refresh_token: @refresh_token, - expires_at: @expires_at, - legacy: @legacy + expires_at: @expires_at ) } class="underline text-indigo-600" diff --git a/lib/plausible_web/templates/google_analytics/property_or_view_form.html.heex b/lib/plausible_web/templates/google_analytics/property_or_view_form.html.heex index 775355947..dd20748ff 100644 --- a/lib/plausible_web/templates/google_analytics/property_or_view_form.html.heex +++ b/lib/plausible_web/templates/google_analytics/property_or_view_form.html.heex @@ -4,7 +4,6 @@ <%= hidden_input(f, :access_token, value: @access_token) %> <%= hidden_input(f, :refresh_token, value: @refresh_token) %> <%= hidden_input(f, :expires_at, value: @expires_at) %> - <%= hidden_input(f, :legacy, value: @legacy) %>
Choose the property or view in your Google Analytics account that will be imported to the <%= @site.domain %> dashboard. diff --git a/lib/plausible_web/templates/google_analytics/user_metric_form.html.heex b/lib/plausible_web/templates/google_analytics/user_metric_form.html.heex index 6a969b332..0f65b725a 100644 --- a/lib/plausible_web/templates/google_analytics/user_metric_form.html.heex +++ b/lib/plausible_web/templates/google_analytics/user_metric_form.html.heex @@ -40,8 +40,7 @@ property_or_view: @property_or_view, access_token: @access_token, refresh_token: @refresh_token, - expires_at: @expires_at, - legacy: @legacy + expires_at: @expires_at ) } class="underline text-indigo-600" @@ -58,8 +57,7 @@ refresh_token: @refresh_token, expires_at: @expires_at, start_date: @start_date, - end_date: @end_date, - legacy: @legacy + end_date: @end_date ), class: "button sm:w-auto w-full" ) %> diff --git a/lib/plausible_web/templates/site/settings_google_import.html.heex b/lib/plausible_web/templates/site/settings_google_import.html.heex deleted file mode 100644 index bb6d2c4d6..000000000 --- a/lib/plausible_web/templates/site/settings_google_import.html.heex +++ /dev/null @@ -1,124 +0,0 @@ -
-
-

- Google Analytics Data Import -

-

- Import existing data from your Google Analytics account. -

- -
- - <%= if Keyword.get(Application.get_env(:plausible, :google), :client_id) do %> - <%= cond do %> - <% @legacy_import && @legacy_import.status in [SiteImport.pending(), SiteImport.importing()] -> %> -
  • -
    -

    - Import from Google Analytics - - - - - - -

    -

    - From <%= PlausibleWeb.EmailView.date_format(@legacy_import.start_date) %> to <%= PlausibleWeb.EmailView.date_format( - @legacy_import.end_date - ) %> -

    -
    - <%= link("Cancel import", - to: "/#{URI.encode_www_form(@site.domain)}/settings/forget-imported", - method: :delete, - class: - "inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150" - ) %> -
  • - <% @legacy_import && @legacy_import.status == SiteImport.completed() -> %> -
  • -
    -

    - Import from Google Analytics - - - -

    -

    - From <%= PlausibleWeb.EmailView.date_format(@legacy_import.start_date) %> to <%= PlausibleWeb.EmailView.date_format( - @legacy_import.end_date - ) %> -

    -
    - <%= link( - "Clear " <> - PlausibleWeb.StatsView.large_number_format(@imported_pageviews) <> - " Imported Pageviews", - to: "/#{URI.encode_www_form(@site.domain)}/settings/forget-imported", - method: :delete, - class: - "inline-block mt-4 px-4 py-2 text-sm leading-5 font-medium text-red-600 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150" - ) %> -
  • - <% true -> %> - <%= if @legacy_import && @legacy_import.status == SiteImport.failed() do %> -
    - Your latest import has failed. You can try importing again by clicking the button below. If you try multiple times and the import keeps failing, please contact support. -
    - <% end %> - - <% end %> - <% else %> -
    - - - - -

    - An extra step is needed to set up your Plausible Analytics Self Hosted for the Google Search Console integration. - Find instructions <%= link("here", - to: "https://plausible.io/docs/self-hosting-configuration#google-search-integration", - class: "text-indigo-500" - ) %> -

    -
    - <% end %> -
    diff --git a/lib/plausible_web/templates/site/settings_imports_exports.html.heex b/lib/plausible_web/templates/site/settings_imports_exports.html.heex index 439c0d065..983d88ccc 100644 --- a/lib/plausible_web/templates/site/settings_imports_exports.html.heex +++ b/lib/plausible_web/templates/site/settings_imports_exports.html.heex @@ -4,7 +4,12 @@ Import Data

    - Import existing data from external sources. Pick one of the options below to start a new import. + Import existing data from external sources. + <%= if FunWithFlags.enabled?(:csv_imports_exports, for: @site) do %> + Pick one of the options below to start a new import. + <% else %> + Click below to start a new import. + <% end %>

    diff --git a/lib/plausible_web/templates/site/settings_integrations.html.heex b/lib/plausible_web/templates/site/settings_integrations.html.heex index bc10f7eef..79ac2220e 100644 --- a/lib/plausible_web/templates/site/settings_integrations.html.heex +++ b/lib/plausible_web/templates/site/settings_integrations.html.heex @@ -3,14 +3,6 @@ search_console_domains={@search_console_domains} /> -<%= if not FunWithFlags.enabled?(:imports_exports, for: @site) do %> - -<% end %> -
    NB: You also need to set up your site on diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.ex index ca93c07ea..bc4c52d35 100644 --- a/lib/plausible_web/views/layout_view.ex +++ b/lib/plausible_web/views/layout_view.ex @@ -49,6 +49,13 @@ defmodule PlausibleWeb.LayoutView do end def settings_tabs(conn) do + imports_exports_key = + if FunWithFlags.enabled?(:csv_imports_exports, for: conn.assigns.site) do + "Imports & Exports" + else + "Imports" + end + [ %{key: "General", value: "general", icon: :rocket_launch}, %{key: "People", value: "people", icon: :users}, @@ -59,9 +66,7 @@ defmodule PlausibleWeb.LayoutView do end, %{key: "Custom Properties", value: "properties", icon: :document_text}, %{key: "Integrations", value: "integrations", icon: :arrow_path_rounded_square}, - if FunWithFlags.enabled?(:imports_exports, for: conn.assigns.site) do - %{key: "Imports & Exports", value: "imports-exports", icon: :arrows_up_down} - end, + %{key: imports_exports_key, value: "imports-exports", icon: :arrows_up_down}, %{ key: "Shields", icon: :shield_exclamation, diff --git a/lib/plausible_web/views/site_view.ex b/lib/plausible_web/views/site_view.ex index b394dbf4c..a3ae89f77 100644 --- a/lib/plausible_web/views/site_view.ex +++ b/lib/plausible_web/views/site_view.ex @@ -2,10 +2,6 @@ defmodule PlausibleWeb.SiteView do use PlausibleWeb, :view use Plausible - alias Plausible.Imported.SiteImport - - require Plausible.Imported.SiteImport - def plausible_url do PlausibleWeb.Endpoint.url() end diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exs index 461ccf2e1..c55356b18 100644 --- a/test/plausible_web/controllers/auth_controller_test.exs +++ b/test/plausible_web/controllers/auth_controller_test.exs @@ -1484,7 +1484,7 @@ defmodule PlausibleWeb.AuthControllerTest do conn = get(conn, Routes.auth_path(conn, :google_auth_callback), callback_params) assert redirected_to(conn, 302) == - Routes.site_path(conn, :settings_integrations, site.domain) + Routes.site_path(conn, :settings_imports_exports, site.domain) assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "unable to authenticate your Google Analytics" diff --git a/test/plausible_web/controllers/google_analytics_controller_test.exs b/test/plausible_web/controllers/google_analytics_controller_test.exs index ccaccf946..770e13484 100644 --- a/test/plausible_web/controllers/google_analytics_controller_test.exs +++ b/test/plausible_web/controllers/google_analytics_controller_test.exs @@ -24,8 +24,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "refresh_token" => "foo", "expires_at" => "2022-09-22T20:01:37.112777", "start_date" => "2020-02-22", - "end_date" => "2022-09-22", - "legacy" => "true" + "end_date" => "2022-09-22" }) |> html_response(200) @@ -36,8 +35,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do refresh_token: "foo", expires_at: "2022-09-22T20:01:37.112777", start_date: "2020-02-22", - end_date: "2022-09-22", - legacy: "true" + end_date: "2022-09-22" ) |> String.replace("&", "&") end @@ -46,30 +44,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do describe "GET /:website/import/google-analytics/property-or-view" do setup [:create_user, :log_in, :create_new_site] - test "lists Google Analytics views (legacy)", %{conn: conn, site: site} do - expect( - Plausible.HTTPClient.Mock, - :get, - fn _url, _opts -> - body = "fixture/ga_list_views.json" |> File.read!() |> Jason.decode!() - {:ok, %Finch.Response{body: body, status: 200}} - end - ) - - response = - conn - |> get("/#{site.domain}/import/google-analytics/property-or-view", %{ - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "true" - }) - |> html_response(200) - - assert response =~ "57238190 - one.test" - assert response =~ "54460083 - two.test" - end - test "lists Google Analytics views and properties", %{conn: conn, site: site} do expect( Plausible.HTTPClient.Mock, @@ -94,8 +68,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do |> get("/#{site.domain}/import/google-analytics/property-or-view", %{ "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "false" + "expires_at" => "2022-09-22T20:01:37.112777" }) |> html_response(200) @@ -106,176 +79,166 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do assert response =~ "GA4 - Google Merch Shop (properties/213025502)" end - for {legacy, view} <- [{"true", :settings_integrations}, {"false", :settings_imports_exports}] do - test "redirects to #{view} on auth error with flash error (legacy: #{legacy})", %{ - conn: conn, - site: site - } do - expect( - Plausible.HTTPClient.Mock, - :get, - fn _url, _opts -> - {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: %{}}}} - end - ) + test "redirects to imports and exports on auth error with flash error", %{ + conn: conn, + site: site + } do + expect( + Plausible.HTTPClient.Mock, + :get, + fn _url, _opts -> + {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: %{}}}} + end + ) - conn = - conn - |> get("/#{site.domain}/import/google-analytics/property-or-view", %{ - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => unquote(legacy) - }) + conn = + conn + |> get("/#{site.domain}/import/google-analytics/property-or-view", %{ + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "We were unable to authenticate your Google Analytics account" - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "We were unable to authenticate your Google Analytics account" + end - test "redirects to #{view} on timeout error with flash error (legacy: #{legacy})", %{ - conn: conn, - site: site - } do - expect( - Plausible.HTTPClient.Mock, - :get, - fn _url, _opts -> - {:error, %Mint.TransportError{reason: :timeout}} - end - ) + test "redirects to imports and exports on timeout error with flash error", %{ + conn: conn, + site: site + } do + expect( + Plausible.HTTPClient.Mock, + :get, + fn _url, _opts -> + {:error, %Mint.TransportError{reason: :timeout}} + end + ) - conn = - conn - |> get("/#{site.domain}/import/google-analytics/property-or-view", %{ - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => unquote(legacy) - }) + conn = + conn + |> get("/#{site.domain}/import/google-analytics/property-or-view", %{ + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "Google Analytics API has timed out." - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "Google Analytics API has timed out." + end - test "redirects to #{view} on list retrival failure with flash error (legacy: #{legacy})", - %{ - conn: conn, - site: site - } do - expect( - Plausible.HTTPClient.Mock, - :get, - fn _url, _opts -> - {:error, - %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}} - end - ) + test "redirects to imports and exports on list retrival failure with flash error", + %{ + conn: conn, + site: site + } do + expect( + Plausible.HTTPClient.Mock, + :get, + fn _url, _opts -> + {:error, %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}} + end + ) - conn = - conn - |> get("/#{site.domain}/import/google-analytics/property-or-view", %{ - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => unquote(legacy) - }) + conn = + conn + |> get("/#{site.domain}/import/google-analytics/property-or-view", %{ + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "We were unable to list your Google Analytics properties and views" - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "We were unable to list your Google Analytics properties and views" end end describe "POST /:website/import/google-analytics/property-or-view" do setup [:create_user, :log_in, :create_new_site] - for legacy <- ["true", "false"] do - test "redirects to user metrics notice (UA legacy: #{legacy})", %{conn: conn, site: site} do - expect( - Plausible.HTTPClient.Mock, - :post, - fn _url, _opts, _params -> - body = "fixture/ga_start_date.json" |> File.read!() |> Jason.decode!() - {:ok, %Finch.Response{body: body, status: 200}} - end - ) + test "redirects to user metrics notice", %{conn: conn, site: site} do + expect( + Plausible.HTTPClient.Mock, + :post, + fn _url, _opts, _params -> + body = "fixture/ga_start_date.json" |> File.read!() |> Jason.decode!() + {:ok, %Finch.Response{body: body, status: 200}} + end + ) - expect( - Plausible.HTTPClient.Mock, - :post, - fn _url, _opts, _params -> - body = "fixture/ga_end_date.json" |> File.read!() |> Jason.decode!() - {:ok, %Finch.Response{body: body, status: 200}} - end - ) + expect( + Plausible.HTTPClient.Mock, + :post, + fn _url, _opts, _params -> + body = "fixture/ga_end_date.json" |> File.read!() |> Jason.decode!() + {:ok, %Finch.Response{body: body, status: 200}} + end + ) - conn = - conn - |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ - "property_or_view" => "57238190", - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => unquote(legacy) - }) + conn = + conn + |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ + "property_or_view" => "57238190", + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777" + }) - assert redirected_to(conn, 302) =~ - "/#{URI.encode_www_form(site.domain)}/import/google-analytics/user-metric" - end + assert redirected_to(conn, 302) =~ + "/#{URI.encode_www_form(site.domain)}/import/google-analytics/user-metric" + end - test "redirects to confirmation (UA legacy: #{legacy})", %{conn: conn, site: site} do - expect( - Plausible.HTTPClient.Mock, - :post, - fn _url, _opts, _params -> - body = "fixture/ga_start_date_later.json" |> File.read!() |> Jason.decode!() - {:ok, %Finch.Response{body: body, status: 200}} - end - ) + test "redirects to confirmation", %{conn: conn, site: site} do + expect( + Plausible.HTTPClient.Mock, + :post, + fn _url, _opts, _params -> + body = "fixture/ga_start_date_later.json" |> File.read!() |> Jason.decode!() + {:ok, %Finch.Response{body: body, status: 200}} + end + ) - expect( - Plausible.HTTPClient.Mock, - :post, - fn _url, _opts, _params -> - body = "fixture/ga_end_date.json" |> File.read!() |> Jason.decode!() - {:ok, %Finch.Response{body: body, status: 200}} - end - ) + expect( + Plausible.HTTPClient.Mock, + :post, + fn _url, _opts, _params -> + body = "fixture/ga_end_date.json" |> File.read!() |> Jason.decode!() + {:ok, %Finch.Response{body: body, status: 200}} + end + ) - conn = - conn - |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ - "property_or_view" => "57238190", - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => unquote(legacy) - }) + conn = + conn + |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ + "property_or_view" => "57238190", + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777" + }) - assert redirected_to(conn, 302) =~ - "/#{URI.encode_www_form(site.domain)}/import/google-analytics/confirm" - end + assert redirected_to(conn, 302) =~ + "/#{URI.encode_www_form(site.domain)}/import/google-analytics/confirm" end test "redirects to confirmation (GA4)", %{conn: conn, site: site} do @@ -303,8 +266,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "property_or_view" => "properties/428685906", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "false" + "expires_at" => "2022-09-22T20:01:37.112777" }) assert redirected_to(conn, 302) =~ @@ -365,8 +327,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "property_or_view" => "properties/428685906", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "false" + "expires_at" => "2022-09-22T20:01:37.112777" }) |> html_response(200) @@ -415,117 +376,110 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "property_or_view" => "properties/428685906", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "false" + "expires_at" => "2022-09-22T20:01:37.112777" }) |> html_response(200) assert response =~ "No data found. Nothing to import." end - for {legacy, view} <- [{"true", :settings_integrations}, {"false", :settings_imports_exports}] do - test "redirects to #{view} on failed property/view choice with flash error (legacy: #{legacy})", - %{ - conn: conn, - site: site - } do - expect( - Plausible.HTTPClient.Mock, - :post, - fn _url, _opts, _params -> - {:error, - %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}} - end - ) + test "redirects to imports and exports on failed property/view choice with flash error", + %{ + conn: conn, + site: site + } do + expect( + Plausible.HTTPClient.Mock, + :post, + fn _url, _opts, _params -> + {:error, %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}} + end + ) - conn = - conn - |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ - "property_or_view" => "properties/428685906", - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => unquote(legacy) - }) + conn = + conn + |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ + "property_or_view" => "properties/428685906", + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "We were unable to retrieve information from Google Analytics" - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "We were unable to retrieve information from Google Analytics" + end - test "redirects to #{view} on expired authentication with flash error (legacy: #{legacy})", - %{ - conn: conn, - site: site - } do - expect( - Plausible.HTTPClient.Mock, - :post, - fn _url, _opts, _params -> - {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: "Access denied"}}} - end - ) + test "redirects to imports and exports on expired authentication with flash error", + %{ + conn: conn, + site: site + } do + expect( + Plausible.HTTPClient.Mock, + :post, + fn _url, _opts, _params -> + {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: "Access denied"}}} + end + ) - conn = - conn - |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ - "property_or_view" => "properties/428685906", - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => unquote(legacy) - }) + conn = + conn + |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ + "property_or_view" => "properties/428685906", + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "Google Analytics authentication seems to have expired." - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "Google Analytics authentication seems to have expired." + end - test "redirects to #{view} on timeout with flash error (legacy: #{legacy})", - %{ - conn: conn, - site: site - } do - expect( - Plausible.HTTPClient.Mock, - :post, - fn _url, _opts, _params -> - {:error, %Mint.TransportError{reason: :timeout}} - end - ) + test "redirects to imports and exports on timeout with flash error", + %{ + conn: conn, + site: site + } do + expect( + Plausible.HTTPClient.Mock, + :post, + fn _url, _opts, _params -> + {:error, %Mint.TransportError{reason: :timeout}} + end + ) - conn = - conn - |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ - "property_or_view" => "properties/428685906", - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => unquote(legacy) - }) + conn = + conn + |> post("/#{site.domain}/import/google-analytics/property-or-view", %{ + "property_or_view" => "properties/428685906", + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "Google Analytics API has timed out." - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "Google Analytics API has timed out." end end @@ -550,8 +504,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "refresh_token" => "foo", "expires_at" => "2022-09-22T20:01:37.112777", "start_date" => "2012-01-18", - "end_date" => "2022-09-22", - "legacy" => "true" + "end_date" => "2022-09-22" }) |> html_response(200) @@ -565,8 +518,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do assert text_of_attr(response, ~s|input[name=expires_at]|, "value") == "2022-09-22T20:01:37.112777" - assert text_of_attr(response, ~s|input[name=legacy]|, "value") == "true" - assert text_of_attr(response, ~s|input[name=property_or_view]|, "value") == "57238190" assert text_of_attr(response, ~s|input[name=start_date]|, "value") == "2012-01-18" @@ -592,8 +543,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "refresh_token" => "foo", "expires_at" => "2022-09-22T20:01:37.112777", "start_date" => "2024-02-22", - "end_date" => "2024-02-26", - "legacy" => "true" + "end_date" => "2024-02-26" }) |> html_response(200) @@ -607,8 +557,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do assert text_of_attr(response, ~s|input[name=expires_at]|, "value") == "2022-09-22T20:01:37.112777" - assert text_of_attr(response, ~s|input[name=legacy]|, "value") == "true" - assert text_of_attr(response, ~s|input[name=property_or_view]|, "value") == "properties/428685444" @@ -617,115 +565,109 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do assert text_of_attr(response, ~s|input[name=end_date]|, "value") == "2024-02-26" end - for {legacy, view} <- [{"true", :settings_integrations}, {"false", :settings_imports_exports}] do - test "redirects to #{view} on failed property/view retrieval with flash error (legacy: #{legacy})", - %{ - conn: conn, - site: site - } do - expect( - Plausible.HTTPClient.Mock, - :get, - fn _url, _params -> - {:error, - %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}} - end - ) + test "redirects to imports and exports on failed property/view retrieval with flash error", + %{ + conn: conn, + site: site + } do + expect( + Plausible.HTTPClient.Mock, + :get, + fn _url, _params -> + {:error, %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}} + end + ) - conn = - conn - |> get("/#{site.domain}/import/google-analytics/confirm", %{ - "property_or_view" => "properties/428685906", - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "start_date" => "2024-02-22", - "end_date" => "2024-02-26", - "legacy" => unquote(legacy) - }) + conn = + conn + |> get("/#{site.domain}/import/google-analytics/confirm", %{ + "property_or_view" => "properties/428685906", + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777", + "start_date" => "2024-02-22", + "end_date" => "2024-02-26" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "We were unable to retrieve information from Google Analytics" - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "We were unable to retrieve information from Google Analytics" + end - test "redirects to #{view} on expired authentication with flash error (legacy: #{legacy})", - %{ - conn: conn, - site: site - } do - expect( - Plausible.HTTPClient.Mock, - :get, - fn _url, _params -> - {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: "Access denied"}}} - end - ) + test "redirects to imports and exports on expired authentication with flash error", + %{ + conn: conn, + site: site + } do + expect( + Plausible.HTTPClient.Mock, + :get, + fn _url, _params -> + {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: "Access denied"}}} + end + ) - conn = - conn - |> get("/#{site.domain}/import/google-analytics/confirm", %{ - "property_or_view" => "properties/428685906", - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "start_date" => "2024-02-22", - "end_date" => "2024-02-26", - "legacy" => unquote(legacy) - }) + conn = + conn + |> get("/#{site.domain}/import/google-analytics/confirm", %{ + "property_or_view" => "properties/428685906", + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777", + "start_date" => "2024-02-22", + "end_date" => "2024-02-26" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "Google Analytics authentication seems to have expired." - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "Google Analytics authentication seems to have expired." + end - test "redirects to #{view} on timeout with flash error (legacy: #{legacy})", - %{ - conn: conn, - site: site - } do - expect( - Plausible.HTTPClient.Mock, - :get, - fn _url, _params -> - {:error, %Mint.TransportError{reason: :timeout}} - end - ) + test "redirects to imports and exports on timeout with flash error", + %{ + conn: conn, + site: site + } do + expect( + Plausible.HTTPClient.Mock, + :get, + fn _url, _params -> + {:error, %Mint.TransportError{reason: :timeout}} + end + ) - conn = - conn - |> get("/#{site.domain}/import/google-analytics/confirm", %{ - "property_or_view" => "properties/428685906", - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "start_date" => "2024-02-22", - "end_date" => "2024-02-26", - "legacy" => unquote(legacy) - }) + conn = + conn + |> get("/#{site.domain}/import/google-analytics/confirm", %{ + "property_or_view" => "properties/428685906", + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777", + "start_date" => "2024-02-22", + "end_date" => "2024-02-26" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "Google Analytics API has timed out." - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "Google Analytics API has timed out." end end @@ -740,8 +682,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "end_date" => "2022-03-01", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "false" + "expires_at" => "2022-09-22T20:01:37.112777" }) assert redirected_to(conn, 302) == @@ -762,12 +703,11 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "end_date" => "2022-03-01", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "true" + "expires_at" => "2022-09-22T20:01:37.112777" }) assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path(conn, :settings_integrations, site.domain) + PlausibleWeb.Router.Helpers.site_path(conn, :settings_imports_exports, site.domain) [site_import] = Plausible.Imported.list_all_imports(site) @@ -776,7 +716,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do assert site_import.status == SiteImport.pending() end - test "redirects to imports and exports when creating UA job with legacy set to false", %{ + test "redirects to imports and exports when creating UA job", %{ conn: conn, site: site } do @@ -787,8 +727,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "end_date" => "2022-03-01", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "false" + "expires_at" => "2022-09-22T20:01:37.112777" }) assert redirected_to(conn, 302) == @@ -808,8 +747,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "end_date" => "2022-03-01", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "false" + "expires_at" => "2022-09-22T20:01:37.112777" }) assert [%{id: import_id, legacy: false}] = Plausible.Imported.list_all_imports(site) @@ -835,11 +773,10 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "end_date" => "2022-03-01", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "true" + "expires_at" => "2022-09-22T20:01:37.112777" }) - assert [%{id: import_id, legacy: true}] = Plausible.Imported.list_all_imports(site) + assert [%{id: import_id, legacy: false}] = Plausible.Imported.list_all_imports(site) assert_enqueued( worker: Plausible.Workers.ImportAnalytics, @@ -872,8 +809,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "end_date" => "2022-03-01", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "false" + "expires_at" => "2022-09-22T20:01:37.112777" }) conn = @@ -883,8 +819,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do "end_date" => "2022-03-01", "access_token" => "token", "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => "true" + "expires_at" => "2022-09-22T20:01:37.112777" }) assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ @@ -895,43 +830,40 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do assert job.args.import_id == import_id end - for {legacy, view} <- [{"true", :settings_integrations}, {"false", :settings_imports_exports}] do - test "redirects to #{view} with no time window error flash error (legacy: #{legacy})", %{ - conn: conn, - site: site - } do - start_date = ~D[2022-01-12] - end_date = ~D[2024-03-13] + test "redirects to imports and exports with no time window error flash error", %{ + conn: conn, + site: site + } do + start_date = ~D[2022-01-12] + end_date = ~D[2024-03-13] - _existing_import = - insert(:site_import, - site: site, - start_date: start_date, - end_date: end_date, - status: :completed - ) + _existing_import = + insert(:site_import, + site: site, + start_date: start_date, + end_date: end_date, + status: :completed + ) - conn = - post(conn, "/#{site.domain}/settings/google-import", %{ - "property_or_view" => "123456", - "start_date" => "2023-03-01", - "end_date" => "2022-03-01", - "access_token" => "token", - "refresh_token" => "foo", - "expires_at" => "2022-09-22T20:01:37.112777", - "legacy" => unquote(legacy) - }) + conn = + post(conn, "/#{site.domain}/settings/google-import", %{ + "property_or_view" => "123456", + "start_date" => "2023-03-01", + "end_date" => "2022-03-01", + "access_token" => "token", + "refresh_token" => "foo", + "expires_at" => "2022-09-22T20:01:37.112777" + }) - assert redirected_to(conn, 302) == - PlausibleWeb.Router.Helpers.site_path( - conn, - unquote(view), - site.domain - ) + assert redirected_to(conn, 302) == + PlausibleWeb.Router.Helpers.site_path( + conn, + :settings_imports_exports, + site.domain + ) - assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "Import failed. No data could be imported because date range overlaps with existing data." - end + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + "Import failed. No data could be imported because date range overlaps with existing data." end end end diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs index d6a876ff2..52942c823 100644 --- a/test/plausible_web/controllers/site_controller_test.exs +++ b/test/plausible_web/controllers/site_controller_test.exs @@ -679,7 +679,7 @@ defmodule PlausibleWeb.SiteControllerTest do end test "disables import buttons when imports are at maximum", %{conn: conn, site: site} do - insert_list(Plausible.Imported.max_complete_imports(), :site_import, + insert_list(Plausible.Imported.max_complete_imports(site), :site_import, site: site, status: SiteImport.completed() ) @@ -687,7 +687,7 @@ defmodule PlausibleWeb.SiteControllerTest do conn = get(conn, "/#{site.domain}/settings/imports-exports") assert html_response(conn, 200) =~ - "Maximum of #{Plausible.Imported.max_complete_imports()} imports is reached." + "Maximum of #{Plausible.Imported.max_complete_imports(site)} imports is reached." end test "considers older legacy imports when showing pageview count", %{conn: conn, site: site} do