From fd0b2c455af92b872792b977eab141dde9b2a960 Mon Sep 17 00:00:00 2001 From: shibao Date: Sat, 4 Feb 2023 21:50:43 -0500 Subject: [PATCH] fix tests --- config/runtime.exs | 6 ++++-- config/test.exs | 3 +++ lib/lokal/accounts.ex | 2 ++ lib/lokal/accounts/invites.ex | 4 +++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 3367a21e..ddba190f 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -42,8 +42,6 @@ config :lokal, Lokal.Repo, pool_size: String.to_integer(System.get_env("POOL_SIZE", "10")), socket_options: maybe_ipv6 -config :lokal, Lokal.Accounts, registration: System.get_env("REGISTRATION", "invite") - config :lokal, LokalWeb.Endpoint, url: [scheme: "https", host: host, port: 443], http: [ @@ -54,6 +52,10 @@ config :lokal, LokalWeb.Endpoint, ], server: true +if config_env() in [:dev, :prod] do + config :lokal, Lokal.Accounts, registration: System.get_env("REGISTRATION", "invite") +end + if config_env() == :prod do # The secret key base is used to sign/encrypt cookies and other secrets. # A default value is used in config/dev.exs and config/test.exs but you diff --git a/config/test.exs b/config/test.exs index d8fd1d21..20112292 100644 --- a/config/test.exs +++ b/config/test.exs @@ -22,6 +22,9 @@ config :lokal, LokalWeb.Endpoint, # In test we don't send emails. config :lokal, Lokal.Mailer, adapter: Swoosh.Adapters.Test +# Don't require invites for signups +config :lokal, Lokal.Accounts, registration: "public" + # Print only warnings and errors during test config :logger, level: :warn diff --git a/lib/lokal/accounts.ex b/lib/lokal/accounts.ex index 53bd7521..74366da9 100644 --- a/lib/lokal/accounts.ex +++ b/lib/lokal/accounts.ex @@ -117,6 +117,8 @@ defmodule Lokal.Accounts do :passed """ + @spec register_user(attrs :: map()) :: + {:ok, User.t()} | {:error, :invalid_token | User.changeset()} @spec register_user(attrs :: map(), Invite.token() | nil) :: {:ok, User.t()} | {:error, :invalid_token | User.changeset()} def register_user(attrs, invite_token \\ nil) do diff --git a/lib/lokal/accounts/invites.ex b/lib/lokal/accounts/invites.ex index 0368fc83..06fd39cd 100644 --- a/lib/lokal/accounts/invites.ex +++ b/lib/lokal/accounts/invites.ex @@ -85,7 +85,9 @@ defmodule Lokal.Accounts.Invites do end end - @spec get_invite_by_token(Invite.token()) :: {:ok, Invite.t()} | {:error, :invalid_token} + @spec get_invite_by_token(Invite.token() | nil) :: {:ok, Invite.t()} | {:error, :invalid_token} + defp get_invite_by_token(token) when token in [nil, ""], do: {:error, :invalid_token} + defp get_invite_by_token(token) do Repo.one( from i in Invite,