2019-11-19 07:30:42 +03:00
|
|
|
defmodule PlausibleWeb.Api.StatsController.PagesTest do
|
|
|
|
use PlausibleWeb.ConnCase
|
|
|
|
import Plausible.TestUtils
|
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/pages" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
test "returns top pages sources by pageviews", %{conn: conn, site: site} do
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/pages?period=day&date=2019-01-01")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-05-18 12:44:52 +03:00
|
|
|
%{"count" => 2, "name" => "/"},
|
|
|
|
%{"count" => 2, "name" => "/register"},
|
|
|
|
%{"count" => 1, "name" => "/contact"},
|
|
|
|
%{"count" => 1, "name" => "/irrelevant"}
|
2019-11-19 07:30:42 +03:00
|
|
|
]
|
|
|
|
end
|
2020-01-06 16:51:43 +03:00
|
|
|
|
|
|
|
test "calculates bounce rate for pages", %{conn: conn, site: site} do
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/pages?period=day&date=2019-01-01&include=bounce_rate")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-05-18 12:44:52 +03:00
|
|
|
%{"count" => 2, "name" => "/", "bounce_rate" => 50.0},
|
|
|
|
%{"bounce_rate" => nil, "count" => 2, "name" => "/register"},
|
|
|
|
%{"bounce_rate" => nil, "count" => 1, "name" => "/contact"},
|
|
|
|
%{"bounce_rate" => nil, "count" => 1, "name" => "/irrelevant"}
|
2020-01-06 16:51:43 +03:00
|
|
|
]
|
|
|
|
end
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|
|
|
|
end
|