Skip to content

Commit

Permalink
Add ability to list checks
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Jun 24, 2024
1 parent aa5d3a7 commit 9746776
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/polar/machines.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ defmodule Polar.Machines do

alias __MODULE__.Check

defdelegate list_checks(),
to: Check.Manager,
as: :list

defdelegate create_check(params),
to: Check.Manager,
as: :create
Expand Down
4 changes: 4 additions & 0 deletions lib/polar/machines/check/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ defmodule Polar.Machines.Check.Manager do
alias Polar.Repo
alias Polar.Machines.Check

def list() do
Repo.all(Check)
end

def create(params) do
%Check{}
|> Check.changeset(params)
Expand Down
11 changes: 11 additions & 0 deletions lib/polar_web/controllers/publish/testing/check_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule PolarWeb.Publish.Testing.CheckController do
use PolarWeb, :controller

alias Polar.Machines

def index(conn, _params) do
checks = Machines.list_checks()

render(conn, :index, %{checks: checks})
end
end
11 changes: 11 additions & 0 deletions lib/polar_web/controllers/publish/testing/check_json.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule PolarWeb.Publish.Testing.CheckJSON do
alias Polar.Machines.Check

def index(%{checks: checks}) do
%{data: Enum.map(checks, &data/1)}
end

def data(%Check{} = check) do
%{id: check.id, slug: check.slug}
end
end
1 change: 1 addition & 0 deletions lib/polar_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ defmodule PolarWeb.Router do
resources "/versions/:version_id/events", EventController, only: [:create]

scope "/testing", as: :testing do
resources "/checks", Testing.CheckController, only: [:index]
resources "/clusters", Testing.ClusterController, only: [:index]

resources "/assessments/:assessment_id/events", EventController, only: [:create]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule PolarWeb.Publish.Version.EventControllerTest do
defmodule PolarWeb.Publish.EventControllerTest do
use PolarWeb.ConnCase

import Polar.AccountsFixtures
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
defmodule PolarWeb.Publish.Testing.CheckControllerTest do
use PolarWeb.ConnCase

alias Polar.Accounts
alias Polar.Machines

import Polar.AccountsFixtures

setup do
password = Accounts.generate_automation_password()

bot = bot_fixture(%{password: password})

user = Accounts.get_user_by_email_and_password(bot.email, password)

session_token =
Accounts.generate_user_session_token(user)
|> Base.encode64()

conn =
build_conn()
|> put_req_header("authorization", session_token)

{:ok, _check} =
Machines.create_check(%{
name: "ipv4-issuing",
description: "checks that ipv4 is correctly issued"
})

{:ok, conn: conn}
end

describe "GET /publish/testing/checks" do
test "get list of available checks", %{conn: conn} do
conn = get(conn, "/publish/testing/checks")

assert %{"data" => data} = json_response(conn, 200)

assert Enum.count(data) == 1
end
end
end

0 comments on commit 9746776

Please sign in to comment.