Skip to content

Commit

Permalink
test: switch to using @example.com so e-mails work on the VPN
Browse files Browse the repository at this point in the history
Our e-mail validation library doesn't validate `@mbta.com` while on the
VPN:
```
iex(1)> EmailChecker.valid?("[email protected]")
false
```
  • Loading branch information
paulswartz committed Feb 22, 2024
1 parent 0bd542f commit ff123f8
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 89 deletions.
14 changes: 7 additions & 7 deletions apps/api_accounts/lib/api_accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ defmodule ApiAccounts do
## Examples
iex> get_user_by_email("test@mbta.com")
iex> get_user_by_email("test@example.com")
{:ok, %User{...}}
iex> get_user_by_email("bad@mbta.com")
iex> get_user_by_email("bad@example.com")
{:error, :not_found}
iex> get_user_by_email(%{email: "test@mbta.com"})
iex> get_user_by_email(%{email: "test@example.com"})
{:ok, %User{...}}
iex> get_user_by_email(%{email: "bad_addr"})
Expand Down Expand Up @@ -123,7 +123,7 @@ defmodule ApiAccounts do
## Examples
iex> get_user_by_email!("test@mbta.com")
iex> get_user_by_email!("test@example.com")
%User{...}
"""
Expand Down Expand Up @@ -516,13 +516,13 @@ defmodule ApiAccounts do
## Examples
iex> authenticate(%{email: "test@mbta.com", password: "password"})
iex> authenticate(%{email: "test@example.com", password: "password"})
{:ok, %User{...}}
iex> authenticate(%{email: "test@mbta.com", password: "password"})
iex> authenticate(%{email: "test@example.com", password: "password"})
{:continue, :totp, %User{...}}
iex> authenticate(%{email: "test@mbta.com", password: "wrong_password"})
iex> authenticate(%{email: "test@example.com", password: "wrong_password"})
{:error, :invalid_credentials}
iex> authenticate(%{email: "bad_id", password: "password"})
Expand Down
4 changes: 2 additions & 2 deletions apps/api_accounts/lib/api_accounts/changeset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ defmodule ApiAccounts.Changeset do
##Examples
iex> cast(%User{}, %{email: "test@mbta.com"}, ~w(email)a)
%Changeset{changes: %{email: "test@mbta.com"}, source: User, ...}
iex> cast(%User{}, %{email: "test@example.com"}, ~w(email)a)
%Changeset{changes: %{email: "test@example.com"}, source: User, ...}
"""
@spec cast(map, %{optional(atom) => term}, [atom]) :: t
Expand Down
2 changes: 1 addition & 1 deletion apps/api_accounts/lib/api_accounts/dynamo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ defmodule ApiAccounts.Dynamo do
## Examples
iex> query(User, "email = :email", %{email: "test@mbta.com"})
iex> query(User, "email = :email", %{email: "test@example.com"})
[...]
"""
Expand Down
16 changes: 8 additions & 8 deletions apps/api_accounts/test/api_accounts/changeset_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ApiAccounts.ChangesetTest do

@data %ApiAccounts.User{
username: "test",
email: "test@mbta.com"
email: "test@example.com"
}

test "change/1" do
Expand All @@ -21,13 +21,13 @@ defmodule ApiAccounts.ChangesetTest do
}

params = %{
email: "test2@mbta.com",
email: "test2@example.com",
role: "test",
join_date: DateTime.from_naive!(~N[2017-01-01T00:00:00], "Etc/UTC")
}

string_params = %{
"email" => "test2@mbta.com",
"email" => "test2@example.com",
"role" => "test",
"join_date" => date
}
Expand Down Expand Up @@ -116,7 +116,7 @@ defmodule ApiAccounts.ChangesetTest do
end

test "unique_contraint/2" do
params = %{email: "test@mbta.com"}
params = %{email: "test@example.com"}
changeset = Changeset.cast(@data, params, :email)
result = Changeset.unique_constraint(changeset, :email)

Expand Down Expand Up @@ -154,16 +154,16 @@ defmodule ApiAccounts.ChangesetTest do
assert result.valid? == true
end

test "marks as valid when supplying a real address on the mbta domain" do
params = %{email: "test@mbta.com"}
test "marks as valid when supplying a real address on the example domain" do
params = %{email: "test@example.com"}
changeset = Changeset.cast(@data, params, :email)
result = Changeset.validate_email(changeset, :email)
assert result.errors == %{}
assert result.valid? == true
end

test "marks as valid when supplying a real address with a plus on the mbta domain" do
params = %{email: "test+test@mbta.com"}
test "marks as valid when supplying a real address with a plus on the example domain" do
params = %{email: "test+test@example.com"}
changeset = Changeset.cast(@data, params, :email)
result = Changeset.validate_email(changeset, :email)
assert result.errors == %{}
Expand Down
12 changes: 6 additions & 6 deletions apps/api_accounts/test/api_accounts/dynamo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ defmodule ApiAccounts.DynamoTest do
end

test "update_item" do
user = put_user(id: "test", email: "test@mbta.com", phone: "1234567")
user = put_user(id: "test", email: "test@example.com", phone: "1234567")

expected_user =
user
Expand All @@ -92,7 +92,7 @@ defmodule ApiAccounts.DynamoTest do
end

test "update_item doesn't persist virtual fields" do
user = put_user(id: "test", email: "test@mbta.com", phone: "1234567")
user = put_user(id: "test", email: "test@example.com", phone: "1234567")
expected_user = Map.put(user, :phone, nil)

assert {:ok, expected_user} ==
Expand All @@ -110,7 +110,7 @@ defmodule ApiAccounts.DynamoTest do
end

test "delete_item" do
user = put_user(id: "test", email: "test@mbta.com")
user = put_user(id: "test", email: "test@example.com")
{:ok, ^user} = Dynamo.fetch_item(User, %{id: "test"})
assert Dynamo.delete_item(user) == :ok
assert {:error, :not_found} == Dynamo.fetch_item(User, %{id: "test"})
Expand Down Expand Up @@ -150,7 +150,7 @@ defmodule ApiAccounts.DynamoTest do
for i <- 1..5 do
user = %User{
id: "#{i}",
email: "#{i}@mbta.com",
email: "#{i}@example.com",
join_date: NaiveDateTime.utc_now(),
schema_version: 0
}
Expand Down Expand Up @@ -193,7 +193,7 @@ defmodule ApiAccounts.DynamoTest do

describe "decode/2" do
test "decodes items" do
expected_user = %User{email: "test@mbta.com"}
expected_user = %User{email: "test@example.com"}

attrs = %{
"email" => %{"S" => expected_user.email},
Expand All @@ -205,7 +205,7 @@ defmodule ApiAccounts.DynamoTest do
end

test "assigns a default schema version of 0 when none present" do
expected_user = %User{email: "test@mbta.com", schema_version: 0}
expected_user = %User{email: "test@example.com", schema_version: 0}
attrs = %{"email" => %{"S" => expected_user.email}}
assert Dynamo.decode(attrs, User) == expected_user
end
Expand Down
14 changes: 7 additions & 7 deletions apps/api_accounts/test/api_accounts/notifications_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ defmodule ApiAccounts.NotificationsTest do
alias ApiAccounts.{Key, Notifications, User}

test "send_password_reset/2" do
user = %User{email: "test@mbta.com"}
user = %User{email: "test@example.com"}
url = "http://localhost"
assert_delivered_email(Notifications.send_password_reset(user, url))
end

test "send_key_request_rejected/1" do
user = %User{email: "test@mbta.com"}
user = %User{email: "test@example.com"}
assert_delivered_email(Notifications.send_key_request_rejected(user))
end

test "send_key_request_approved/1" do
user = %User{email: "test@mbta.com"}
user = %User{email: "test@example.com"}
key = %Key{key: "key"}
url = "http://localhost"
assert_delivered_email(Notifications.send_key_request_approved(user, key, url))
end

test "send_key_requested/3" do
admins = [%User{email: "admin1@mbta.com"}, %User{email: "admin2@mbta.com"}]
user = %User{email: "test@mbta.com"}
admins = [%User{email: "admin1@example.com"}, %User{email: "admin2@example.com"}]
user = %User{email: "test@example.com"}
url = "http://localhost/"
assert_delivered_email(Notifications.send_key_requested(admins, user, url))
end

test "send_limit_increase_requested/4" do
admins = [%User{email: "admin1@mbta.com"}, %User{email: "admin2@mbta.com"}]
user = %User{email: "test@mbta.com"}
admins = [%User{email: "admin1@example.com"}, %User{email: "admin2@example.com"}]
user = %User{email: "test@example.com"}
key = %Key{user_id: user.id}
url = "http://localhost/"
reason = "My app is too popular"
Expand Down
8 changes: 4 additions & 4 deletions apps/api_accounts/test/api_accounts/table_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ defmodule ApiAccounts.TableTest do
end

test "generates function on module to retrieve pkey for module structs" do
model = %Model{email: "test@mbta.com"}
assert Model.pkey(model) == "test@mbta.com"
model = %Model{email: "test@example.com"}
assert Model.pkey(model) == "test@example.com"
end

test "generates function on module to create matcher for module structs" do
model = %Model{email: "test@mbta.com"}
assert Model.pkey_matcher(model) == %{email: "test@mbta.com"}
model = %Model{email: "test@example.com"}
assert Model.pkey_matcher(model) == %{email: "test@example.com"}
end

test "generates function on module to get table information" do
Expand Down
20 changes: 10 additions & 10 deletions apps/api_accounts/test/api_accounts/user_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ApiAccounts.UserTest do

test "changeset/2" do
changes = %{
email: "test@mbta.com",
email: "test@example.com",
role: "test",
username: "test",
phone: "test",
Expand All @@ -18,13 +18,13 @@ defmodule ApiAccounts.UserTest do
end

test "new/3 generates a unique ID for a user" do
changes = %{email: "test@mbta.com", password: "password"}
changes = %{email: "test@example.com", password: "password"}
changeset = User.new(%User{}, changes)
assert changeset.changes[:id] != nil
end

test "new/3 hashes an applied password" do
changes = %{email: "test@mbta.com", password: "password"}
changes = %{email: "test@example.com", password: "password"}

changeset = User.new(%User{}, changes)
refute changeset.changes.password == changes.password
Expand All @@ -45,15 +45,15 @@ defmodule ApiAccounts.UserTest do
assert Enum.at(result.errors.password, 0) =~ "required"
refute result.valid?

params = %{email: "test@mbta.com", password: "password"}
params = %{email: "test@example.com", password: "password"}
result = User.authenticate(%User{}, params)
assert result.errors == %{}
assert result.valid?
end

describe "register/2" do
@register_params %{
email: "test@mbta.com",
email: "test@example.com",
password: "password",
password_confirmation: "password"
}
Expand All @@ -68,7 +68,7 @@ defmodule ApiAccounts.UserTest do

test "enforces minimum password length" do
params = %{
email: "test@mbta.com",
email: "test@example.com",
password: "short",
password_confirmation: "short"
}
Expand All @@ -93,9 +93,9 @@ defmodule ApiAccounts.UserTest do
end

test "trims and downcases email addresses" do
params = Map.put(@register_params, :email, " TEST@mBtA.CoM ")
params = Map.put(@register_params, :email, " TEST@example.com ")
result = User.register(%User{}, params)
assert result.changes.email == "test@mbta.com"
assert result.changes.email == "test@example.com"
assert result.valid?
end

Expand Down Expand Up @@ -170,8 +170,8 @@ defmodule ApiAccounts.UserTest do
end

test "trims and downcases email addresses" do
result = User.account_recovery(%{email: " TEST@mBtA.CoM "})
assert result.changes.email == "test@mbta.com"
result = User.account_recovery(%{email: " TEST@eXaMpLe.com "})
assert result.changes.email == "test@example.com"
assert result.valid?
end
end
Expand Down
Loading

0 comments on commit ff123f8

Please sign in to comment.