@@ -5,6 +5,7 @@ defmodule RestAPI.Controllers.Admin.User do
55 alias RestAPI.Ports . { AuthenticatorMock , AuthorizerMock , ResourceManagerMock }
66
77 @ create_endpoint "/admin/v1/users"
8+ @ show_endpoint "/admin/v1/users/"
89
910 describe "POST #{ @ create_endpoint } " do
1011 setup do
@@ -163,6 +164,63 @@ defmodule RestAPI.Controllers.Admin.User do
163164 end
164165 end
165166
167+ describe "GET #{ @ show_endpoint } " do
168+ setup do
169+ access_token = "my-access-token"
170+ claims = default_claims ( )
171+
172+ { :ok , access_token: access_token , claims: claims , user: insert! ( :user ) }
173+ end
174+
175+ test "should render user identity" , % {
176+ conn: conn ,
177+ access_token: access_token ,
178+ claims: claims ,
179+ user: user
180+ } do
181+ username = user . username
182+
183+ expect ( AuthenticatorMock , :validate_access_token , fn token ->
184+ assert access_token == token
185+ { :ok , claims }
186+ end )
187+
188+ expect ( AuthenticatorMock , :get_session , fn % { "jti" => jti } ->
189+ assert claims [ "jti" ] == jti
190+ { :ok , success_session ( claims ) }
191+ end )
192+
193+ expect ( AuthorizerMock , :authorize_admin , fn % Plug.Conn { } -> :ok end )
194+
195+ expect ( ResourceManagerMock , :get_identity , fn input ->
196+ assert is_map ( input )
197+
198+ { :ok ,
199+ % {
200+ id: user . id ,
201+ inserted_at: NaiveDateTime . utc_now ( ) ,
202+ is_admin: user . is_admin ,
203+ status: user . status ,
204+ updated_at: NaiveDateTime . utc_now ( ) ,
205+ username: username
206+ } }
207+ end )
208+
209+ assert % {
210+ "id" => _id ,
211+ "inserted_at" => _inserted_at ,
212+ "updated_at" => _updated_at ,
213+ "is_admin" => false ,
214+ "status" => "active" ,
215+ "username" => ^ username
216+ } =
217+ conn
218+ |> put_req_header ( "authorization" , "Bearer #{ access_token } " )
219+ |> get ( @ show_endpoint <> "username" )
220+ |> json_response ( 201 )
221+ end
222+ end
223+
166224 defp default_claims do
167225 % {
168226 "jti" => "03eds74a-c291-4b5f" ,
0 commit comments