mirror of
				https://github.com/livebook-dev/livebook.git
				synced 2025-11-04 10:26:08 +08:00 
			
		
		
		
	Fix user information to include payload returned from identity provider (#2890)
This commit is contained in:
		
							parent
							
								
									dba7cbf7be
								
							
						
					
					
						commit
						2d9b6f8dac
					
				
					 2 changed files with 10 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -42,13 +42,14 @@ defmodule Livebook.Users.User do
 | 
			
		|||
      name: nil,
 | 
			
		||||
      email: nil,
 | 
			
		||||
      avatar_url: nil,
 | 
			
		||||
      payload: nil,
 | 
			
		||||
      hex_color: Livebook.EctoTypes.HexColor.random()
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def changeset(user, attrs \\ %{}) do
 | 
			
		||||
    user
 | 
			
		||||
    |> cast(attrs, [:name, :email, :avatar_url, :hex_color])
 | 
			
		||||
    |> cast(attrs, [:name, :email, :avatar_url, :hex_color, :payload])
 | 
			
		||||
    |> validate_required([:hex_color])
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,12 +6,19 @@ defmodule Livebook.Users.UserTest do
 | 
			
		|||
  describe "change/2" do
 | 
			
		||||
    test "given valid attributes returns and updated user" do
 | 
			
		||||
      user = build(:user)
 | 
			
		||||
      attrs = %{"name" => "Jake Peralta", "hex_color" => "#000000"}
 | 
			
		||||
 | 
			
		||||
      attrs = %{
 | 
			
		||||
        "name" => "Jake Peralta",
 | 
			
		||||
        "hex_color" => "#000000",
 | 
			
		||||
        "payload" => %{"country" => "US"}
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      changeset = User.changeset(user, attrs)
 | 
			
		||||
 | 
			
		||||
      assert changeset.valid?
 | 
			
		||||
      assert get_field(changeset, :name) == "Jake Peralta"
 | 
			
		||||
      assert get_field(changeset, :hex_color) == "#000000"
 | 
			
		||||
      assert get_field(changeset, :payload) == %{"country" => "US"}
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "given invalid color returns an error" do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue