diff --git a/lib/towerops/accounts/user.ex b/lib/towerops/accounts/user.ex index d61a819c..7d3341e8 100644 --- a/lib/towerops/accounts/user.ex +++ b/lib/towerops/accounts/user.ex @@ -24,7 +24,7 @@ defmodule Towerops.Accounts.User do field :authenticated_at, :utc_datetime, virtual: true field :is_superuser, :boolean, default: false field :name, :string - field :timezone, :string + field :timezone, :string, default: "UTC" field :totp_secret, :binary, redact: true field :totp_verified_at, :utc_datetime, virtual: true field :privacy_policy_consent, :boolean, virtual: true @@ -122,7 +122,7 @@ defmodule Towerops.Accounts.User do """ def registration_changeset(user, attrs, opts \\ []) do user - |> cast(attrs, [:email, :password, :privacy_policy_consent, :terms_of_service_consent]) + |> cast(attrs, [:email, :password, :timezone, :privacy_policy_consent, :terms_of_service_consent]) |> validate_email_for_registration(opts) |> validate_password(opts) |> validate_consent() diff --git a/test/towerops/accounts_test.exs b/test/towerops/accounts_test.exs index 7ab57f43..84e576a5 100644 --- a/test/towerops/accounts_test.exs +++ b/test/towerops/accounts_test.exs @@ -772,4 +772,33 @@ defmodule Towerops.AccountsTest do assert 11 = Accounts.count_unused_recovery_codes(user.id) end end + + describe "register_user_with_organization/1" do + test "accepts timezone in registration params" do + valid_attrs = %{ + "email" => "user@example.com", + "password" => "a valid password", + "privacy_policy_consent" => true, + "terms_of_service_consent" => true, + "organization_name" => "Test Org", + "timezone" => "America/Chicago" + } + + assert {:ok, user} = Accounts.register_user_with_organization(valid_attrs) + assert user.timezone == "America/Chicago" + end + + test "defaults to UTC when timezone not provided" do + valid_attrs = %{ + "email" => "user@example.com", + "password" => "a valid password", + "privacy_policy_consent" => true, + "terms_of_service_consent" => true, + "organization_name" => "Test Org" + } + + assert {:ok, user} = Accounts.register_user_with_organization(valid_attrs) + assert user.timezone == "UTC" + end + end end