From 44f16bdd19cf44322b8e8d8ec44bbac4de4857e5 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 15 May 2021 07:34:06 +0800 Subject: [PATCH 1/4] refactor: more test --- .../cms/article_community/job_test.exs | 247 ++++++++++++++++++ .../cms/article_community/repo_test.exs | 247 ++++++++++++++++++ 2 files changed, 494 insertions(+) create mode 100644 test/groupher_server_web/mutation/cms/article_community/job_test.exs create mode 100644 test/groupher_server_web/mutation/cms/article_community/repo_test.exs diff --git a/test/groupher_server_web/mutation/cms/article_community/job_test.exs b/test/groupher_server_web/mutation/cms/article_community/job_test.exs new file mode 100644 index 000000000..bdb0ca15d --- /dev/null +++ b/test/groupher_server_web/mutation/cms/article_community/job_test.exs @@ -0,0 +1,247 @@ +defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do + use GroupherServer.TestTools + + alias Helper.ORM + alias GroupherServer.CMS + + setup do + {:ok, post} = db_insert(:post) + {:ok, community} = db_insert(:community) + + guest_conn = simu_conn(:guest) + user_conn = simu_conn(:user) + owner_conn = simu_conn(:owner, post) + + {:ok, ~m(user_conn guest_conn owner_conn community post)a} + end + + describe "[mutation post tag]" do + @set_tag_query """ + mutation($id: ID!, $tagId: ID! $communityId: ID!) { + setTag(id: $id, tagId: $tagId, communityId: $communityId) { + id + title + } + } + """ + test "auth user can set a valid tag to post", ~m(post)a do + {:ok, community} = db_insert(:community) + {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) + + passport_rules = %{community.title => %{"post.tag.set" => true}} + rule_conn = simu_conn(:user, cms: passport_rules) + + variables = %{id: post.id, tagId: tag.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables, "setTag") + {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) + + assoc_tags = found.tags |> Enum.map(& &1.id) + assert tag.id in assoc_tags + end + + # TODO: should fix in auth layer + # test "auth user set a other community tag to post fails", ~m(post)a do + # {:ok, community} = db_insert(:community) + # {:ok, tag} = db_insert(:tag, %{thread: "post"}) + + # passport_rules = %{community.title => %{"post.tag.set" => true}} + # rule_conn = simu_conn(:user, cms: passport_rules) + + # variables = %{id: post.id, tagId: tag.id, communityId: community.id} + # assert rule_conn |> mutation_get_error?(@set_tag_query, variables) + # end + + test "can set multi tag to a post", ~m(post)a do + {:ok, community} = db_insert(:community) + {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) + {:ok, tag2} = db_insert(:tag, %{thread: "post", community: community}) + + passport_rules = %{community.title => %{"post.tag.set" => true}} + rule_conn = simu_conn(:user, cms: passport_rules) + + variables = %{id: post.id, tagId: tag.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables, "setTag") + + variables2 = %{id: post.id, tagId: tag2.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") + + {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) + + assoc_tags = found.tags |> Enum.map(& &1.id) + assert tag.id in assoc_tags + assert tag2.id in assoc_tags + end + + @unset_tag_query """ + mutation($id: ID!, $tagId: ID!, $communityId: ID!) { + unsetTag(id: $id, tagId: $tagId, communityId: $communityId) { + id + title + } + } + """ + test "can unset tag to a post", ~m(post)a do + {:ok, community} = db_insert(:community) + + passport_rules = %{community.title => %{"post.tag.set" => true}} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) + {:ok, tag2} = db_insert(:tag, %{thread: "post", community: community}) + + variables = %{id: post.id, tagId: tag.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables, "setTag") + + variables2 = %{id: post.id, tagId: tag2.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") + + {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) + + assoc_tags = found.tags |> Enum.map(& &1.id) + assert tag.id in assoc_tags + assert tag2.id in assoc_tags + + passport_rules2 = %{community.title => %{"post.tag.unset" => true}} + rule_conn2 = simu_conn(:user, cms: passport_rules2) + + rule_conn2 |> mutation_result(@unset_tag_query, variables, "unsetTag") + + {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) + assoc_tags = found.tags |> Enum.map(& &1.id) + + assert tag.id not in assoc_tags + assert tag2.id in assoc_tags + end + end + + describe "[mirror/unmirror/move psot to/from community]" do + @mirror_article_query """ + mutation($id: ID!, $communityId: ID!) { + mirrorArticle(id: $id, communityId: $communityId) { + id + } + } + """ + test "auth user can mirror a post to other community", ~m(post)a do + passport_rules = %{"post.community.mirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, community} = db_insert(:community) + variables = %{id: post.id, communityId: community.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) + + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id in assoc_communities + end + + test "unauth user cannot mirror a post to a community", ~m(user_conn guest_conn post)a do + {:ok, community} = db_insert(:community) + variables = %{id: post.id, communityId: community.id} + rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) + + assert user_conn + |> mutation_get_error?(@mirror_article_query, variables, ecode(:passport)) + + assert guest_conn + |> mutation_get_error?(@mirror_article_query, variables, ecode(:account_login)) + + assert rule_conn + |> mutation_get_error?(@mirror_article_query, variables, ecode(:passport)) + end + + test "auth user can mirror multi post to other communities", ~m(post)a do + passport_rules = %{"post.community.mirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, community} = db_insert(:community) + {:ok, community2} = db_insert(:community) + + variables = %{id: post.id, communityId: community.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + + variables = %{id: post.id, communityId: community2.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + + {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) + + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id in assoc_communities + assert community2.id in assoc_communities + end + + @unmirror_article_query """ + mutation($id: ID!, $communityId: ID!) { + unmirrorArticle(id: $id, communityId: $communityId) { + id + } + } + """ + @tag :wip2 + test "auth user can unmirror post to a community", ~m(post)a do + passport_rules = %{"post.community.mirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, community} = db_insert(:community) + {:ok, community2} = db_insert(:community) + + variables = %{id: post.id, communityId: community.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + + variables2 = %{id: post.id, communityId: community2.id} + rule_conn |> mutation_result(@mirror_article_query, variables2, "mirrorArticle") + + {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) + + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id in assoc_communities + assert community2.id in assoc_communities + + passport_rules = %{"post.community.unmirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + rule_conn |> mutation_result(@unmirror_article_query, variables, "unmirrorArticle") + {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id not in assoc_communities + assert community2.id in assoc_communities + end + + @move_article_query """ + mutation($id: ID!, $communityId: ID!) { + moveArticle(id: $id, communityId: $communityId) { + id + } + } + """ + @tag :wip2 + test "auth user can move post to other community", ~m(post)a do + passport_rules = %{"post.community.mirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, community} = db_insert(:community) + {:ok, community2} = db_insert(:community) + + variables = %{id: post.id, communityId: community.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + {:ok, found} = ORM.find(CMS.Post, post.id, preload: [:original_community, :communities]) + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id in assoc_communities + + passport_rules = %{"post.community.move" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + pre_original_community_id = found.original_community.id + + variables = %{id: post.id, communityId: community2.id} + rule_conn |> mutation_result(@move_article_query, variables, "moveArticle") + {:ok, found} = ORM.find(CMS.Post, post.id, preload: [:original_community, :communities]) + assoc_communities = found.communities |> Enum.map(& &1.id) + assert pre_original_community_id not in assoc_communities + assert community2.id in assoc_communities + assert community2.id == found.original_community_id + + assert found.original_community.id == community2.id + end + end +end diff --git a/test/groupher_server_web/mutation/cms/article_community/repo_test.exs b/test/groupher_server_web/mutation/cms/article_community/repo_test.exs new file mode 100644 index 000000000..cbcad59f8 --- /dev/null +++ b/test/groupher_server_web/mutation/cms/article_community/repo_test.exs @@ -0,0 +1,247 @@ +defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do + use GroupherServer.TestTools + + alias Helper.ORM + alias GroupherServer.CMS + + setup do + {:ok, repo} = db_insert(:repo) + {:ok, community} = db_insert(:community) + + guest_conn = simu_conn(:guest) + user_conn = simu_conn(:user) + owner_conn = simu_conn(:owner, repo) + + {:ok, ~m(user_conn guest_conn owner_conn community repo)a} + end + + describe "[mutation repo tag]" do + @set_tag_query """ + mutation($id: ID!, $tagId: ID! $communityId: ID!) { + setTag(id: $id, tagId: $tagId, communityId: $communityId) { + id + title + } + } + """ + test "auth user can set a valid tag to repo", ~m(repo)a do + {:ok, community} = db_insert(:community) + {:ok, tag} = db_insert(:tag, %{thread: "repo", community: community}) + + passport_rules = %{community.title => %{"repo.tag.set" => true}} + rule_conn = simu_conn(:user, cms: passport_rules) + + variables = %{id: repo.id, tagId: tag.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables, "setTag") + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :tags) + + assoc_tags = found.tags |> Enum.map(& &1.id) + assert tag.id in assoc_tags + end + + # TODO: should fix in auth layer + # test "auth user set a other community tag to repo fails", ~m(repo)a do + # {:ok, community} = db_insert(:community) + # {:ok, tag} = db_insert(:tag, %{thread: "repo"}) + + # passport_rules = %{community.title => %{"repo.tag.set" => true}} + # rule_conn = simu_conn(:user, cms: passport_rules) + + # variables = %{id: repo.id, tagId: tag.id, communityId: community.id} + # assert rule_conn |> mutation_get_error?(@set_tag_query, variables) + # end + + test "can set multi tag to a repo", ~m(repo)a do + {:ok, community} = db_insert(:community) + {:ok, tag} = db_insert(:tag, %{thread: "repo", community: community}) + {:ok, tag2} = db_insert(:tag, %{thread: "repo", community: community}) + + passport_rules = %{community.title => %{"repo.tag.set" => true}} + rule_conn = simu_conn(:user, cms: passport_rules) + + variables = %{id: repo.id, tagId: tag.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables, "setTag") + + variables2 = %{id: repo.id, tagId: tag2.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") + + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :tags) + + assoc_tags = found.tags |> Enum.map(& &1.id) + assert tag.id in assoc_tags + assert tag2.id in assoc_tags + end + + @unset_tag_query """ + mutation($id: ID!, $tagId: ID!, $communityId: ID!) { + unsetTag(id: $id, tagId: $tagId, communityId: $communityId) { + id + title + } + } + """ + test "can unset tag to a repo", ~m(repo)a do + {:ok, community} = db_insert(:community) + + passport_rules = %{community.title => %{"repo.tag.set" => true}} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, tag} = db_insert(:tag, %{thread: "repo", community: community}) + {:ok, tag2} = db_insert(:tag, %{thread: "repo", community: community}) + + variables = %{id: repo.id, tagId: tag.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables, "setTag") + + variables2 = %{id: repo.id, tagId: tag2.id, communityId: community.id} + rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") + + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :tags) + + assoc_tags = found.tags |> Enum.map(& &1.id) + assert tag.id in assoc_tags + assert tag2.id in assoc_tags + + passport_rules2 = %{community.title => %{"repo.tag.unset" => true}} + rule_conn2 = simu_conn(:user, cms: passport_rules2) + + rule_conn2 |> mutation_result(@unset_tag_query, variables, "unsetTag") + + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :tags) + assoc_tags = found.tags |> Enum.map(& &1.id) + + assert tag.id not in assoc_tags + assert tag2.id in assoc_tags + end + end + + describe "[mirror/unmirror/move psot to/from community]" do + @mirror_article_query """ + mutation($id: ID!, $communityId: ID!) { + mirrorArticle(id: $id, communityId: $communityId) { + id + } + } + """ + test "auth user can mirror a repo to other community", ~m(repo)a do + passport_rules = %{"repo.community.mirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, community} = db_insert(:community) + variables = %{id: repo.id, communityId: community.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :communities) + + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id in assoc_communities + end + + test "unauth user cannot mirror a repo to a community", ~m(user_conn guest_conn repo)a do + {:ok, community} = db_insert(:community) + variables = %{id: repo.id, communityId: community.id} + rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) + + assert user_conn + |> mutation_get_error?(@mirror_article_query, variables, ecode(:passport)) + + assert guest_conn + |> mutation_get_error?(@mirror_article_query, variables, ecode(:account_login)) + + assert rule_conn + |> mutation_get_error?(@mirror_article_query, variables, ecode(:passport)) + end + + test "auth user can mirror multi repo to other communities", ~m(repo)a do + passport_rules = %{"repo.community.mirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, community} = db_insert(:community) + {:ok, community2} = db_insert(:community) + + variables = %{id: repo.id, communityId: community.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + + variables = %{id: repo.id, communityId: community2.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :communities) + + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id in assoc_communities + assert community2.id in assoc_communities + end + + @unmirror_article_query """ + mutation($id: ID!, $communityId: ID!) { + unmirrorArticle(id: $id, communityId: $communityId) { + id + } + } + """ + @tag :wip2 + test "auth user can unmirror repo to a community", ~m(repo)a do + passport_rules = %{"repo.community.mirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, community} = db_insert(:community) + {:ok, community2} = db_insert(:community) + + variables = %{id: repo.id, communityId: community.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + + variables2 = %{id: repo.id, communityId: community2.id} + rule_conn |> mutation_result(@mirror_article_query, variables2, "mirrorArticle") + + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :communities) + + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id in assoc_communities + assert community2.id in assoc_communities + + passport_rules = %{"repo.community.unmirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + rule_conn |> mutation_result(@unmirror_article_query, variables, "unmirrorArticle") + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :communities) + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id not in assoc_communities + assert community2.id in assoc_communities + end + + @move_article_query """ + mutation($id: ID!, $communityId: ID!) { + moveArticle(id: $id, communityId: $communityId) { + id + } + } + """ + @tag :wip2 + test "auth user can move repo to other community", ~m(repo)a do + passport_rules = %{"repo.community.mirror" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + {:ok, community} = db_insert(:community) + {:ok, community2} = db_insert(:community) + + variables = %{id: repo.id, communityId: community.id} + rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: [:original_community, :communities]) + assoc_communities = found.communities |> Enum.map(& &1.id) + assert community.id in assoc_communities + + passport_rules = %{"repo.community.move" => true} + rule_conn = simu_conn(:user, cms: passport_rules) + + pre_original_community_id = found.original_community.id + + variables = %{id: repo.id, communityId: community2.id} + rule_conn |> mutation_result(@move_article_query, variables, "moveArticle") + {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: [:original_community, :communities]) + assoc_communities = found.communities |> Enum.map(& &1.id) + assert pre_original_community_id not in assoc_communities + assert community2.id in assoc_communities + assert community2.id == found.original_community_id + + assert found.original_community.id == community2.id + end + end +end From ae034fb956ae07247039d03469de54b3721ca99f Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 15 May 2021 07:42:34 +0800 Subject: [PATCH 2/4] refactor: more test --- .../cms/article_community/job_test.exs | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/test/groupher_server_web/mutation/cms/article_community/job_test.exs b/test/groupher_server_web/mutation/cms/article_community/job_test.exs index bdb0ca15d..10fdb6d44 100644 --- a/test/groupher_server_web/mutation/cms/article_community/job_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/job_test.exs @@ -1,21 +1,21 @@ -defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do +defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do use GroupherServer.TestTools alias Helper.ORM alias GroupherServer.CMS setup do - {:ok, post} = db_insert(:post) + {:ok, job} = db_insert(:job) {:ok, community} = db_insert(:community) guest_conn = simu_conn(:guest) user_conn = simu_conn(:user) - owner_conn = simu_conn(:owner, post) + owner_conn = simu_conn(:owner, job) - {:ok, ~m(user_conn guest_conn owner_conn community post)a} + {:ok, ~m(user_conn guest_conn owner_conn community job)a} end - describe "[mutation post tag]" do + describe "[mutation job tag]" do @set_tag_query """ mutation($id: ID!, $tagId: ID! $communityId: ID!) { setTag(id: $id, tagId: $tagId, communityId: $communityId) { @@ -24,48 +24,48 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do } } """ - test "auth user can set a valid tag to post", ~m(post)a do + test "auth user can set a valid tag to job", ~m(job)a do {:ok, community} = db_insert(:community) - {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) + {:ok, tag} = db_insert(:tag, %{thread: "job", community: community}) - passport_rules = %{community.title => %{"post.tag.set" => true}} + passport_rules = %{community.title => %{"job.tag.set" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - variables = %{id: post.id, tagId: tag.id, communityId: community.id} + variables = %{id: job.id, tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: :tags) assoc_tags = found.tags |> Enum.map(& &1.id) assert tag.id in assoc_tags end # TODO: should fix in auth layer - # test "auth user set a other community tag to post fails", ~m(post)a do + # test "auth user set a other community tag to job fails", ~m(job)a do # {:ok, community} = db_insert(:community) - # {:ok, tag} = db_insert(:tag, %{thread: "post"}) + # {:ok, tag} = db_insert(:tag, %{thread: "job"}) - # passport_rules = %{community.title => %{"post.tag.set" => true}} + # passport_rules = %{community.title => %{"job.tag.set" => true}} # rule_conn = simu_conn(:user, cms: passport_rules) - # variables = %{id: post.id, tagId: tag.id, communityId: community.id} + # variables = %{id: job.id, tagId: tag.id, communityId: community.id} # assert rule_conn |> mutation_get_error?(@set_tag_query, variables) # end - test "can set multi tag to a post", ~m(post)a do + test "can set multi tag to a job", ~m(job)a do {:ok, community} = db_insert(:community) - {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) - {:ok, tag2} = db_insert(:tag, %{thread: "post", community: community}) + {:ok, tag} = db_insert(:tag, %{thread: "job", community: community}) + {:ok, tag2} = db_insert(:tag, %{thread: "job", community: community}) - passport_rules = %{community.title => %{"post.tag.set" => true}} + passport_rules = %{community.title => %{"job.tag.set" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - variables = %{id: post.id, tagId: tag.id, communityId: community.id} + variables = %{id: job.id, tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") - variables2 = %{id: post.id, tagId: tag2.id, communityId: community.id} + variables2 = %{id: job.id, tagId: tag2.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: :tags) assoc_tags = found.tags |> Enum.map(& &1.id) assert tag.id in assoc_tags @@ -80,33 +80,33 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do } } """ - test "can unset tag to a post", ~m(post)a do + test "can unset tag to a job", ~m(job)a do {:ok, community} = db_insert(:community) - passport_rules = %{community.title => %{"post.tag.set" => true}} + passport_rules = %{community.title => %{"job.tag.set" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) - {:ok, tag2} = db_insert(:tag, %{thread: "post", community: community}) + {:ok, tag} = db_insert(:tag, %{thread: "job", community: community}) + {:ok, tag2} = db_insert(:tag, %{thread: "job", community: community}) - variables = %{id: post.id, tagId: tag.id, communityId: community.id} + variables = %{id: job.id, tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") - variables2 = %{id: post.id, tagId: tag2.id, communityId: community.id} + variables2 = %{id: job.id, tagId: tag2.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: :tags) assoc_tags = found.tags |> Enum.map(& &1.id) assert tag.id in assoc_tags assert tag2.id in assoc_tags - passport_rules2 = %{community.title => %{"post.tag.unset" => true}} + passport_rules2 = %{community.title => %{"job.tag.unset" => true}} rule_conn2 = simu_conn(:user, cms: passport_rules2) rule_conn2 |> mutation_result(@unset_tag_query, variables, "unsetTag") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: :tags) assoc_tags = found.tags |> Enum.map(& &1.id) assert tag.id not in assoc_tags @@ -122,22 +122,22 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do } } """ - test "auth user can mirror a post to other community", ~m(post)a do - passport_rules = %{"post.community.mirror" => true} + test "auth user can mirror a job to other community", ~m(job)a do + passport_rules = %{"job.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) {:ok, community} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: job.id, communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: :communities) assoc_communities = found.communities |> Enum.map(& &1.id) assert community.id in assoc_communities end - test "unauth user cannot mirror a post to a community", ~m(user_conn guest_conn post)a do + test "unauth user cannot mirror a job to a community", ~m(user_conn guest_conn job)a do {:ok, community} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) assert user_conn @@ -150,20 +150,20 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do |> mutation_get_error?(@mirror_article_query, variables, ecode(:passport)) end - test "auth user can mirror multi post to other communities", ~m(post)a do - passport_rules = %{"post.community.mirror" => true} + test "auth user can mirror multi job to other communities", ~m(job)a do + passport_rules = %{"job.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: job.id, communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - variables = %{id: post.id, communityId: community2.id} + variables = %{id: job.id, communityId: community2.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: :communities) assoc_communities = found.communities |> Enum.map(& &1.id) assert community.id in assoc_communities @@ -178,30 +178,30 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do } """ @tag :wip2 - test "auth user can unmirror post to a community", ~m(post)a do - passport_rules = %{"post.community.mirror" => true} + test "auth user can unmirror job to a community", ~m(job)a do + passport_rules = %{"job.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: job.id, communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - variables2 = %{id: post.id, communityId: community2.id} + variables2 = %{id: job.id, communityId: community2.id} rule_conn |> mutation_result(@mirror_article_query, variables2, "mirrorArticle") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: :communities) assoc_communities = found.communities |> Enum.map(& &1.id) assert community.id in assoc_communities assert community2.id in assoc_communities - passport_rules = %{"post.community.unmirror" => true} + passport_rules = %{"job.community.unmirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) rule_conn |> mutation_result(@unmirror_article_query, variables, "unmirrorArticle") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: :communities) assoc_communities = found.communities |> Enum.map(& &1.id) assert community.id not in assoc_communities assert community2.id in assoc_communities @@ -215,27 +215,27 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do } """ @tag :wip2 - test "auth user can move post to other community", ~m(post)a do - passport_rules = %{"post.community.mirror" => true} + test "auth user can move job to other community", ~m(job)a do + passport_rules = %{"job.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: job.id, communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: [:original_community, :communities]) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: [:original_community, :communities]) assoc_communities = found.communities |> Enum.map(& &1.id) assert community.id in assoc_communities - passport_rules = %{"post.community.move" => true} + passport_rules = %{"job.community.move" => true} rule_conn = simu_conn(:user, cms: passport_rules) pre_original_community_id = found.original_community.id - variables = %{id: post.id, communityId: community2.id} + variables = %{id: job.id, communityId: community2.id} rule_conn |> mutation_result(@move_article_query, variables, "moveArticle") - {:ok, found} = ORM.find(CMS.Post, post.id, preload: [:original_community, :communities]) + {:ok, found} = ORM.find(CMS.Job, job.id, preload: [:original_community, :communities]) assoc_communities = found.communities |> Enum.map(& &1.id) assert pre_original_community_id not in assoc_communities assert community2.id in assoc_communities From 79784b32de7713bcb3cb33c51852ceb42d37c784 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 15 May 2021 08:13:33 +0800 Subject: [PATCH 3/4] refactor: add thread var --- .../cms/article_community/job_test.exs | 2 +- .../cms/article_community/post_test.exs | 2 +- .../cms/article_community/repo_test.exs | 2 +- .../cms/article_community/job_test.exs | 30 +++++++++---------- .../cms/article_community/post_test.exs | 30 +++++++++---------- .../cms/article_community/repo_test.exs | 30 +++++++++---------- .../mutation/cms/articles/job_test.exs | 2 +- .../cms/abuse_reports/job_report_test.exs | 2 +- .../cms/abuse_reports/post_report_test.exs | 2 +- 9 files changed, 51 insertions(+), 51 deletions(-) diff --git a/test/groupher_server/cms/article_community/job_test.exs b/test/groupher_server/cms/article_community/job_test.exs index 931504eca..d64e2f3f8 100644 --- a/test/groupher_server/cms/article_community/job_test.exs +++ b/test/groupher_server/cms/article_community/job_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Job do assert job.original_community_id == community.id end - @tag :wip2 + @tag :wip3 test "job can be move to other community", ~m(user community community2 job_attrs)a do {:ok, job} = CMS.create_article(community, :job, job_attrs, user) assert job.original_community_id == community.id diff --git a/test/groupher_server/cms/article_community/post_test.exs b/test/groupher_server/cms/article_community/post_test.exs index 9fa6f15bf..71ab8bea1 100644 --- a/test/groupher_server/cms/article_community/post_test.exs +++ b/test/groupher_server/cms/article_community/post_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Post do assert post.original_community_id == community.id end - @tag :wip2 + @tag :wip3 test "post can be move to other community", ~m(user community community2 post_attrs)a do {:ok, post} = CMS.create_article(community, :post, post_attrs, user) assert post.original_community_id == community.id diff --git a/test/groupher_server/cms/article_community/repo_test.exs b/test/groupher_server/cms/article_community/repo_test.exs index 5d80ab1d0..182d2395f 100644 --- a/test/groupher_server/cms/article_community/repo_test.exs +++ b/test/groupher_server/cms/article_community/repo_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommunity.Repo do assert repo.original_community_id == community.id end - @tag :wip2 + @tag :wip3 test "repo can be move to other community", ~m(user community community2 repo_attrs)a do {:ok, repo} = CMS.create_article(community, :repo, repo_attrs, user) assert repo.original_community_id == community.id diff --git a/test/groupher_server_web/mutation/cms/article_community/job_test.exs b/test/groupher_server_web/mutation/cms/article_community/job_test.exs index 10fdb6d44..0214d7bab 100644 --- a/test/groupher_server_web/mutation/cms/article_community/job_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/job_test.exs @@ -116,8 +116,8 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do describe "[mirror/unmirror/move psot to/from community]" do @mirror_article_query """ - mutation($id: ID!, $communityId: ID!) { - mirrorArticle(id: $id, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $communityId: ID!) { + mirrorArticle(id: $id, thread: $thread, communityId: $communityId) { id } } @@ -127,7 +127,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do rule_conn = simu_conn(:user, cms: passport_rules) {:ok, community} = db_insert(:community) - variables = %{id: job.id, communityId: community.id} + variables = %{id: job.id, thread: "JOB", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") {:ok, found} = ORM.find(CMS.Job, job.id, preload: :communities) @@ -137,7 +137,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do test "unauth user cannot mirror a job to a community", ~m(user_conn guest_conn job)a do {:ok, community} = db_insert(:community) - variables = %{id: job.id, communityId: community.id} + variables = %{id: job.id, thread: "JOB", communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) assert user_conn @@ -157,10 +157,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: job.id, communityId: community.id} + variables = %{id: job.id, thread: "JOB", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - variables = %{id: job.id, communityId: community2.id} + variables = %{id: job.id, thread: "JOB", communityId: community2.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") {:ok, found} = ORM.find(CMS.Job, job.id, preload: :communities) @@ -171,13 +171,13 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do end @unmirror_article_query """ - mutation($id: ID!, $communityId: ID!) { - unmirrorArticle(id: $id, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $communityId: ID!) { + unmirrorArticle(id: $id, thread: $thread, communityId: $communityId) { id } } """ - @tag :wip2 + @tag :wip3 test "auth user can unmirror job to a community", ~m(job)a do passport_rules = %{"job.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) @@ -185,10 +185,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: job.id, communityId: community.id} + variables = %{id: job.id, thread: "JOB", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - variables2 = %{id: job.id, communityId: community2.id} + variables2 = %{id: job.id, thread: "JOB", communityId: community2.id} rule_conn |> mutation_result(@mirror_article_query, variables2, "mirrorArticle") {:ok, found} = ORM.find(CMS.Job, job.id, preload: :communities) @@ -208,8 +208,8 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do end @move_article_query """ - mutation($id: ID!, $communityId: ID!) { - moveArticle(id: $id, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $communityId: ID!) { + moveArticle(id: $id, thread: $thread, communityId: $communityId) { id } } @@ -222,7 +222,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: job.id, communityId: community.id} + variables = %{id: job.id, thread: "JOB", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") {:ok, found} = ORM.find(CMS.Job, job.id, preload: [:original_community, :communities]) assoc_communities = found.communities |> Enum.map(& &1.id) @@ -233,7 +233,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do pre_original_community_id = found.original_community.id - variables = %{id: job.id, communityId: community2.id} + variables = %{id: job.id, thread: "JOB", communityId: community2.id} rule_conn |> mutation_result(@move_article_query, variables, "moveArticle") {:ok, found} = ORM.find(CMS.Job, job.id, preload: [:original_community, :communities]) assoc_communities = found.communities |> Enum.map(& &1.id) diff --git a/test/groupher_server_web/mutation/cms/article_community/post_test.exs b/test/groupher_server_web/mutation/cms/article_community/post_test.exs index bdb0ca15d..27984f098 100644 --- a/test/groupher_server_web/mutation/cms/article_community/post_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/post_test.exs @@ -116,8 +116,8 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do describe "[mirror/unmirror/move psot to/from community]" do @mirror_article_query """ - mutation($id: ID!, $communityId: ID!) { - mirrorArticle(id: $id, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $communityId: ID!) { + mirrorArticle(id: $id, thread: $thread, communityId: $communityId) { id } } @@ -127,7 +127,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do rule_conn = simu_conn(:user, cms: passport_rules) {:ok, community} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: post.id, thread: "POST", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) @@ -137,7 +137,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do test "unauth user cannot mirror a post to a community", ~m(user_conn guest_conn post)a do {:ok, community} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: post.id, thread: "POST", communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) assert user_conn @@ -157,10 +157,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: post.id, thread: "POST", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - variables = %{id: post.id, communityId: community2.id} + variables = %{id: post.id, thread: "POST", communityId: community2.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) @@ -171,13 +171,13 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do end @unmirror_article_query """ - mutation($id: ID!, $communityId: ID!) { - unmirrorArticle(id: $id, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $communityId: ID!) { + unmirrorArticle(id: $id, thread: $thread, communityId: $communityId) { id } } """ - @tag :wip2 + @tag :wip3 test "auth user can unmirror post to a community", ~m(post)a do passport_rules = %{"post.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) @@ -185,10 +185,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: post.id, thread: "POST", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - variables2 = %{id: post.id, communityId: community2.id} + variables2 = %{id: post.id, thread: "POST", communityId: community2.id} rule_conn |> mutation_result(@mirror_article_query, variables2, "mirrorArticle") {:ok, found} = ORM.find(CMS.Post, post.id, preload: :communities) @@ -208,8 +208,8 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do end @move_article_query """ - mutation($id: ID!, $communityId: ID!) { - moveArticle(id: $id, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $communityId: ID!) { + moveArticle(id: $id, thread: $thread, communityId: $communityId) { id } } @@ -222,7 +222,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: post.id, communityId: community.id} + variables = %{id: post.id, thread: "POST", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") {:ok, found} = ORM.find(CMS.Post, post.id, preload: [:original_community, :communities]) assoc_communities = found.communities |> Enum.map(& &1.id) @@ -233,7 +233,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do pre_original_community_id = found.original_community.id - variables = %{id: post.id, communityId: community2.id} + variables = %{id: post.id, thread: "POST", communityId: community2.id} rule_conn |> mutation_result(@move_article_query, variables, "moveArticle") {:ok, found} = ORM.find(CMS.Post, post.id, preload: [:original_community, :communities]) assoc_communities = found.communities |> Enum.map(& &1.id) diff --git a/test/groupher_server_web/mutation/cms/article_community/repo_test.exs b/test/groupher_server_web/mutation/cms/article_community/repo_test.exs index cbcad59f8..7c629fe31 100644 --- a/test/groupher_server_web/mutation/cms/article_community/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/repo_test.exs @@ -116,8 +116,8 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do describe "[mirror/unmirror/move psot to/from community]" do @mirror_article_query """ - mutation($id: ID!, $communityId: ID!) { - mirrorArticle(id: $id, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $communityId: ID!) { + mirrorArticle(id: $id, thread: $thread, communityId: $communityId) { id } } @@ -127,7 +127,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do rule_conn = simu_conn(:user, cms: passport_rules) {:ok, community} = db_insert(:community) - variables = %{id: repo.id, communityId: community.id} + variables = %{id: repo.id, thread: "REPO", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :communities) @@ -137,7 +137,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do test "unauth user cannot mirror a repo to a community", ~m(user_conn guest_conn repo)a do {:ok, community} = db_insert(:community) - variables = %{id: repo.id, communityId: community.id} + variables = %{id: repo.id, thread: "REPO", communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) assert user_conn @@ -157,10 +157,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: repo.id, communityId: community.id} + variables = %{id: repo.id, thread: "REPO", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - variables = %{id: repo.id, communityId: community2.id} + variables = %{id: repo.id, thread: "REPO", communityId: community2.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :communities) @@ -171,13 +171,13 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do end @unmirror_article_query """ - mutation($id: ID!, $communityId: ID!) { - unmirrorArticle(id: $id, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $communityId: ID!) { + unmirrorArticle(id: $id, thread: $thread, communityId: $communityId) { id } } """ - @tag :wip2 + @tag :wip3 test "auth user can unmirror repo to a community", ~m(repo)a do passport_rules = %{"repo.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) @@ -185,10 +185,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: repo.id, communityId: community.id} + variables = %{id: repo.id, thread: "REPO", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") - variables2 = %{id: repo.id, communityId: community2.id} + variables2 = %{id: repo.id, thread: "REPO", communityId: community2.id} rule_conn |> mutation_result(@mirror_article_query, variables2, "mirrorArticle") {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :communities) @@ -208,8 +208,8 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do end @move_article_query """ - mutation($id: ID!, $communityId: ID!) { - moveArticle(id: $id, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $communityId: ID!) { + moveArticle(id: $id, thread: $thread, communityId: $communityId) { id } } @@ -222,7 +222,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do {:ok, community} = db_insert(:community) {:ok, community2} = db_insert(:community) - variables = %{id: repo.id, communityId: community.id} + variables = %{id: repo.id, thread: "REPO", communityId: community.id} rule_conn |> mutation_result(@mirror_article_query, variables, "mirrorArticle") {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: [:original_community, :communities]) assoc_communities = found.communities |> Enum.map(& &1.id) @@ -233,7 +233,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do pre_original_community_id = found.original_community.id - variables = %{id: repo.id, communityId: community2.id} + variables = %{id: repo.id, thread: "REPO", communityId: community2.id} rule_conn |> mutation_result(@move_article_query, variables, "moveArticle") {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: [:original_community, :communities]) assoc_communities = found.communities |> Enum.map(& &1.id) diff --git a/test/groupher_server_web/mutation/cms/articles/job_test.exs b/test/groupher_server_web/mutation/cms/articles/job_test.exs index 9348d1973..02ed66ff1 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -68,7 +68,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do } } """ - @tag :wip2 + @tag :wip3 test "create job with valid attrs and make sure author exsit" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) diff --git a/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs index b143c87b0..a824fb5ee 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs @@ -91,7 +91,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.JobReport do assert results["totalCount"] == 1 end - @tag :wip2 + @tag :wip3 test "support article_comment", ~m(guest_conn job user)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "comment", user) {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) diff --git a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs index f4701901a..e0260ea7a 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs @@ -91,7 +91,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do assert results["totalCount"] == 1 end - @tag :wip2 + @tag :wip3 test "support article_comment", ~m(guest_conn post user)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "comment", user) {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) From 97e3e235f1a03641a25ce36c940de2a6fe48b254 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 15 May 2021 08:33:11 +0800 Subject: [PATCH 4/4] refactor: fix thread error --- .../cms/article_community/job_test.exs | 21 +++++++++++-------- .../cms/article_community/post_test.exs | 21 +++++++++++-------- .../cms/article_community/repo_test.exs | 21 +++++++++++-------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/test/groupher_server_web/mutation/cms/article_community/job_test.exs b/test/groupher_server_web/mutation/cms/article_community/job_test.exs index 0214d7bab..de9dcebc5 100644 --- a/test/groupher_server_web/mutation/cms/article_community/job_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/job_test.exs @@ -17,13 +17,14 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do describe "[mutation job tag]" do @set_tag_query """ - mutation($id: ID!, $tagId: ID! $communityId: ID!) { - setTag(id: $id, tagId: $tagId, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $tagId: ID! $communityId: ID!) { + setTag(id: $id, thread: $thread, tagId: $tagId, communityId: $communityId) { id title } } """ + @tag :wip2 test "auth user can set a valid tag to job", ~m(job)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "job", community: community}) @@ -31,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do passport_rules = %{community.title => %{"job.tag.set" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - variables = %{id: job.id, tagId: tag.id, communityId: community.id} + variables = %{id: job.id, thread: "JOB", tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") {:ok, found} = ORM.find(CMS.Job, job.id, preload: :tags) @@ -51,6 +52,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do # assert rule_conn |> mutation_get_error?(@set_tag_query, variables) # end + @tag :wip2 test "can set multi tag to a job", ~m(job)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "job", community: community}) @@ -59,10 +61,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do passport_rules = %{community.title => %{"job.tag.set" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - variables = %{id: job.id, tagId: tag.id, communityId: community.id} + variables = %{id: job.id, thread: "JOB", tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") - variables2 = %{id: job.id, tagId: tag2.id, communityId: community.id} + variables2 = %{id: job.id, thread: "JOB", tagId: tag2.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") {:ok, found} = ORM.find(CMS.Job, job.id, preload: :tags) @@ -73,13 +75,14 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do end @unset_tag_query """ - mutation($id: ID!, $tagId: ID!, $communityId: ID!) { - unsetTag(id: $id, tagId: $tagId, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $tagId: ID! $communityId: ID!) { + unsetTag(id: $id, thread: $thread, tagId: $tagId, communityId: $communityId) { id title } } """ + @tag :wip2 test "can unset tag to a job", ~m(job)a do {:ok, community} = db_insert(:community) @@ -89,10 +92,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do {:ok, tag} = db_insert(:tag, %{thread: "job", community: community}) {:ok, tag2} = db_insert(:tag, %{thread: "job", community: community}) - variables = %{id: job.id, tagId: tag.id, communityId: community.id} + variables = %{id: job.id, thread: "JOB", tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") - variables2 = %{id: job.id, tagId: tag2.id, communityId: community.id} + variables2 = %{id: job.id, thread: "JOB", tagId: tag2.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") {:ok, found} = ORM.find(CMS.Job, job.id, preload: :tags) diff --git a/test/groupher_server_web/mutation/cms/article_community/post_test.exs b/test/groupher_server_web/mutation/cms/article_community/post_test.exs index 27984f098..fbf247a53 100644 --- a/test/groupher_server_web/mutation/cms/article_community/post_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/post_test.exs @@ -17,13 +17,14 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do describe "[mutation post tag]" do @set_tag_query """ - mutation($id: ID!, $tagId: ID! $communityId: ID!) { - setTag(id: $id, tagId: $tagId, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $tagId: ID! $communityId: ID!) { + setTag(id: $id, thread: $thread, tagId: $tagId, communityId: $communityId) { id title } } """ + @tag :wip2 test "auth user can set a valid tag to post", ~m(post)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) @@ -31,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do passport_rules = %{community.title => %{"post.tag.set" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - variables = %{id: post.id, tagId: tag.id, communityId: community.id} + variables = %{id: post.id, thread: "POST", tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) @@ -51,6 +52,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do # assert rule_conn |> mutation_get_error?(@set_tag_query, variables) # end + @tag :wip2 test "can set multi tag to a post", ~m(post)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) @@ -59,10 +61,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do passport_rules = %{community.title => %{"post.tag.set" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - variables = %{id: post.id, tagId: tag.id, communityId: community.id} + variables = %{id: post.id, thread: "POST", tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") - variables2 = %{id: post.id, tagId: tag2.id, communityId: community.id} + variables2 = %{id: post.id, thread: "POST", tagId: tag2.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) @@ -73,13 +75,14 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do end @unset_tag_query """ - mutation($id: ID!, $tagId: ID!, $communityId: ID!) { - unsetTag(id: $id, tagId: $tagId, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $tagId: ID! $communityId: ID!) { + unsetTag(id: $id, thread: $thread, tagId: $tagId, communityId: $communityId) { id title } } """ + @tag :wip2 test "can unset tag to a post", ~m(post)a do {:ok, community} = db_insert(:community) @@ -89,10 +92,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) {:ok, tag2} = db_insert(:tag, %{thread: "post", community: community}) - variables = %{id: post.id, tagId: tag.id, communityId: community.id} + variables = %{id: post.id, thread: "POST", tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") - variables2 = %{id: post.id, tagId: tag2.id, communityId: community.id} + variables2 = %{id: post.id, thread: "POST", tagId: tag2.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") {:ok, found} = ORM.find(CMS.Post, post.id, preload: :tags) diff --git a/test/groupher_server_web/mutation/cms/article_community/repo_test.exs b/test/groupher_server_web/mutation/cms/article_community/repo_test.exs index 7c629fe31..dbc77b040 100644 --- a/test/groupher_server_web/mutation/cms/article_community/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/repo_test.exs @@ -17,13 +17,14 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do describe "[mutation repo tag]" do @set_tag_query """ - mutation($id: ID!, $tagId: ID! $communityId: ID!) { - setTag(id: $id, tagId: $tagId, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $tagId: ID! $communityId: ID!) { + setTag(id: $id, thread: $thread, tagId: $tagId, communityId: $communityId) { id title } } """ + @tag :wip2 test "auth user can set a valid tag to repo", ~m(repo)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "repo", community: community}) @@ -31,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do passport_rules = %{community.title => %{"repo.tag.set" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - variables = %{id: repo.id, tagId: tag.id, communityId: community.id} + variables = %{id: repo.id, thread: "REPO", tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :tags) @@ -51,6 +52,7 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do # assert rule_conn |> mutation_get_error?(@set_tag_query, variables) # end + @tag :wip2 test "can set multi tag to a repo", ~m(repo)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "repo", community: community}) @@ -59,10 +61,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do passport_rules = %{community.title => %{"repo.tag.set" => true}} rule_conn = simu_conn(:user, cms: passport_rules) - variables = %{id: repo.id, tagId: tag.id, communityId: community.id} + variables = %{id: repo.id, thread: "REPO", tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") - variables2 = %{id: repo.id, tagId: tag2.id, communityId: community.id} + variables2 = %{id: repo.id, thread: "REPO", tagId: tag2.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :tags) @@ -73,13 +75,14 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do end @unset_tag_query """ - mutation($id: ID!, $tagId: ID!, $communityId: ID!) { - unsetTag(id: $id, tagId: $tagId, communityId: $communityId) { + mutation($id: ID!, $thread: Thread, $tagId: ID! $communityId: ID!) { + unsetTag(id: $id, thread: $thread, tagId: $tagId, communityId: $communityId) { id title } } """ + @tag :wip2 test "can unset tag to a repo", ~m(repo)a do {:ok, community} = db_insert(:community) @@ -89,10 +92,10 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do {:ok, tag} = db_insert(:tag, %{thread: "repo", community: community}) {:ok, tag2} = db_insert(:tag, %{thread: "repo", community: community}) - variables = %{id: repo.id, tagId: tag.id, communityId: community.id} + variables = %{id: repo.id, thread: "REPO", tagId: tag.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables, "setTag") - variables2 = %{id: repo.id, tagId: tag2.id, communityId: community.id} + variables2 = %{id: repo.id, thread: "REPO", tagId: tag2.id, communityId: community.id} rule_conn |> mutation_result(@set_tag_query, variables2, "setTag") {:ok, found} = ORM.find(CMS.Repo, repo.id, preload: :tags)