From cd8df23e5e82df206b2a20dafb64383f07807476 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Fri, 6 May 2022 10:20:35 +0300 Subject: [PATCH] Do not rely on insertion order in tests --- lib/plausible/stats/imported.ex | 2 +- test/plausible/imported/imported_test.exs | 7 ++++--- .../api/external_stats_controller/breakdown_test.exs | 12 +++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/plausible/stats/imported.ex b/lib/plausible/stats/imported.ex index 52cd58634..c96684e18 100644 --- a/lib/plausible/stats/imported.ex +++ b/lib/plausible/stats/imported.ex @@ -408,7 +408,7 @@ defmodule Plausible.Stats.Imported do |> select_merge([s, i], %{ visit_duration: fragment( - "(? + ? * ?) / (? + ?)", + "round((? + ? * ?) / (? + ?), 1)", i.visit_duration, s.visit_duration, s.visits, diff --git a/test/plausible/imported/imported_test.exs b/test/plausible/imported/imported_test.exs index 7cbd07586..5bc8bd0c2 100644 --- a/test/plausible/imported/imported_test.exs +++ b/test/plausible/imported/imported_test.exs @@ -211,6 +211,7 @@ defmodule Plausible.ImportedTest do test "UTM terms data imported from Google Analytics", %{conn: conn, site: site} do populate_stats(site, [ build(:pageview, utm_term: "oat milk", timestamp: ~N[2021-01-01 00:00:00]), + build(:pageview, utm_term: "Sweden", timestamp: ~N[2021-01-01 00:00:00]), build(:pageview, utm_term: "Sweden", timestamp: ~N[2021-01-01 00:00:00]) ]) @@ -243,9 +244,9 @@ defmodule Plausible.ImportedTest do assert json_response(conn, 200) == [ %{ "name" => "Sweden", - "visitors" => 2, - "bounce_rate" => 50.0, - "visit_duration" => 50.0 + "visitors" => 3, + "bounce_rate" => 67.0, + "visit_duration" => 33.3 }, %{ "name" => "oat milk", diff --git a/test/plausible_web/controllers/api/external_stats_controller/breakdown_test.exs b/test/plausible_web/controllers/api/external_stats_controller/breakdown_test.exs index 83b722d88..e6b41b03e 100644 --- a/test/plausible_web/controllers/api/external_stats_controller/breakdown_test.exs +++ b/test/plausible_web/controllers/api/external_stats_controller/breakdown_test.exs @@ -606,7 +606,6 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do build(:pageview, domain: site.domain, pathname: "/non-existing", - user_id: @user_id, timestamp: ~N[2021-01-01 00:00:01] ), build(:pageview, @@ -641,7 +640,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do assert json_response(conn, 200) == %{ "results" => [ - %{"name" => "pageview", "visitors" => 1, "events" => 4}, + %{"name" => "pageview", "visitors" => 2, "events" => 4}, %{"name" => "404", "visitors" => 1, "events" => 2} ] } @@ -922,6 +921,13 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do domain: site.domain, timestamp: ~N[2021-01-01 00:00:00] ), + build(:event, + name: "Purchase", + "meta.key": ["cost"], + "meta.value": ["16"], + domain: site.domain, + timestamp: ~N[2021-01-01 00:00:00] + ), build(:event, name: "Purchase", domain: site.domain, @@ -954,7 +960,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do assert json_response(conn, 200) == %{ "results" => [ - %{"cost" => "16", "visitors" => 2}, + %{"cost" => "16", "visitors" => 3}, %{"cost" => "14", "visitors" => 2}, %{"cost" => "(none)", "visitors" => 1} ]