Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

refactor(cite-workflow): cross cite fix & test#403

Merged
mydearxym merged 1 commit intodevfromcite-cross-test
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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
24 changes: 13 additions & 11 deletionslib/groupher_server/cms/delegates/cited_content.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,38 +38,32 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do
Map.put(paged_contents, :entries, entries)
end

defp thread_to_atom(thread), do: thread |> String.downcase() |> String.to_atom()

# shape comment cite
@spec shape_article(CitedContent.t()) :: T.cite_info()
defp shape_article(%CitedContent{comment_id: comment_id} = cited) when not is_nil(comment_id) do
%{
block_linker: block_linker,
cited_by_type: cited_by_type,
comment: comment,
inserted_at: inserted_at
} = cited
%{block_linker: block_linker, comment: comment, inserted_at: inserted_at} = cited

comment_thread = comment.thread |> String.downcase() |> String.to_atom()
article = comment |> Map.get(comment_thread)
article_thread = thread_to_atom(article.meta.thread)
user = comment.author |> Map.take([:login, :nickname, :avatar])

article
|> Map.take([:id, :title])
|> Map.merge(%{
inserted_at: inserted_at,
user: user,
thread:thread_to_atom(cited_by_type),
thread:article_thread,
comment_id: comment.id,
block_linker: block_linker
})
end

# shape general article cite
defp shape_article(%CitedContent{} = cited) do
%{block_linker: block_linker,cited_by_type: cited_by_type,inserted_at: inserted_at} = cited
%{block_linker: block_linker, inserted_at: inserted_at} = cited

thread =thread_to_atom(cited_by_type)
thread =citing_thread(cited)
article = Map.get(cited, thread)

user = get_in(article, [:author, :user]) |> Map.take([:login, :nickname, :avatar])
Expand All@@ -83,4 +77,12 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do
inserted_at: inserted_at
})
end

# find thread_id that not empty
# only used for shape_article
defp citing_thread(cited) do
@article_threads |> Enum.find(fn thread -> not is_nil(Map.get(cited, :"#{thread}_id")) end)
end

defp thread_to_atom(thread), do: thread |> String.downcase() |> String.to_atom()
end
58 changes: 58 additions & 0 deletionstest/groupher_server/cms/cite_contents/cite_post_test.exs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -218,4 +218,62 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do
assert result.total_count == 3
end
end

describe "[cross cite]" do
@tag :wip
test "can citing multi type thread and comment in one time", ~m(user community post2)a do
post_attrs = mock_attrs(:post, %{community_id: community.id})
job_attrs = mock_attrs(:job, %{community_id: community.id})
blog_attrs = mock_attrs(:blog, %{community_id: community.id})

body = mock_rich_text(~s(the <a href=#{@site_host}/post/#{post2.id} />))

{:ok, post} =
CMS.create_article(community, :post, Map.merge(post_attrs, %{body: body}), user)

CiteTasks.handle(post)

Process.sleep(1000)

{:ok, job} = CMS.create_article(community, :job, Map.merge(job_attrs, %{body: body}), user)
CiteTasks.handle(job)

Process.sleep(1000)

comment_body = mock_comment(~s(the <a href=#{@site_host}/post/#{post2.id} />))
{:ok, comment} = CMS.create_comment(:job, job.id, comment_body, user)

CiteTasks.handle(comment)

Process.sleep(1000)

{:ok, blog} =
CMS.create_article(community, :blog, Map.merge(blog_attrs, %{body: body}), user)

CiteTasks.handle(blog)

{:ok, result} = CMS.paged_citing_contents("POST", post2.id, %{page: 1, size: 10})
# IO.inspect(result, label: "the result")

result.total_count == 4

result_post = result.entries |> List.first()
result_job = result.entries |> Enum.at(1)
result_comment = result.entries |> Enum.at(2)
result_blog = result.entries |> List.last()

assert result_post.id == post.id
assert result_post.thread == :post

assert result_job.id == job.id
assert result_job.thread == :job

assert result_comment.id == job.id
assert result_comment.thread == :job
assert result_comment.comment_id == comment.id

assert result_blog.id == blog.id
assert result_blog.thread == :blog
end
end
end
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,7 +44,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.BlogCiting do
}
}
"""
@tag :wip

test "should get paged cittings", ~m(guest_conn community blog_attrs user)a do
{:ok, blog2} = db_insert(:blog)

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,7 +44,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.JobCiting do
}
}
"""
@tag :wip

test "should get paged cittings", ~m(guest_conn community job_attrs user)a do
{:ok, job2} = db_insert(:job)

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,7 +44,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostCiting do
}
}
"""
@tag :wip

test "should get paged cittings", ~m(guest_conn community post_attrs user)a do
{:ok, post2} = db_insert(:post)

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp