Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/admin/notifications/localized_email.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule Admin.Notifications.LocalizedEmail do
localized_email
|> cast(attrs, [:subject, :message, :button_text, :button_url, :language])
|> validate_required([:subject, :message, :language])
|> validate_length(:button_url, max: 2048)
|> validate_inclusion(:language, ["en", "fr", "es", "it", "de"])
|> put_change(:notification_id, notification_id)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule Admin.Repo.Migrations.UpdateEmailMessageLength do
use Ecto.Migration

def change do
alter table(:localized_emails) do
modify :message, :varchar, from: :string
modify :button_url, :string, size: 2048
end
end
end
45 changes: 45 additions & 0 deletions test/admin/notifications_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,51 @@ defmodule Admin.NotificationsTest do
end
end

describe "localized emails" do
setup [:create_notification]

test "creates a localized email", %{scope: scope, notification: notification} do
assert {:ok, %Admin.Notifications.LocalizedEmail{} = localized_email} =
Notifications.create_localized_email(scope, notification.id, %{
subject: "example_subject",
message: "This is an example message",
button_text: "example_button_text",
button_url: "https://example.com",
language: "en"
})

assert localized_email.notification_id == notification.id
end

test "allows long messages", %{scope: scope, notification: notification} do
assert {:ok, %Admin.Notifications.LocalizedEmail{} = localized_email} =
Notifications.create_localized_email(scope, notification.id, %{
subject: "example_subject",
message: String.duplicate("a", 2050),
button_text: "example_button_text",
button_url: "https://example.com",
language: "en"
})

assert localized_email.notification_id == notification.id
end

test "errors for url too long", %{scope: scope, notification: notification} do
assert {:error, %Ecto.Changeset{} = changeset} =
Notifications.create_localized_email(scope, notification.id, %{
subject: "example_subject",
message: "This is an example message",
button_text: "example_button_text",
button_url: String.duplicate("a", 2050),
language: "en"
})

assert changeset.errors[:button_url] ==
{"should be at most %{count} character(s)",
[{:count, 2048}, {:validation, :length}, {:kind, :max}, {:type, :string}]}
end
end

defp create_notification(_) do
scope = user_scope_fixture()
notification = notification_fixture(scope)
Expand Down
12 changes: 8 additions & 4 deletions test/admin/publications_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ defmodule Admin.PublicationsTest do
use Admin.DataCase, async: false

alias Admin.Publications
alias Admin.Publications.PublishedItem

describe "published_items" do
alias Admin.Publications.PublishedItem
def without_thumbnail(%PublishedItem{thumbnails: nil} = published_item), do: published_item

def without_thumbnail(%PublishedItem{thumbnails: _} = published_item),
do: %{published_item | thumbnails: nil}

describe "published_items" do
import Admin.AccountsFixtures, only: [user_scope_fixture: 0]
import Admin.PublicationsFixtures
import Admin.ItemsFixtures, only: [item_fixture: 1]
Expand Down Expand Up @@ -33,8 +37,8 @@ defmodule Admin.PublicationsTest do
|> Admin.Publications.with_item()
|> Admin.Publications.with_creator()

assert Publications.get_published_item!(scope, published_item.id) ==
published_item
assert without_thumbnail(Publications.get_published_item!(scope, published_item.id)) ==
without_thumbnail(published_item)
end

test "create_published_item/2 with valid data creates a published_item" do
Expand Down
Loading