diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index 5338af41a..86fc2cb93 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -430,9 +430,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do defp add_rich_text_attrs(attrs), do: attrs - # except Job, other article will just pass, should use set_article_tags function instead - # defp exec_update_tags(_, _tags_ids), do: {:ok, :pass} - defp update_viewed_user_list(%{meta: nil} = article, user_id) do new_ids = Enum.uniq([user_id] ++ @default_article_meta.viewed_user_ids) meta = @default_article_meta |> Map.merge(%{viewed_user_ids: new_ids}) diff --git a/lib/groupher_server/cms/delegates/article_tag.ex b/lib/groupher_server/cms/delegates/article_tag.ex index 947d11d6c..7546624b8 100644 --- a/lib/groupher_server/cms/delegates/article_tag.ex +++ b/lib/groupher_server/cms/delegates/article_tag.ex @@ -72,12 +72,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleTag do end # check if the tag to be set is in same community & thread - defp is_article_tag_in_some_thread?(article_tags, filter) do + defp is_article_tag_in_some_thread?(article_tag_ids, filter) do with {:ok, paged_article_tags} <- paged_article_tags(filter) do domain_tags_ids = Enum.map(paged_article_tags.entries, &to_string(&1.id)) - cur_tags_ids = Enum.map(article_tags, &to_string(&1.id)) + article_tag_ids = Enum.map(article_tag_ids, &to_string(&1)) - Enum.all?(cur_tags_ids, &Enum.member?(domain_tags_ids, &1)) + Enum.all?(article_tag_ids, &Enum.member?(domain_tags_ids, &1)) end end @@ -86,15 +86,11 @@ defmodule GroupherServer.CMS.Delegate.ArticleTag do used for create article with article_tags in args """ - def set_article_tags(%Community{id: cid}, thread, article, %{article_tags: article_tags}) do + def set_article_tags(%Community{id: cid}, thread, article, %{article_tags: article_tag_ids}) do check_filter = %{page: 1, size: 100, community_id: cid, thread: thread} - with true <- is_article_tag_in_some_thread?(article_tags, check_filter) do - Enum.each(article_tags, fn article_tag -> - set_article_tag(thread, article, article_tag.id) - end) - - {:ok, :pass} + with true <- is_article_tag_in_some_thread?(article_tag_ids, check_filter) do + Enum.each(article_tag_ids, &set_article_tag(thread, article, &1)) |> done else false -> raise_error(:invalid_domain_tag, "tag not in same community & thread") end diff --git a/lib/groupher_server_web/schema/Helper/metrics.ex b/lib/groupher_server_web/schema/Helper/metrics.ex index 09c1ae223..048629e7b 100644 --- a/lib/groupher_server_web/schema/Helper/metrics.ex +++ b/lib/groupher_server_web/schema/Helper/metrics.ex @@ -27,10 +27,6 @@ defmodule GroupherServerWeb.Schema.Helper.Metrics do pagination_fields() end - input_object :ids do - field(:id, :id) - end - input_object :common_paged_filter do pagination_args() field(:sort, :inserted_sort_enum, default_value: :desc_inserted) diff --git a/lib/groupher_server_web/schema/cms/mutations/blog.ex b/lib/groupher_server_web/schema/cms/mutations/blog.ex index 3a159419e..01bf3cee4 100644 --- a/lib/groupher_server_web/schema/cms/mutations/blog.ex +++ b/lib/groupher_server_web/schema/cms/mutations/blog.ex @@ -15,7 +15,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Blog do arg(:community_id, non_null(:id)) arg(:link_addr, :string) arg(:thread, :thread, default_value: :blog) - arg(:article_tags, list_of(:ids)) + arg(:article_tags, list_of(:id)) middleware(M.Authorize, :login) middleware(M.PublishThrottle) @@ -34,7 +34,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Blog do arg(:company, :string) arg(:company_link, :string) - arg(:article_tags, list_of(:ids)) + arg(:article_tags, list_of(:id)) # ... diff --git a/lib/groupher_server_web/schema/cms/mutations/job.ex b/lib/groupher_server_web/schema/cms/mutations/job.ex index 40031999d..52a4f0989 100644 --- a/lib/groupher_server_web/schema/cms/mutations/job.ex +++ b/lib/groupher_server_web/schema/cms/mutations/job.ex @@ -21,7 +21,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Job do arg(:copy_right, :string) arg(:thread, :thread, default_value: :job) - arg(:article_tags, list_of(:ids)) + arg(:article_tags, list_of(:id)) middleware(M.Authorize, :login) middleware(M.PublishThrottle) @@ -42,7 +42,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Job do arg(:company, :string) arg(:company_link, :string) - arg(:article_tags, list_of(:ids)) + arg(:article_tags, list_of(:id)) # ... diff --git a/lib/groupher_server_web/schema/cms/mutations/post.ex b/lib/groupher_server_web/schema/cms/mutations/post.ex index fab287082..b428f6374 100644 --- a/lib/groupher_server_web/schema/cms/mutations/post.ex +++ b/lib/groupher_server_web/schema/cms/mutations/post.ex @@ -17,7 +17,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Post do arg(:copy_right, :string) arg(:community_id, non_null(:id)) arg(:thread, :thread, default_value: :post) - arg(:article_tags, list_of(:ids)) + arg(:article_tags, list_of(:id)) middleware(M.Authorize, :login) # middleware(M.PublishThrottle) @@ -34,7 +34,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Post do arg(:digest, :string) arg(:copy_right, :string) arg(:link_addr, :string) - arg(:article_tags, list_of(:ids)) + arg(:article_tags, list_of(:id)) middleware(M.Authorize, :login) middleware(M.PassportLoader, source: :post) diff --git a/lib/groupher_server_web/schema/cms/mutations/repo.ex b/lib/groupher_server_web/schema/cms/mutations/repo.ex index 84d699a11..2eb8ad8b7 100644 --- a/lib/groupher_server_web/schema/cms/mutations/repo.ex +++ b/lib/groupher_server_web/schema/cms/mutations/repo.ex @@ -31,7 +31,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Repo do arg(:community_id, non_null(:id)) arg(:thread, :thread, default_value: :repo) - arg(:article_tags, list_of(:ids)) + arg(:article_tags, list_of(:id)) middleware(M.Authorize, :login) middleware(M.PublishThrottle) diff --git a/test/groupher_server/cms/article_tags/blog_tag_test.exs b/test/groupher_server/cms/article_tags/blog_tag_test.exs index c2da1dba8..2b88e1145 100644 --- a/test/groupher_server/cms/article_tags/blog_tag_test.exs +++ b/test/groupher_server/cms/article_tags/blog_tag_test.exs @@ -12,9 +12,9 @@ defmodule GroupherServer.Test.CMS.ArticleTag.BlogTag do article_tag_attrs = mock_attrs(:article_tag) article_tag_attrs2 = mock_attrs(:article_tag) - post_attrs = mock_attrs(:blog) + blog_attrs = mock_attrs(:blog) - {:ok, ~m(user community blog post_attrs article_tag_attrs article_tag_attrs2)a} + {:ok, ~m(user community blog blog_attrs article_tag_attrs article_tag_attrs2)a} end describe "[blog tag CURD]" do @@ -80,14 +80,13 @@ defmodule GroupherServer.Test.CMS.ArticleTag.BlogTag do describe "[create/update blog with tags]" do test "can create blog with exsited article tags", - ~m(community user post_attrs article_tag_attrs article_tag_attrs2)a do + ~m(community user blog_attrs article_tag_attrs article_tag_attrs2)a do {:ok, article_tag} = CMS.create_article_tag(community, :blog, article_tag_attrs, user) {:ok, article_tag2} = CMS.create_article_tag(community, :blog, article_tag_attrs2, user) - post_with_tags = - Map.merge(post_attrs, %{article_tags: [%{id: article_tag.id}, %{id: article_tag2.id}]}) + blog_with_tags = Map.merge(blog_attrs, %{article_tags: [article_tag.id, article_tag2.id]}) - {:ok, created} = CMS.create_article(community, :blog, post_with_tags, user) + {:ok, created} = CMS.create_article(community, :blog, blog_with_tags, user) {:ok, blog} = ORM.find(Blog, created.id, preload: :article_tags) assert exist_in?(article_tag, blog.article_tags) @@ -95,15 +94,14 @@ defmodule GroupherServer.Test.CMS.ArticleTag.BlogTag do end test "can not create blog with other community's article tags", - ~m(community user post_attrs article_tag_attrs article_tag_attrs2)a do + ~m(community user blog_attrs article_tag_attrs article_tag_attrs2)a do {:ok, community2} = db_insert(:community) {:ok, article_tag} = CMS.create_article_tag(community, :blog, article_tag_attrs, user) {:ok, article_tag2} = CMS.create_article_tag(community2, :blog, article_tag_attrs2, user) - post_with_tags = - Map.merge(post_attrs, %{article_tags: [%{id: article_tag.id}, %{id: article_tag2.id}]}) + blog_with_tags = Map.merge(blog_attrs, %{article_tags: [article_tag.id, article_tag2.id]}) - {:error, reason} = CMS.create_article(community, :blog, post_with_tags, user) + {:error, reason} = CMS.create_article(community, :blog, blog_with_tags, user) is_error?(reason, :invalid_domain_tag) end end diff --git a/test/groupher_server/cms/article_tags/job_tag_test.exs b/test/groupher_server/cms/article_tags/job_tag_test.exs index 794ff8fe1..e93f8ae2b 100644 --- a/test/groupher_server/cms/article_tags/job_tag_test.exs +++ b/test/groupher_server/cms/article_tags/job_tag_test.exs @@ -12,9 +12,9 @@ defmodule GroupherServer.Test.CMS.ArticleTag.JobTag do article_tag_attrs = mock_attrs(:article_tag) article_tag_attrs2 = mock_attrs(:article_tag) - post_attrs = mock_attrs(:job) + job_attrs = mock_attrs(:job) - {:ok, ~m(user community job post_attrs article_tag_attrs article_tag_attrs2)a} + {:ok, ~m(user community job job_attrs article_tag_attrs article_tag_attrs2)a} end describe "[job tag CURD]" do @@ -80,14 +80,13 @@ defmodule GroupherServer.Test.CMS.ArticleTag.JobTag do describe "[create/update job with tags]" do test "can create job with exsited article tags", - ~m(community user post_attrs article_tag_attrs article_tag_attrs2)a do + ~m(community user job_attrs article_tag_attrs article_tag_attrs2)a do {:ok, article_tag} = CMS.create_article_tag(community, :job, article_tag_attrs, user) {:ok, article_tag2} = CMS.create_article_tag(community, :job, article_tag_attrs2, user) - post_with_tags = - Map.merge(post_attrs, %{article_tags: [%{id: article_tag.id}, %{id: article_tag2.id}]}) + job_with_tags = Map.merge(job_attrs, %{article_tags: [article_tag.id, article_tag2.id]}) - {:ok, created} = CMS.create_article(community, :job, post_with_tags, user) + {:ok, created} = CMS.create_article(community, :job, job_with_tags, user) {:ok, job} = ORM.find(Job, created.id, preload: :article_tags) assert exist_in?(article_tag, job.article_tags) @@ -95,15 +94,14 @@ defmodule GroupherServer.Test.CMS.ArticleTag.JobTag do end test "can not create job with other community's article tags", - ~m(community user post_attrs article_tag_attrs article_tag_attrs2)a do + ~m(community user job_attrs article_tag_attrs article_tag_attrs2)a do {:ok, community2} = db_insert(:community) {:ok, article_tag} = CMS.create_article_tag(community, :job, article_tag_attrs, user) {:ok, article_tag2} = CMS.create_article_tag(community2, :job, article_tag_attrs2, user) - post_with_tags = - Map.merge(post_attrs, %{article_tags: [%{id: article_tag.id}, %{id: article_tag2.id}]}) + job_with_tags = Map.merge(job_attrs, %{article_tags: [article_tag.id, article_tag2.id]}) - {:error, reason} = CMS.create_article(community, :job, post_with_tags, user) + {:error, reason} = CMS.create_article(community, :job, job_with_tags, user) is_error?(reason, :invalid_domain_tag) end end diff --git a/test/groupher_server/cms/article_tags/post_tag_test.exs b/test/groupher_server/cms/article_tags/post_tag_test.exs index c3bf06faa..b80c9ee2f 100644 --- a/test/groupher_server/cms/article_tags/post_tag_test.exs +++ b/test/groupher_server/cms/article_tags/post_tag_test.exs @@ -84,8 +84,7 @@ defmodule GroupherServer.Test.CMS.ArticleTag.PostTag do {:ok, article_tag} = CMS.create_article_tag(community, :post, article_tag_attrs, user) {:ok, article_tag2} = CMS.create_article_tag(community, :post, article_tag_attrs2, user) - post_with_tags = - Map.merge(post_attrs, %{article_tags: [%{id: article_tag.id}, %{id: article_tag2.id}]}) + post_with_tags = Map.merge(post_attrs, %{article_tags: [article_tag.id, article_tag2.id]}) {:ok, created} = CMS.create_article(community, :post, post_with_tags, user) {:ok, post} = ORM.find(Post, created.id, preload: :article_tags) @@ -100,8 +99,7 @@ defmodule GroupherServer.Test.CMS.ArticleTag.PostTag do {:ok, article_tag} = CMS.create_article_tag(community, :post, article_tag_attrs, user) {:ok, article_tag2} = CMS.create_article_tag(community2, :post, article_tag_attrs2, user) - post_with_tags = - Map.merge(post_attrs, %{article_tags: [%{id: article_tag.id}, %{id: article_tag2.id}]}) + post_with_tags = Map.merge(post_attrs, %{article_tags: [article_tag.id, article_tag2.id]}) {:error, reason} = CMS.create_article(community, :post, post_with_tags, user) is_error?(reason, :invalid_domain_tag) diff --git a/test/groupher_server/cms/article_tags/repo_tag_test.exs b/test/groupher_server/cms/article_tags/repo_tag_test.exs index b3f28b725..5ce0ceae7 100644 --- a/test/groupher_server/cms/article_tags/repo_tag_test.exs +++ b/test/groupher_server/cms/article_tags/repo_tag_test.exs @@ -12,9 +12,9 @@ defmodule GroupherServer.Test.CMS.ArticleTag.RepoTag do article_tag_attrs = mock_attrs(:article_tag) article_tag_attrs2 = mock_attrs(:article_tag) - post_attrs = mock_attrs(:repo) + repo_attrs = mock_attrs(:repo) - {:ok, ~m(user community repo post_attrs article_tag_attrs article_tag_attrs2)a} + {:ok, ~m(user community repo repo_attrs article_tag_attrs article_tag_attrs2)a} end describe "[repo tag CURD]" do @@ -80,14 +80,13 @@ defmodule GroupherServer.Test.CMS.ArticleTag.RepoTag do describe "[create/update repo with tags]" do test "can create repo with exsited article tags", - ~m(community user post_attrs article_tag_attrs article_tag_attrs2)a do + ~m(community user repo_attrs article_tag_attrs article_tag_attrs2)a do {:ok, article_tag} = CMS.create_article_tag(community, :repo, article_tag_attrs, user) {:ok, article_tag2} = CMS.create_article_tag(community, :repo, article_tag_attrs2, user) - post_with_tags = - Map.merge(post_attrs, %{article_tags: [%{id: article_tag.id}, %{id: article_tag2.id}]}) + repo_with_tags = Map.merge(repo_attrs, %{article_tags: [article_tag.id, article_tag2.id]}) - {:ok, created} = CMS.create_article(community, :repo, post_with_tags, user) + {:ok, created} = CMS.create_article(community, :repo, repo_with_tags, user) {:ok, repo} = ORM.find(Repo, created.id, preload: :article_tags) assert exist_in?(article_tag, repo.article_tags) @@ -95,15 +94,14 @@ defmodule GroupherServer.Test.CMS.ArticleTag.RepoTag do end test "can not create repo with other community's article tags", - ~m(community user post_attrs article_tag_attrs article_tag_attrs2)a do + ~m(community user repo_attrs article_tag_attrs article_tag_attrs2)a do {:ok, community2} = db_insert(:community) {:ok, article_tag} = CMS.create_article_tag(community, :repo, article_tag_attrs, user) {:ok, article_tag2} = CMS.create_article_tag(community2, :repo, article_tag_attrs2, user) - post_with_tags = - Map.merge(post_attrs, %{article_tags: [%{id: article_tag.id}, %{id: article_tag2.id}]}) + repo_with_tags = Map.merge(repo_attrs, %{article_tags: [article_tag.id, article_tag2.id]}) - {:error, reason} = CMS.create_article(community, :repo, post_with_tags, user) + {:error, reason} = CMS.create_article(community, :repo, repo_with_tags, user) is_error?(reason, :invalid_domain_tag) end end diff --git a/test/groupher_server_web/mutation/accounts/mailbox_test.exs b/test/groupher_server_web/mutation/accounts/mailbox_test.exs index 6a7f82312..3345f8417 100644 --- a/test/groupher_server_web/mutation/accounts/mailbox_test.exs +++ b/test/groupher_server_web/mutation/accounts/mailbox_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.Accounts.Mailbox do +defmodule GroupherServer.Test.Mutaion.Accounts.Mailbox do use GroupherServer.TestTools alias GroupherServer.Delivery @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Accounts.Mailbox do mention = mentions.entries |> List.first() variables = %{ids: [mention.id], type: "MENTION"} - result = user_conn |> mutation_result(@query, variables, "markRead") + user_conn |> mutation_result(@query, variables, "markRead") {:ok, mentions} = Delivery.fetch(:mention, user, %{page: 1, size: 10, read: true}) mention = mentions.entries |> List.first() @@ -44,7 +44,7 @@ defmodule GroupherServer.Test.Query.Accounts.Mailbox do notify = notifications.entries |> List.first() variables = %{ids: [notify.id], type: "NOTIFICATION"} - result = user_conn |> mutation_result(@query, variables, "markRead") + user_conn |> mutation_result(@query, variables, "markRead") {:ok, notifications} = Delivery.fetch(:notification, user, %{page: 1, size: 10, read: true}) notify = notifications.entries |> List.first() @@ -68,7 +68,7 @@ defmodule GroupherServer.Test.Query.Accounts.Mailbox do assert mentions.total_count == 2 variables = %{type: "MENTION"} - result = user_conn |> mutation_result(@query, variables, "markReadAll") + user_conn |> mutation_result(@query, variables, "markReadAll") {:ok, mentions} = Delivery.fetch(:mention, user, %{page: 1, size: 10, read: true}) assert mentions.total_count == 2 @@ -81,7 +81,7 @@ defmodule GroupherServer.Test.Query.Accounts.Mailbox do assert notifications.total_count == 1 variables = %{type: "NOTIFICATION"} - result = user_conn |> mutation_result(@query, variables, "markReadAll") + user_conn |> mutation_result(@query, variables, "markReadAll") {:ok, notifications} = Delivery.fetch(:notification, user, %{page: 1, size: 10, read: true}) assert notifications.total_count == 1 diff --git a/test/groupher_server_web/mutation/cms/articles/blog_test.exs b/test/groupher_server_web/mutation/cms/articles/blog_test.exs index 2fbc893db..94992996b 100644 --- a/test/groupher_server_web/mutation/cms/articles/blog_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/blog_test.exs @@ -9,12 +9,13 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do setup do {:ok, blog} = db_insert(:blog) {:ok, user} = db_insert(:user) + {:ok, community} = db_insert(:community) guest_conn = simu_conn(:guest) user_conn = simu_conn(:user) owner_conn = simu_conn(:owner, blog) - {:ok, ~m(user_conn guest_conn owner_conn user blog)a} + {:ok, ~m(user_conn guest_conn owner_conn community user blog)a} end describe "[mutation blog curd]" do @@ -25,7 +26,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do $digest: String!, $length: Int, $communityId: ID!, - $articleTags: [Ids] + $articleTags: [Id] ) { createBlog( title: $title, @@ -67,6 +68,21 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do assert created["id"] == to_string(found.id) end + test "create blog with valid tags id list", ~m(user_conn user community)a do + article_tag_attrs = mock_attrs(:article_tag) + {:ok, article_tag} = CMS.create_article_tag(community, :blog, article_tag_attrs, user) + + blog_attr = mock_attrs(:blog) + + variables = + blog_attr |> Map.merge(%{communityId: community.id, articleTags: [article_tag.id]}) + + created = user_conn |> mutation_result(@create_blog_query, variables, "createBlog") + {:ok, blog} = ORM.find(Blog, created["id"], preload: :article_tags) + + assert exist_in?(%{id: article_tag.id}, blog.article_tags) + end + test "create blog should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) 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 e8ebcd078..7a7d7bb6a 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -9,12 +9,13 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do setup do {:ok, job} = db_insert(:job) {:ok, user} = db_insert(:user) + {:ok, community} = db_insert(:community) guest_conn = simu_conn(:guest) user_conn = simu_conn(:user) owner_conn = simu_conn(:owner, job) - {:ok, ~m(user_conn guest_conn owner_conn user job)a} + {:ok, ~m(user_conn guest_conn owner_conn user community job)a} end describe "[mutation job curd]" do @@ -26,7 +27,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do $length: Int!, $communityId: ID!, $company: String!, - $articleTags: [Ids] + $articleTags: [Id] ) { createJob( title: $title, @@ -50,7 +51,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do } } """ - test "create job with valid attrs and make sure author exsit" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) @@ -70,6 +70,21 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do assert created["id"] == to_string(found.id) end + test "create job with valid tags id list.", ~m(user_conn user community)a do + article_tag_attrs = mock_attrs(:article_tag) + {:ok, article_tag} = CMS.create_article_tag(community, :job, article_tag_attrs, user) + + job_attr = mock_attrs(:job) + + variables = + job_attr |> Map.merge(%{communityId: community.id, articleTags: [article_tag.id]}) + + created = user_conn |> mutation_result(@create_job_query, variables, "createJob") + {:ok, job} = ORM.find(Job, created["id"], preload: :article_tags) + + assert exist_in?(%{id: article_tag.id}, job.article_tags) + end + test "create job should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) diff --git a/test/groupher_server_web/mutation/cms/articles/post_test.exs b/test/groupher_server_web/mutation/cms/articles/post_test.exs index d6c11174d..588c52b98 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -8,13 +8,14 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do setup do {:ok, post} = db_insert(:post) + {:ok, user} = db_insert(:user) {: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} + {:ok, ~m(user_conn guest_conn owner_conn user community post)a} end describe "[mutation post curd]" do @@ -25,7 +26,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do $digest: String! $length: Int! $communityId: ID! - $articleTags: [Ids] + $articleTags: [Id] ) { createPost( title: $title @@ -61,6 +62,21 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do assert {:ok, _} = ORM.find_by(Author, user_id: user.id) end + test "create post with valid tags id list", ~m(user_conn user community)a do + article_tag_attrs = mock_attrs(:article_tag) + {:ok, article_tag} = CMS.create_article_tag(community, :post, article_tag_attrs, user) + + post_attr = mock_attrs(:post) + + variables = + post_attr |> Map.merge(%{communityId: community.id, articleTags: [article_tag.id]}) + + created = user_conn |> mutation_result(@create_post_query, variables, "createPost") + {:ok, post} = ORM.find(Post, created["id"], preload: :article_tags) + + assert exist_in?(%{id: article_tag.id}, post.article_tags) + end + test "create post should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) @@ -153,7 +169,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do end @query """ - mutation($id: ID!, $title: String, $body: String, $copyRight: String, $articleTags: [Ids]){ + mutation($id: ID!, $title: String, $body: String, $copyRight: String, $articleTags: [Id]){ updatePost(id: $id, title: $title, body: $body, copyRight: $copyRight, articleTags: $articleTags) { id title diff --git a/test/groupher_server_web/mutation/cms/articles/repo_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_test.exs index bd6be0065..658c2440a 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_test.exs @@ -8,12 +8,14 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do setup do {:ok, repo} = db_insert(:repo) + {:ok, user} = db_insert(:user) + {: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 repo)a} + {:ok, ~m(user_conn guest_conn owner_conn user community repo)a} end describe "[mutation repo curd]" do @@ -36,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do $primaryLanguage: RepoLangInput, $contributors: [RepoContributorInput], $communityId: ID!, - $articleTags: [Ids] + $articleTags: [Id] ) { createRepo( title: $title, @@ -85,6 +87,21 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do assert {:ok, _} = ORM.find_by(Author, user_id: user.id) end + test "create repo with valid tags id list.", ~m(user_conn user community)a do + article_tag_attrs = mock_attrs(:article_tag) + {:ok, article_tag} = CMS.create_article_tag(community, :repo, article_tag_attrs, user) + + repo_attr = mock_attrs(:repo) |> camelize_map_key + + variables = + repo_attr |> Map.merge(%{communityId: community.id, articleTags: [article_tag.id]}) + + created = user_conn |> mutation_result(@create_repo_query, variables, "createRepo") + {:ok, repo} = ORM.find(Repo, created["id"], preload: :article_tags) + + assert exist_in?(%{id: article_tag.id}, repo.article_tags) + end + @update_repo_query """ mutation( $id: ID!,