Delete test/plausible_web/controllers/api/internal_controller/docs_query_test.exs with huggingface_hub
Browse files
test/plausible_web/controllers/api/internal_controller/docs_query_test.exs
DELETED
|
@@ -1,108 +0,0 @@
|
|
| 1 |
-
defmodule PlausibleWeb.Api.InternalController.DocsQueryTest do
|
| 2 |
-
use PlausibleWeb.ConnCase, async: true
|
| 3 |
-
use Plausible.Repo
|
| 4 |
-
@user_id Enum.random(1000..9999)
|
| 5 |
-
|
| 6 |
-
describe "POST /api/docs/query not logged in" do
|
| 7 |
-
setup [:create_user, :create_site]
|
| 8 |
-
|
| 9 |
-
test "rejects request when not logged in", %{conn: conn, site: site} do
|
| 10 |
-
populate_stats(site, [
|
| 11 |
-
build(:pageview, timestamp: ~N[2021-01-01 00:00:00])
|
| 12 |
-
])
|
| 13 |
-
|
| 14 |
-
conn =
|
| 15 |
-
post(conn, "/api/docs/query", %{
|
| 16 |
-
"site_id" => site.domain,
|
| 17 |
-
"metrics" => ["pageviews"],
|
| 18 |
-
"date_range" => "all"
|
| 19 |
-
})
|
| 20 |
-
|
| 21 |
-
assert json_response(conn, 404) == %{
|
| 22 |
-
"error" => "Site does not exist or user does not have sufficient access."
|
| 23 |
-
}
|
| 24 |
-
end
|
| 25 |
-
end
|
| 26 |
-
|
| 27 |
-
describe "POST /api/docs/query logged in" do
|
| 28 |
-
setup [:create_user, :create_site, :log_in]
|
| 29 |
-
|
| 30 |
-
test "rejects when accessing any other site", %{conn: conn} do
|
| 31 |
-
conn =
|
| 32 |
-
post(conn, "/api/docs/query", %{
|
| 33 |
-
"site_id" => "any.other.site",
|
| 34 |
-
"metrics" => ["pageviews"],
|
| 35 |
-
"date_range" => "all"
|
| 36 |
-
})
|
| 37 |
-
|
| 38 |
-
assert json_response(conn, 404) == %{
|
| 39 |
-
"error" => "Site does not exist or user does not have sufficient access."
|
| 40 |
-
}
|
| 41 |
-
end
|
| 42 |
-
|
| 43 |
-
test "rejects when using invalid param name", %{conn: conn, site: site} do
|
| 44 |
-
conn =
|
| 45 |
-
post(conn, "/api/docs/query", %{
|
| 46 |
-
"domain" => site.domain,
|
| 47 |
-
"metrics" => ["pageviews"],
|
| 48 |
-
"date_range" => "all"
|
| 49 |
-
})
|
| 50 |
-
|
| 51 |
-
assert json_response(conn, 404) == %{
|
| 52 |
-
"error" => "Site does not exist or user does not have sufficient access."
|
| 53 |
-
}
|
| 54 |
-
end
|
| 55 |
-
|
| 56 |
-
test "returns aggregated metrics when site id given", %{conn: conn, site: site} do
|
| 57 |
-
populate_stats(site, [
|
| 58 |
-
build(:pageview, user_id: @user_id, timestamp: ~N[2021-01-01 00:00:00]),
|
| 59 |
-
build(:pageview, user_id: @user_id, timestamp: ~N[2021-01-01 00:25:00]),
|
| 60 |
-
build(:pageview, timestamp: ~N[2021-01-01 00:00:00])
|
| 61 |
-
])
|
| 62 |
-
|
| 63 |
-
conn =
|
| 64 |
-
post(conn, "/api/docs/query?site_id=ignored_when_site_id_present_in_body", %{
|
| 65 |
-
"site_id" => site.domain,
|
| 66 |
-
"metrics" => ["pageviews"],
|
| 67 |
-
"date_range" => "all"
|
| 68 |
-
})
|
| 69 |
-
|
| 70 |
-
assert json_response(conn, 200)["results"] == [%{"metrics" => [3], "dimensions" => []}]
|
| 71 |
-
end
|
| 72 |
-
|
| 73 |
-
test "succeeds when site_id missing in body, but present in query params", %{
|
| 74 |
-
conn: conn,
|
| 75 |
-
site: site
|
| 76 |
-
} do
|
| 77 |
-
populate_stats(site, [
|
| 78 |
-
build(:pageview, user_id: @user_id, timestamp: ~N[2021-01-01 00:00:00])
|
| 79 |
-
])
|
| 80 |
-
|
| 81 |
-
conn =
|
| 82 |
-
post(conn, "/api/docs/query?site_id=#{site.domain}", %{
|
| 83 |
-
"metrics" => ["pageviews"],
|
| 84 |
-
"date_range" => "all"
|
| 85 |
-
})
|
| 86 |
-
|
| 87 |
-
assert json_response(conn, 200)["results"] == [%{"metrics" => [1], "dimensions" => []}]
|
| 88 |
-
end
|
| 89 |
-
|
| 90 |
-
test "supports 24h date_range shorthand", %{conn: conn, site: site} do
|
| 91 |
-
now = NaiveDateTime.utc_now()
|
| 92 |
-
|
| 93 |
-
populate_stats(site, [
|
| 94 |
-
build(:pageview, timestamp: NaiveDateTime.add(now, -23, :hour)),
|
| 95 |
-
build(:pageview, timestamp: NaiveDateTime.add(now, -25, :hour))
|
| 96 |
-
])
|
| 97 |
-
|
| 98 |
-
conn =
|
| 99 |
-
post(conn, "/api/docs/query", %{
|
| 100 |
-
"site_id" => site.domain,
|
| 101 |
-
"metrics" => ["pageviews"],
|
| 102 |
-
"date_range" => "24h"
|
| 103 |
-
})
|
| 104 |
-
|
| 105 |
-
assert json_response(conn, 200)["results"] == [%{"metrics" => [1], "dimensions" => []}]
|
| 106 |
-
end
|
| 107 |
-
end
|
| 108 |
-
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|