Skip to content

Commit

Permalink
refactor: current response
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm committed Feb 4, 2024
1 parent 2e77f90 commit 3223e96
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/safira_web/controllers/spotlight/spotlight_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ defmodule SafiraWeb.SpotlightJSON do
end

def current(%{company: company, spotlight: spotlight}) do
data =
data(company, spotlight)
|> Map.drop([:remaining])
|> Map.put(:badge_id, company.badge_id)

%{
data: data(company, spotlight)
data: data
}
end

Expand Down
27 changes: 26 additions & 1 deletion test/safira_web/controllers/spotlight_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ defmodule SafiraWeb.SpotlightControllerTest do
"data" => %{
"id" => company.id,
"name" => company.name,
"remaining" => company.remaining_spotlights,
"badge_id" => company.badge_id,
"end" => DateTime.to_iso8601(spotlight.end)
}
}
Expand Down Expand Up @@ -260,6 +260,31 @@ defmodule SafiraWeb.SpotlightControllerTest do
assert json_response(conn, 404) == %{"error" => "Spotlight not found"}
end

test "when user is an attendee and a spotlight is running", %{user: user} do
_staff = insert(:staff, user: user, is_admin: true)
company = insert(:company, remaining_spotlights: 1)

%{conn: conn, user: _user} = api_authenticate(user)

# Start a spotlight for the company
Interaction.start_spotlight(company)
spotlight = Interaction.get_spotlight()
assert spotlight != nil

conn =
conn
|> get(Routes.spotlight_path(conn, :current))

assert json_response(conn, 200) == %{
"data" => %{
"id" => company.id,
"name" => company.name,
"badge_id" => company.badge_id,
"end" => DateTime.to_iso8601(spotlight.end)
}
}
end

test "when user is a company", %{user: user} do
_company = insert(:company, user: user)

Expand Down

0 comments on commit 3223e96

Please sign in to comment.