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

Commit a4f6557

Browse files
committed
refactor(article-emotions): fix broken test
1 parent 5b2f45e commit a4f6557

File tree

14 files changed

+38
-32
lines changed

14 files changed

+38
-32
lines changed

lib/groupher_server/cms/delegates/article_curd.ex

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,22 +300,21 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
300300

301301
defp domain_filter_query(queryable, _filter), do: queryable
302302

303-
defp add_pin_contents_ifneed(contents, querable, %{community: _community} = filter) do
303+
defp add_pin_contents_ifneed(contents, querable, %{community: community} = filter) do
304304
with {:ok, _} <- should_add_pin?(filter),
305305
{:ok, info} <- match(querable),
306-
{:ok, normal_contents} <- contents,
307-
true <- Map.has_key?(filter, :community),
308-
true <- 1 == Map.get(normal_contents, :page_number) do
309-
{:ok, pined_content} =
306+
true <- 1 == Map.get(contents, :page_number) do
307+
{:ok, pinned_articles} =
310308
PinnedArticle
311309
|> join(:inner, [p], c in assoc(p, :community))
312-
|> join(:inner, [p], content in assoc(p, ^info.thread))
313-
|> where([p, c, content], c.raw == ^filter.community)
314-
|> select([p, c, content], content)
310+
# |> join(:inner, [p], article in assoc(p, ^filter.thread))
311+
|> join(:inner, [p], article in assoc(p, ^info.thread))
312+
|> where([p, c, article], c.raw == ^community)
313+
|> select([p, c, article], article)
315314
# 10 pined contents per community/thread, at most
316-
|> ORM.paginater(%{page: 1, size: 10})
315+
|> ORM.find_all(%{page: 1, size: 10})
317316

318-
concat_contents(pined_content, normal_contents)
317+
concat_contents(pinned_articles, contents)
319318
else
320319
_error -> contents
321320
end
@@ -325,22 +324,16 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
325324

326325
# if filter contains like: tags, sort.., then don't add pin content
327326
defp should_add_pin?(%{page: 1, tag: :all, sort: :desc_inserted} = filter) do
328-
filter
329-
|> Map.keys()
330-
|> Enum.reject(fn x -> x in [:community, :tag, :sort, :page, :size] end)
331-
|> case do
332-
[] -> {:ok, :pass}
333-
_ -> {:error, :pass}
334-
end
327+
{:ok, :pass}
335328
end
336329

337330
defp should_add_pin?(_filter), do: {:error, :pass}
338331

339332
defp concat_contents(%{total_count: 0}, normal_contents), do: normal_contents
340333

341-
defp concat_contents(pined_content, normal_contents) do
334+
defp concat_contents(pinned_articles, normal_contents) do
342335
pind_entries =
343-
pined_content
336+
pinned_articles
344337
|> Map.get(:entries)
345338
|> Enum.map(&struct(&1, %{is_pinned: true}))
346339

lib/groupher_server/cms/delegates/helper.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defmodule GroupherServer.CMS.Delegate.Helper do
1717
defp get_supported_mentions(_), do: @supported_emotions
1818

1919
def mark_viewer_emotion_states(paged_contents, nil), do: paged_contents
20+
def mark_viewer_emotion_states(paged_contents, nil, :comment), do: paged_contents
2021
def mark_viewer_emotion_states(%{entries: []} = paged_contents, _), do: paged_contents
2122

2223
@doc """

lib/groupher_server/cms/repo.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ defmodule GroupherServer.CMS.Repo do
5353
field(:views, :integer, default: 0)
5454

5555
embeds_one(:meta, Embeds.ArticleMeta, on_replace: :update)
56+
embeds_one(:emotions, Embeds.ArticleEmotion, on_replace: :update)
5657

5758
belongs_to(:author, Author)
5859
has_many(:community_flags, {"repos_communities_flags", RepoCommunityFlag})

lib/groupher_server_web/schema/cms/cms_queries.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do
7979
resolve(&R.CMS.cheatsheet/3)
8080
end
8181

82-
article_queries(:post)
83-
article_queries(:job)
84-
article_queries(:repo)
85-
8682
article_reacted_users_query(:upvot, &R.CMS.upvoted_users/3)
8783
article_reacted_users_query(:collect, &R.CMS.collected_users/3)
8884

@@ -207,5 +203,9 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do
207203

208204
resolve(&R.CMS.search_items/3)
209205
end
206+
207+
article_queries(:post)
208+
article_queries(:job)
209+
article_queries(:repo)
210210
end
211211
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule GroupherServer.Repo.Migrations.AddEmotionsToRepo do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:cms_repos) do
6+
add(:emotions, :map)
7+
end
8+
end
9+
end

test/groupher_server/cms/comments/post_comment_replies_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do
160160
end
161161

162162
describe "[paged article comment replies]" do
163-
@tag :wip
163+
@tag :wip3
164164
test "can get paged replies of a parent comment", ~m(post user)a do
165165
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user)
166166
{:ok, paged_replies} = CMS.list_comment_replies(parent_comment.id, %{page: 1, size: 20})

test/groupher_server/cms/comments/post_comment_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
435435
assert paged_comments.total_count == total_count
436436
end
437437

438-
@tag :wip
438+
@tag :wip3
439439
test "paged article comments should not contains folded and repoted comments",
440440
~m(user post)a do
441441
total_count = 15

test/groupher_server/cms/post_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ defmodule GroupherServer.Test.CMS.Post do
1818
describe "[cms post curd]" do
1919
alias CMS.{Author, Community}
2020

21+
@tag :wip3
2122
test "can create post with valid attrs", ~m(user community post_attrs)a do
2223
assert {:error, _} = ORM.find_by(Author, user_id: user.id)
2324

test/groupher_server/cms/repo_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule GroupherServer.Test.Repo do
1717

1818
describe "[cms repo curd]" do
1919
alias CMS.{Author, Community}
20-
20+
@tag :wip3
2121
test "can create repo with valid attrs", ~m(user community repo_attrs)a do
2222
assert {:error, _} = ORM.find_by(Author, user_id: user.id)
2323

test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do
3232
}
3333
}
3434
"""
35-
@tag :wip2
35+
@tag :wip3
3636
test "login user can emotion to a pjob", ~m(community job_attrs user user_conn)a do
3737
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
3838

@@ -58,7 +58,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do
5858
}
5959
}
6060
"""
61-
@tag :wip2
61+
@tag :wip3
6262
test "login user can undo emotion to a job", ~m(community job_attrs user owner_conn)a do
6363
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
6464
{:ok, _} = CMS.emotion_to_article(:job, job.id, :beer, user)

0 commit comments

Comments
 (0)