Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 3cc2483

Browse files
committed
refactor(mailer): fix test error & mv send logic to later
1 parent 988eed4 commit 3cc2483

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

lib/groupher_server/cms/delegates/article_curd.ex

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -398,30 +398,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
398398
end
399399

400400
defp create_content_result({:ok, %{create_content: result}}) do
401-
# Later.exec({__MODULE__, :nofify_admin_new_content, [result]})
402-
nofify_admin_new_content(result)
401+
Later.exec({__MODULE__, :nofify_admin_new_content, [result]})
403402
{:ok, result}
404403
end
405404

406-
def nofify_admin_new_content(%{id: id} = result) do
407-
target = result.__struct__
408-
preload = [:origial_community, author: :user]
409-
410-
with {:ok, content} <- ORM.find(target, id, preload: preload) do
411-
info = %{
412-
id: content.id,
413-
title: content.title,
414-
digest: content.digest,
415-
author_name: content.author.user.nickname,
416-
community_raw: content.origial_community.raw,
417-
type:
418-
result.__struct__ |> to_string |> String.split(".") |> List.last() |> String.downcase()
419-
}
420-
421-
Email.notify_admin(info, :new_content)
422-
end
423-
end
424-
425405
defp create_content_result({:error, :create_content, %Ecto.Changeset{} = result, _steps}) do
426406
{:error, result}
427407
end
@@ -516,4 +496,23 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
516496
defp content_id(:job, id), do: %{job_id: id}
517497
defp content_id(:repo, id), do: %{repo_id: id}
518498
defp content_id(:video, id), do: %{video_id: id}
499+
500+
defp nofify_admin_new_content(%{id: id} = result) do
501+
target = result.__struct__
502+
preload = [:origial_community, author: :user]
503+
504+
with {:ok, content} <- ORM.find(target, id, preload: preload) do
505+
info = %{
506+
id: content.id,
507+
title: content.title,
508+
digest: Map.get(content, :digest, content.title),
509+
author_name: content.author.user.nickname,
510+
community_raw: content.origial_community.raw,
511+
type:
512+
result.__struct__ |> to_string |> String.split(".") |> List.last() |> String.downcase()
513+
}
514+
515+
Email.notify_admin(info, :new_content)
516+
end
517+
end
519518
end

test/groupher_server/mailer/email_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
defmodule GroupherServer.Test.Mailer do
22
@moduledoc """
3-
mailer test, see details: https://github.com/thoughtbot/bamboo
3+
mailer test, see details: https://github.com/thoughtbot/bamboo
44
"""
55
use GroupherServer.TestTools
66
use Bamboo.Test
77

88
import Helper.Utils, only: [get_config: 2]
9-
@support_email get_config(:system_emails, :support)
9+
@support_email get_config(:system_emails, :support_email)
1010

1111
describe "basic email" do
1212
test "send welcome email when user has email addr" do

test/groupher_server_web/query/accounts/published_contents_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ defmodule GroupherServer.Test.Query.Accounts.PublishedContents do
110110
}
111111
}
112112
"""
113+
@tag :wip
113114
test "user can get paged published videos", ~m(guest_conn user community)a do
114115
pub_videos =
115116
Enum.reduce(1..@publish_count, [], fn _, acc ->

0 commit comments

Comments
 (0)