@@ -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,29 +164,21 @@ defmodule RestAPI.Controllers.Admin.User do
163164 end
164165 end
165166
166- describe "GET #{ @ create_endpoint } " do
167+ describe "GET #{ @ show_endpoint } " do
167168 setup do
168169 access_token = "my-access-token"
169170 claims = default_claims ( )
170171
171- { :ok , access_token: access_token , claims: claims }
172+ { :ok , access_token: access_token , claims: claims , user: insert! ( :user ) }
172173 end
173174
174- test "should render user identity response " , % {
175+ test "should render user identity" , % {
175176 conn: conn ,
176177 access_token: access_token ,
177- claims: claims
178+ claims: claims ,
179+ user: user
178180 } do
179- password = "MyP@ssword1234"
180-
181- params = % {
182- "username" => "Shurato" ,
183- "password" => password ,
184- "scopes" => [
185- "6a3a3771-9f56-4254-9497-927e441dacfc" ,
186- "8a235ba0-a827-4593-92c9-6248bef4fa06"
187- ]
188- }
181+ username = user . username
189182
190183 expect ( AuthenticatorMock , :validate_access_token , fn token ->
191184 assert access_token == token
@@ -197,41 +190,33 @@ defmodule RestAPI.Controllers.Admin.User do
197190 { :ok , success_session ( claims ) }
198191 end )
199192
200- expect ( ResourceManagerMock , :password_allowed? , fn _input ->
201- true
202- end )
203-
204- expect ( AuthenticatorMock , :generate_hash , fn password_to_hash , :argon2 ->
205- assert password == password_to_hash
206- "password_hashed"
207- end )
193+ expect ( AuthorizerMock , :authorize_admin , fn % Plug.Conn { } -> :ok end )
208194
209- expect ( ResourceManagerMock , :create_identity , fn input ->
195+ expect ( ResourceManagerMock , :get_identity , fn input ->
210196 assert is_map ( input )
211197
212198 { :ok ,
213199 % {
214- id: Ecto.UUID . generate ( ) ,
200+ id: user . id ,
215201 inserted_at: NaiveDateTime . utc_now ( ) ,
216- is_admin: false ,
217- status: "active" ,
202+ is_admin: user . is_admin ,
203+ status: user . status ,
218204 updated_at: NaiveDateTime . utc_now ( ) ,
219- username: "Shurato"
205+ username: username
220206 } }
221207 end )
222208
223- expect ( AuthorizerMock , :authorize_admin , fn % Plug.Conn { } -> :ok end )
224-
225209 assert % {
226210 "id" => _id ,
227211 "inserted_at" => _inserted_at ,
212+ "updated_at" => _updated_at ,
228213 "is_admin" => false ,
229214 "status" => "active" ,
230- "username" => "Shurato"
215+ "username" => ^ username
231216 } =
232217 conn
233218 |> put_req_header ( "authorization" , "Bearer #{ access_token } " )
234- |> post ( @ create_endpoint , params )
219+ |> get ( @ show_endpoint <> "username" )
235220 |> json_response ( 201 )
236221 end
237222 end
0 commit comments