Skip to content

Commit db6f013

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

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,40 @@ 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, {:error, :invalid_params}}
244+
end)
245+
246+
assert %{
247+
"detail" => "The given parameters are invalid",
248+
"error" => "bad_request",
249+
"status" => 400
250+
} =
251+
conn
252+
|> put_req_header("authorization", "Bearer #{access_token}")
253+
|> get(@show_endpoint <> "1")
254+
|> json_response(400)
255+
end
222256
end
223257

224258
defp default_claims do

0 commit comments

Comments
 (0)