mirror of
https://github.com/plausible/analytics.git
synced 2024-12-26 02:55:02 +03:00
5de43b758d
* Set pg pool size for MIX_ENV=test
* Include slow tests in CI run
* Exclude slow tests by default
* Mark tests slow/async where applicable
* Restructure captcha mocks
* Revert async where env is relied upon
* Add --max-failures=1 to CI run
* Set warnings as errors
* Disable async where various mocks are used
* Revert "Disable async where various mocks are used"
This reverts commit 2446b72a29
.
* Disable async for test using vcr
49 lines
1.4 KiB
Elixir
49 lines
1.4 KiB
Elixir
defmodule PlausibleWeb.Api.InternalControllerTest do
|
|
use PlausibleWeb.ConnCase, async: true
|
|
use Plausible.Repo
|
|
|
|
describe "GET /api/:domain/status" do
|
|
setup [:create_user, :log_in]
|
|
|
|
test "is WAITING when site has no pageviews", %{conn: conn, user: user} do
|
|
site = insert(:site, members: [user])
|
|
conn = get(conn, "/api/#{site.domain}/status")
|
|
|
|
assert json_response(conn, 200) == "WAITING"
|
|
end
|
|
|
|
test "is READY when site has at least 1 pageview", %{conn: conn, user: user} do
|
|
site = insert(:site, members: [user])
|
|
Plausible.TestUtils.create_pageviews([%{domain: site.domain}])
|
|
|
|
conn = get(conn, "/api/#{site.domain}/status")
|
|
|
|
assert json_response(conn, 200) == "READY"
|
|
end
|
|
end
|
|
|
|
describe "GET /api/sites" do
|
|
setup [:create_user, :log_in]
|
|
|
|
test "returns a list of site domains for the current user", %{conn: conn, user: user} do
|
|
site = insert(:site, members: [user])
|
|
site2 = insert(:site, members: [user])
|
|
conn = get(conn, "/api/sites")
|
|
|
|
%{"data" => sites} = json_response(conn, 200)
|
|
|
|
assert Enum.map(sites, & &1["domain"]) == [site.domain, site2.domain]
|
|
end
|
|
end
|
|
|
|
describe "GET /api/sites - user not logged in" do
|
|
test "returns 401 unauthorized", %{conn: conn} do
|
|
conn = get(conn, "/api/sites")
|
|
|
|
assert json_response(conn, 401) == %{
|
|
"error" => "You need to be logged in to request a list of sites"
|
|
}
|
|
end
|
|
end
|
|
end
|