Skip to content

Commit

Permalink
add institution info controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
nmenag committed Mar 29, 2024
1 parent 2ed9bc9 commit b697a17
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ defmodule Web.Onboarding.InstitutionInfoJSON do
"""

def show(%{institution_info: institution_info}) do
%{data: %{name: institution_info.name, created_at: institution_info.inserted_at}}
%{data: %{name: institution_info.name}}
end
end
6 changes: 4 additions & 2 deletions apps/web/test/web/controllers/enrollments_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,17 @@ defmodule Web.EnrollmentsControllerTest do
end

describe "delete/2" do
test "unauthorized", %{user: user} do
test "unauthorized", %{user: user, course: course} do
enrollment = insert!(:enrollment, course_id: course.uuid, user_id: user.uuid)

{:ok, token, _} = encode_and_sign(user, %{}, token_type: :access)

conn =
session_conn()
|> put_session(:user_id, user.uuid)
|> put_req_header("accept", "application/json")
|> put_req_header("authorization", "Bearer " <> token)
|> delete(~p"/api/enrollments")
|> delete(~p"/api/enrollments/#{enrollment.uuid}")

assert json_response(conn, 403)["errors"] == %{"detail" => "Forbidden resource"}
end
Expand Down
32 changes: 32 additions & 0 deletions apps/web/test/web/controllers/institution_info_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
defmodule Web.InstitutionInfoControllerTest do
use ExUnit.Case
use Core.DataCase
use Web.ConnCase

import Web.Auth.Guardian
import Core.Factory

setup do
institution = insert!(:institution_info)
organizer = insert!(:user, role: :organizer)

{:ok, institution: institution, organizer: organizer}
end

describe "show/2" do
test "display institution info", %{organizer: organizer, institution: institution} do
{:ok, token, _} = encode_and_sign(organizer, %{}, token_type: :access)

conn =
session_conn()
|> put_session(:user_id, organizer.uuid)
|> put_req_header("accept", "application/json")
|> put_req_header("authorization", "Bearer " <> token)
|> get(~p"/api/onboarding/institution_info")

response = json_response(conn, 200)["data"]

assert response == %{"name" => institution.name}
end
end
end

0 comments on commit b697a17

Please sign in to comment.