Skip to content

Commit e3aaf45

Browse files
committed
feat: improve tests
1 parent de40cdb commit e3aaf45

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

apps/rest_api/test/controllers/admin/user_test.exs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,36 @@ defmodule RestAPI.Controllers.Admin.User do
219219
|> get(@show_endpoint <> "username")
220220
|> json_response(201)
221221
end
222+
223+
test "if id is not an id, should return error", %{
224+
conn: conn,
225+
access_token: access_token,
226+
claims: claims
227+
} do
228+
expect(AuthenticatorMock, :validate_access_token, fn token ->
229+
assert access_token == token
230+
{:ok, claims}
231+
end)
232+
233+
expect(AuthenticatorMock, :get_session, fn %{"jti" => jti} ->
234+
assert claims["jti"] == jti
235+
{:ok, success_session(claims)}
236+
end)
237+
238+
expect(AuthorizerMock, :authorize_admin, fn %Plug.Conn{} -> :ok end)
239+
240+
expect(ResourceManagerMock, :get_identity, fn input ->
241+
assert is_map(input)
242+
243+
{:error, :some_reason}
244+
end)
245+
246+
assert {:error, :some_areason} =
247+
conn
248+
|> put_req_header("authorization", "Bearer #{access_token}")
249+
|> get(@show_endpoint <> "1")
250+
|> json_response(201)
251+
end
222252
end
223253

224254
defp default_claims do

0 commit comments

Comments
 (0)