|
|
|
|
@ -139,38 +139,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
|
|
|
|
|
"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
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
assert redirected_to(conn, 302) ==
|
|
|
|
|
PlausibleWeb.Router.Helpers.site_path(
|
|
|
|
|
conn,
|
|
|
|
|
unquote(view),
|
|
|
|
|
site.domain
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
@ -492,40 +460,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
|
|
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
assert redirected_to(conn, 302) ==
|
|
|
|
|
PlausibleWeb.Router.Helpers.site_path(
|
|
|
|
|
conn,
|
|
|
|
|
unquote(view),
|
|
|
|
|
site.domain
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
|
|
|
|
|
"Google Analytics API has timed out."
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -690,42 +624,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
|
|
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
assert redirected_to(conn, 302) ==
|
|
|
|
|
PlausibleWeb.Router.Helpers.site_path(
|
|
|
|
|
conn,
|
|
|
|
|
unquote(view),
|
|
|
|
|
site.domain
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
|
|
|
|
|
"Google Analytics API has timed out."
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -855,46 +753,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "does not start another import when there's any other in progress for the same site", %{
|
|
|
|
|
conn: conn,
|
|
|
|
|
site: site,
|
|
|
|
|
user: user
|
|
|
|
|
} do
|
|
|
|
|
{:ok, job} =
|
|
|
|
|
Plausible.Imported.NoopImporter.new_import(site, user,
|
|
|
|
|
start_date: ~D[2020-01-02],
|
|
|
|
|
end_date: ~D[2021-10-11]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
post(conn, "/#{site.domain}/settings/google-import", %{
|
|
|
|
|
"property_or_view" => "properties/123456",
|
|
|
|
|
"start_date" => "2018-03-01",
|
|
|
|
|
"end_date" => "2022-03-01",
|
|
|
|
|
"access_token" => "token",
|
|
|
|
|
"refresh_token" => "foo",
|
|
|
|
|
"expires_at" => "2022-09-22T20:01:37.112777",
|
|
|
|
|
"legacy" => "false"
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
conn =
|
|
|
|
|
post(conn, "/#{site.domain}/settings/google-import", %{
|
|
|
|
|
"property_or_view" => "123456",
|
|
|
|
|
"start_date" => "2018-03-01",
|
|
|
|
|
"end_date" => "2022-03-01",
|
|
|
|
|
"access_token" => "token",
|
|
|
|
|
"refresh_token" => "foo",
|
|
|
|
|
"expires_at" => "2022-09-22T20:01:37.112777",
|
|
|
|
|
"legacy" => "true"
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
|
|
|
|
|
"There's another import still in progress."
|
|
|
|
|
|
|
|
|
|
assert [%{id: import_id, legacy: false}] = Plausible.Imported.list_all_imports(site)
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|