defmodule VigilWeb.MonitorApiTest do
use VigilWeb.ConnCase, async: true
import Vigil.AccountsFixtures
import Vigil.OrganizationsFixtures
alias Vigil.{ApiTokens, Monitors}
test "monitors of visible projects, in Sentry's shape", %{conn: conn} do
owner = user_fixture()
org = organization_fixture(owner)
project = project_fixture(org_scope(owner, org), %{"name" => "web"})
Monitors.check_in(project, %{
"monitor_slug" => "nightly",
"status" => "ok",
"monitor_config" => %{"schedule" => %{"type" => "crontab", "value" => "0 3 * * *"}}
})
{:ok, t} = ApiTokens.create_token(owner, %{label: "cli", scopes: ["project:read"]})
assert [
%{
"slug" => "nightly",
"status" => "active",
"config" => %{"schedule" => "0 3 * * *"}
}
] =
conn
|> put_req_header("authorization", "Bearer " <> t.token)
|> get("/api/0/organizations/#{org.slug}/monitors/")
|> json_response(200)
# A member whose teams don't include the project sees none of it.
member = member_fixture(org, nil, :member)
{:ok, mt} = ApiTokens.create_token(member.user, %{label: "m", scopes: ["project:read"]})
org = Vigil.Repo.reload!(org)
body =
build_conn()
|> put_req_header("authorization", "Bearer " <> mt.token)
|> get("/api/0/organizations/#{org.slug}/monitors/")
|> json_response(200)
if org.open_membership, do: assert([_] = body), else: assert(body == [])
end
end
neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions running · Badges · Packages
⭐
Log in to mark this repository.
1.5 KiB · text
History
bbb2a48