2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.StatsControllerTest do
|
|
|
|
use PlausibleWeb.ConnCase
|
|
|
|
use Plausible.Repo
|
|
|
|
import Plausible.TestUtils
|
|
|
|
|
|
|
|
describe "as an anonymous visitor" do
|
|
|
|
test "public site - shows site stats", %{conn: conn} do
|
|
|
|
insert(:site, domain: "public-site.io", public: true)
|
|
|
|
insert(:pageview, hostname: "public-site.io")
|
|
|
|
|
|
|
|
conn = get(conn, "/public-site.io")
|
2019-11-19 07:30:42 +03:00
|
|
|
assert html_response(conn, 200) =~ "stats-react-container"
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "can not view stats of a private website", %{conn: conn} do
|
|
|
|
insert(:pageview, hostname: "some-other-site.com")
|
|
|
|
|
|
|
|
conn = get(conn, "/some-other-site.com")
|
|
|
|
assert html_response(conn, 404) =~ "There's nothing here"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "as a logged in user" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
test "can view stats of a website I've created", %{conn: conn, site: site} do
|
|
|
|
insert(:pageview, hostname: site.domain)
|
|
|
|
|
|
|
|
conn = get(conn, "/" <> site.domain)
|
2019-11-19 07:30:42 +03:00
|
|
|
assert html_response(conn, 200) =~ "stats-react-container"
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
test "can not view stats of someone else's website", %{conn: conn} do
|
|
|
|
insert(:pageview, hostname: "some-other-site.com")
|
|
|
|
|
|
|
|
conn = get(conn, "/some-other-site.com")
|
|
|
|
assert html_response(conn, 404) =~ "There's nothing here"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|