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

Commit

Permalink
refactor(mailer): fix test error & mv send logic to later
Browse files Browse the repository at this point in the history
  • Loading branch information
mydearxym committed Aug 4, 2019
1 parent 988eed4 commit 3cc2483
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
41 changes: 20 additions & 21 deletions lib/groupher_server/cms/delegates/article_curd.ex
Expand Up @@ -398,30 +398,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
end

defp create_content_result({:ok, %{create_content: result}}) do
# Later.exec({__MODULE__, :nofify_admin_new_content, [result]})
nofify_admin_new_content(result)
Later.exec({__MODULE__, :nofify_admin_new_content, [result]})
{:ok, result}
end

def nofify_admin_new_content(%{id: id} = result) do
target = result.__struct__
preload = [:origial_community, author: :user]

with {:ok, content} <- ORM.find(target, id, preload: preload) do
info = %{
id: content.id,
title: content.title,
digest: content.digest,
author_name: content.author.user.nickname,
community_raw: content.origial_community.raw,
type:
result.__struct__ |> to_string |> String.split(".") |> List.last() |> String.downcase()
}

Email.notify_admin(info, :new_content)
end
end

defp create_content_result({:error, :create_content, %Ecto.Changeset{} = result, _steps}) do
{:error, result}
end
Expand Down Expand Up @@ -516,4 +496,23 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
defp content_id(:job, id), do: %{job_id: id}
defp content_id(:repo, id), do: %{repo_id: id}
defp content_id(:video, id), do: %{video_id: id}

defp nofify_admin_new_content(%{id: id} = result) do
target = result.__struct__
preload = [:origial_community, author: :user]

with {:ok, content} <- ORM.find(target, id, preload: preload) do
info = %{
id: content.id,
title: content.title,
digest: Map.get(content, :digest, content.title),
author_name: content.author.user.nickname,
community_raw: content.origial_community.raw,
type:
result.__struct__ |> to_string |> String.split(".") |> List.last() |> String.downcase()
}

Email.notify_admin(info, :new_content)
end
end
end
4 changes: 2 additions & 2 deletions test/groupher_server/mailer/email_test.exs
@@ -1,12 +1,12 @@
defmodule GroupherServer.Test.Mailer do
@moduledoc """
mailer test, see details: https://github.com/thoughtbot/bamboo
mailer test, see details: https://github.com/thoughtbot/bamboo
"""
use GroupherServer.TestTools
use Bamboo.Test

import Helper.Utils, only: [get_config: 2]
@support_email get_config(:system_emails, :support)
@support_email get_config(:system_emails, :support_email)

describe "basic email" do
test "send welcome email when user has email addr" do
Expand Down
Expand Up @@ -110,6 +110,7 @@ defmodule GroupherServer.Test.Query.Accounts.PublishedContents do
}
}
"""
@tag :wip
test "user can get paged published videos", ~m(guest_conn user community)a do
pub_videos =
Enum.reduce(1..@publish_count, [], fn _, acc ->
Expand Down

0 comments on commit 3cc2483

Please sign in to comment.