Skip to content

Commit

Permalink
[identity] fix user metadata edition
Browse files Browse the repository at this point in the history
  • Loading branch information
patatoid committed Nov 17, 2024
1 parent 0605b09 commit 254c8b4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ defmodule BorutaIdentity.Accounts.User do
_ -> false
end)
|> Enum.map(fn
{_key, value} when is_map(value) -> value
{key, value} when is_map(value) -> {key, value}
{key, value} ->
{key, %{"value" => value, "status" => "valid"}}
# TODO default display
{key, %{"value" => value, "status" => "valid", "display" => []}}
end)
|> Enum.into(%{})
end
Expand Down
22 changes: 18 additions & 4 deletions apps/boruta_identity/test/boruta_identity/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ defmodule BorutaIdentity.AccountsTest do
DummyRegistration
)

assert user.metadata == %{"test" => %{"value" => "test value", "status" => "valid"}}
assert user.metadata == %{
"test" => %{"value" => "test value", "status" => "valid", "display" => []}
}
end

test "registers users with default organization", %{client_id: client_id, backend: backend} do
Expand Down Expand Up @@ -1620,10 +1622,19 @@ defmodule BorutaIdentity.AccountsTest do
)
end

test "updates user with metadata", %{client_id: client_id, user: user, backend: backend} do
test "updates user with metadata", %{client_id: client_id, backend: backend} do
user =
user_fixture(%{
backend: backend,
metadata: %{"other" => %{"value" => "other", "status" => "valid", "display" => []}}
})

{:ok, _backend} =
Ecto.Changeset.change(backend, %{
metadata_fields: [%{"attribute_name" => "test", "user_editable" => true}]
metadata_fields: [
%{"attribute_name" => "other", "user_editable" => false},
%{"attribute_name" => "test", "user_editable" => true}
]
})
|> Repo.update()

Expand All @@ -1634,7 +1645,10 @@ defmodule BorutaIdentity.AccountsTest do
assert {:user_updated, :context,
%User{
username: ^updated_email,
metadata: %{"test" => %{"value" => "test value", "status" => "valid"}}
metadata: %{
"test" => %{"value" => "test value", "status" => "valid", "display" => []},
"other" => %{"value" => "other", "status" => "valid", "display" => []}
}
}} =
Accounts.update_user(
:context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ defmodule BorutaIdentity.AccountsFixtures do
username: user.email,
uid: user.id,
backend: backend,
account_type: account_type
account_type: account_type,
metadata: attrs[:metadata] || %{}
)
|> Repo.preload([:backend, :authorized_scopes, :roles, :organizations])
end
Expand Down

0 comments on commit 254c8b4

Please sign in to comment.