diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index 0c07744c0..d0ee5f017 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -254,52 +254,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do ORM.find_by(Author, user_id: changeset.data.user_id) end - defp domain_filter_query(CMS.Job = queryable, filter) do - Enum.reduce(filter, queryable, fn - {:salary, salary}, queryable -> - queryable |> where([content], content.salary == ^salary) - - {:field, field}, queryable -> - queryable |> where([content], content.field == ^field) - - {:finance, finance}, queryable -> - queryable |> where([content], content.finance == ^finance) - - {:scale, scale}, queryable -> - queryable |> where([content], content.scale == ^scale) - - {:exp, exp}, queryable -> - if exp == "不限", do: queryable, else: queryable |> where([content], content.exp == ^exp) - - {:education, education}, queryable -> - cond do - education == "大专" -> - queryable - |> where([content], content.education == "大专" or content.education == "不限") - - education == "本科" -> - queryable - |> where([content], content.education != "不限") - |> where([content], content.education != "大专") - - education == "硕士" -> - queryable - |> where([content], content.education != "不限") - |> where([content], content.education != "大专") - |> where([content], content.education != "本科") - - education == "不限" -> - queryable - - true -> - queryable |> where([content], content.education == ^education) - end - - {_, _}, queryable -> - queryable - end) - end - defp domain_filter_query(CMS.Repo = queryable, filter) do Enum.reduce(filter, queryable, fn {:sort, :most_github_star}, queryable -> @@ -327,12 +281,11 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do defp add_pin_articles_ifneed(articles, querable, %{community: community} = filter) do thread = module_to_thread(querable) - with {:ok, _} <- should_add_pin?(filter), + with true <- should_add_pin?(filter), true <- 1 == Map.get(articles, :page_number), {:ok, pinned_articles} <- PinnedArticle |> join(:inner, [p], c in assoc(p, :community)) - # |> join(:inner, [p], article in assoc(p, ^filter.thread)) |> join(:inner, [p], article in assoc(p, ^thread)) |> where([p, c, article], c.raw == ^community) |> select([p, c, article], article) @@ -347,13 +300,13 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do defp add_pin_articles_ifneed(articles, _querable, _filter), do: articles # if filter contains like: tags, sort.., then don't add pin article - # TODO: tag - # defp should_add_pin?(%{page: 1, article_tag: :all, sort: :desc_inserted} = _filter) do - defp should_add_pin?(%{page: 1, sort: :desc_inserted} = _filter) do - {:ok, :pass} + defp should_add_pin?(%{page: 1, sort: :desc_inserted} = filter) do + skip_pinned_fields = [:article_tag, :article_tags] + + not Enum.any?(Map.keys(filter), &(&1 in skip_pinned_fields)) end - defp should_add_pin?(_filter), do: {:error, :pass} + defp should_add_pin?(_filter), do: false defp concat_articles(%{total_count: 0}, non_pinned_articles), do: non_pinned_articles diff --git a/lib/groupher_server/cms/job.ex b/lib/groupher_server/cms/job.ex index c78a0bc8e..e86f964d5 100644 --- a/lib/groupher_server/cms/job.ex +++ b/lib/groupher_server/cms/job.ex @@ -13,30 +13,20 @@ defmodule GroupherServer.CMS.Job do alias Helper.HTML @timestamps_opts [type: :utc_datetime_usec] - @required_fields ~w(title company company_logo body digest length)a + @required_fields ~w(title company body digest length)a @article_cast_fields general_article_fields(:cast) - @optional_fields @article_cast_fields ++ - ~w(desc company_link link_addr copy_right salary exp education field finance scale)a + @optional_fields @article_cast_fields ++ ~w(desc company_link link_addr copy_right)a @type t :: %Job{} schema "cms_jobs" do field(:title, :string) field(:company, :string) - field(:company_logo, :string) field(:company_link, :string) field(:desc, :string) field(:body, :string) field(:link_addr, :string) field(:copy_right, :string) - - field(:salary, :string) - field(:exp, :string) - field(:education, :string) - field(:field, :string) - field(:finance, :string) - field(:scale, :string) - field(:digest, :string) field(:length, :integer) diff --git a/lib/groupher_server_web/schema/Helper/fields.ex b/lib/groupher_server_web/schema/Helper/fields.ex index 169088ddb..e72b8c933 100644 --- a/lib/groupher_server_web/schema/Helper/fields.ex +++ b/lib/groupher_server_web/schema/Helper/fields.ex @@ -41,6 +41,7 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do field(:when, :when_enum) field(:length, :length_enum) field(:article_tag, :string) + field(:article_tags, list_of(:string)) field(:community, :string) end end diff --git a/lib/groupher_server_web/schema/account/account_misc.ex b/lib/groupher_server_web/schema/account/account_misc.ex deleted file mode 100644 index 1ed6a7dea..000000000 --- a/lib/groupher_server_web/schema/account/account_misc.ex +++ /dev/null @@ -1,113 +0,0 @@ -defmodule GroupherServerWeb.Schema.Account.Misc do - @moduledoc false - - use Absinthe.Schema.Notation - import GroupherServerWeb.Schema.Helper.Fields - - @desc "article_filter doc" - input_object :paged_users_filter do - pagination_args() - # field(:when, :when_enum) - # field(:sort, :sort_enum) - # field(:community, :string) - end - - input_object :github_profile_input do - # is github_id in db table - field(:id, non_null(:string)) - field(:login, non_null(:string)) - field(:avatar_url, non_null(:string)) - field(:url, :string) - field(:html_url, :string) - field(:name, :string) - field(:company, :string) - field(:blog, :string) - field(:location, :string) - field(:email, :string) - field(:bio, :string) - field(:public_repos, :integer) - field(:public_gists, :integer) - end - - input_object :work_background_input do - field(:company, :string) - field(:title, :string) - end - - input_object :edu_background_input do - field(:school, :string) - field(:major, :string) - end - - input_object :user_profile_input do - field(:nickname, :string) - field(:bio, :string) - field(:sex, :string) - field(:location, :string) - field(:email, :string) - end - - input_object :social_input do - social_fields() - end - - enum :cus_banner_layout_num do - value(:digest) - value(:brief) - end - - enum :cus_contents_layout_num do - value(:digest) - value(:list) - end - - input_object :customization_input do - field(:theme, :string) - field(:community_chart, :boolean) - field(:brainwash_free, :boolean) - - field(:banner_layout, :cus_banner_layout_num) - field(:contents_layout, :cus_contents_layout_num) - field(:content_divider, :boolean) - field(:content_hover, :boolean) - field(:mark_viewed, :boolean) - field(:display_density, :string) - end - - input_object :community_index do - field(:community, :string) - field(:index, :integer) - end - - # see: https://github.com/absinthe-graphql/absinthe/issues/206 - # https://github.com/absinthe-graphql/absinthe/wiki/Scalar-Recipes - scalar :json, name: "Json" do - description(""" - The `Json` scalar type represents arbitrary json string data, represented as UTF-8 - character sequences. The Json type is most often used to represent a free-form - human-readable json string. - """) - - serialize(&encode/1) - parse(&decode/1) - end - - @spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term()} | :error - @spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil} - defp decode(%Absinthe.Blueprint.Input.String{value: value}) do - case Jason.decode(value) do - {:ok, result} -> {:ok, result} - _ -> :error - end - end - - defp decode(%Absinthe.Blueprint.Input.Null{}) do - {:ok, nil} - end - - defp decode(_) do - :error - end - - defp encode(value), do: value -end diff --git a/lib/groupher_server_web/schema/cms/cms_metrics.ex b/lib/groupher_server_web/schema/cms/cms_metrics.ex index 4f6be23a2..6ee852a6e 100644 --- a/lib/groupher_server_web/schema/cms/cms_metrics.ex +++ b/lib/groupher_server_web/schema/cms/cms_metrics.ex @@ -206,13 +206,6 @@ defmodule GroupherServerWeb.Schema.CMS.Metrics do pagination_args() article_filter_fields() field(:sort, :sort_enum) - - field(:salary, :string) - field(:exp, :string) - field(:education, :string) - field(:field, :string) - field(:finance, :string) - field(:scale, :string) end @desc "article_filter doc" diff --git a/lib/groupher_server_web/schema/cms/cms_misc.ex b/lib/groupher_server_web/schema/cms/cms_misc.ex deleted file mode 100644 index 4d61a4be0..000000000 --- a/lib/groupher_server_web/schema/cms/cms_misc.ex +++ /dev/null @@ -1,337 +0,0 @@ -defmodule GroupherServerWeb.Schema.CMS.Misc do - @moduledoc """ - common metrics in queries - """ - use Absinthe.Schema.Notation - - import GroupherServerWeb.Schema.Helper.Fields - - alias GroupherServer.CMS - - @default_inner_page_size 5 - - enum(:post_thread, do: value(:post)) - enum(:job_thread, do: value(:job)) - enum(:repo_thread, do: value(:repo)) - - enum(:community_type, do: value(:community)) - enum(:comment_replies_type, do: value(:comment_replies_type)) - - enum(:count_type, do: value(:count)) - enum(:viewer_did_type, do: value(:viewer_did)) - - enum(:star_action, do: value(:star)) - enum(:comment_action, do: value(:comment)) - - enum :unique_type do - value(true) - value(false) - end - - enum :react_action do - value(:collect) - value(:upvote) - # value(:watch) - end - - enum :reactable_action do - value(:upvote) - # value(:collect) - # value(:watch) - end - - enum :cms_comment do - value(:post_comment) - end - - enum :thread do - value(:post) - value(:job) - value(:user) - value(:repo) - value(:wiki) - value(:cheatsheet) - # home community - value(:tech) - value(:city) - value(:share) - end - - enum :when_enum do - value(:today) - value(:this_week) - value(:this_month) - value(:this_year) - end - - enum :inserted_sort_enum do - value(:asc_inserted) - value(:desc_inserted) - end - - enum :thread_sort_enum do - value(:asc_index) - value(:desc_index) - value(:asc_inserted) - value(:desc_inserted) - end - - enum :sort_enum do - value(:most_views) - value(:most_updated) - value(:most_upvotes) - value(:most_stars) - value(:most_comments) - value(:least_views) - value(:least_updated) - value(:least_upvotes) - value(:least_stars) - value(:least_watched) - value(:least_comments) - value(:recent_updated) - end - - enum :repo_sort_enum do - value(:most_github_star) - value(:most_github_fork) - value(:most_github_watch) - value(:most_github_pr) - value(:most_github_issue) - value(:most_views) - value(:most_comments) - value(:recent_updated) - value(:most_upvotes) - end - - enum :length_enum do - value(:most_words) - value(:least_words) - end - - enum :rainbow_color do - value(:red) - value(:orange) - value(:yellow) - value(:green) - value(:cyan) - value(:blue) - value(:purple) - value(:dodgerblue) - value(:yellowgreen) - value(:brown) - value(:grey) - end - - @desc "emotion options of article" - enum(:article_emotion, do: emotion_enum()) - - @desc "emotion options of comment" - enum(:article_comment_emotion, do: comment_emotion_enum()) - - @desc "the filter mode for list comments" - enum :article_comments_mode do - value(:replies) - value(:timeline) - end - - @desc "inline members-like filter for dataloader usage" - input_object :members_filter do - field(:first, :integer, default_value: @default_inner_page_size) - end - - input_object :comments_filter do - pagination_args() - field(:sort, :inserted_sort_enum, default_value: :asc_inserted) - end - - input_object :communities_filter do - @desc "limit of records (default 20), if first > 30, only return 30 at most" - pagination_args() - field(:sort, :sort_enum) - field(:category, :string) - end - - input_object :threads_filter do - pagination_args() - field(:sort, :thread_sort_enum) - end - - input_object :article_tags_filter do - field(:community_id, :id) - field(:thread, :thread) - pagination_args() - end - - input_object :paged_filter do - @desc "limit of records (default 20), if first > 30, only return 30 at most" - pagination_args() - field(:sort, :sort_enum) - end - - @desc "article_filter doc" - input_object :article_filter do - @desc "limit of records (default 20), if first > 30, only return 30 at most" - field(:first, :integer) - - @desc "Matching a tag" - field(:article_tag, :string) - # field(:sort, :sort_input) - field(:when, :when_enum) - field(:sort, :sort_enum) - field(:length, :length_enum) - # @desc "Matching a tag" - # @desc "Added to the menu after this date" - # field(:added_after, :datetime) - end - - @desc "article_filter doc" - input_object :paged_article_filter do - @desc "limit of records (default 20), if first > 30, only return 30 at most" - pagination_args() - article_filter_fields() - field(:sort, :sort_enum) - end - - @desc "posts_filter doc" - input_object :paged_posts_filter do - @desc "limit of records (default 20), if first > 30, only return 30 at most" - pagination_args() - article_filter_fields() - field(:sort, :sort_enum) - end - - @desc "job_filter doc" - input_object :paged_jobs_filter do - @desc "limit of records (default 20), if first > 30, only return 30 at most" - pagination_args() - article_filter_fields() - field(:sort, :sort_enum) - - field(:salary, :string) - field(:exp, :string) - field(:education, :string) - field(:field, :string) - field(:finance, :string) - field(:scale, :string) - end - - @desc "article_filter doc" - input_object :paged_repos_filter do - @desc "limit of records (default 20), if first > 30, only return 30 at most" - pagination_args() - article_filter_fields() - - field(:sort, :repo_sort_enum) - end - - @desc "common filter for upvoted articles" - input_object :upvoted_articles_filter do - field(:thread, :thread) - pagination_args() - end - - @desc "common filter for collect folders" - input_object :collect_folders_filter do - field(:thread, :thread) - pagination_args() - end - - @desc "common filter for collect articles" - input_object :collected_articles_filter do - field(:thread, :thread) - pagination_args() - end - - @desc """ - cms github repo contribotor - """ - input_object :repo_contributor_input do - field(:avatar, :string) - field(:html_url, :string) - field(:nickname, :string) - end - - @desc """ - cms github repo contribotor, detail version - """ - input_object :github_contributor_input do - field(:github_id, non_null(:string)) - field(:avatar, non_null(:string)) - field(:html_url, non_null(:string)) - field(:nickname, non_null(:string)) - field(:bio, :string) - field(:location, :string) - field(:company, :string) - end - - @desc """ - cms github repo lang - """ - input_object :repo_lang_input do - field(:name, :string) - field(:color, :string) - end - - enum :report_content_type do - value(:post) - value(:job) - value(:repo) - value(:account) - value(:article_comment) - # value(:community) - end - - @desc """ - abuse report filter - """ - input_object :report_filter do - field(:content_type, :report_content_type) - field(:content_id, :id) - pagination_args() - # operate_user_id, - # min_case_count, - # max_case_count, - end - - @doc """ - only used for reaction result, like: upvote/collect/watch ... - """ - interface :article do - field(:id, :id) - # field(:title, :string) - - resolve_type(fn - %CMS.Post{}, _ -> :post - %CMS.Job{}, _ -> :job - %CMS.Repo{}, _ -> :repo - _, _ -> nil - end) - end - - # @desc """ - # The `DateTime` scalar type represents a date and time in the UTC - # timezone. The DateTime appears in a JSON response as an ISO8601 formatted - # string, including UTC timezone ("Z"). The parsed date and time string will - # be converted to UTC and any UTC offset other than 0 will be rejected. - # """ - # scalar :datetime, name: "DateTime" do - # serialize &DateTime.to_iso8601/1 - # parse &parse_datetime/1 - # end - - # @spec parse_datetime(Absinthe.Blueprint.Input.String.t) :: {:ok, DateTime.t} | :error - # @spec parse_datetime(Absinthe.Blueprint.Input.Null.t) :: {:ok, nil} - # defp parse_datetime(%Absinthe.Blueprint.Input.String{value: value}) do - # case DateTime.from_iso8601(value) do - # {:ok, datetime, 0} -> {:ok, datetime} - # {:ok, _datetime, _offset} -> :error - # _error -> :error - # end - # end - # defp parse_datetime(%Absinthe.Blueprint.Input.Null{}) do - # {:ok, nil} - # end - # defp parse_datetime(_) do - # :error - # end -end diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index 80c01623c..5a80a3ed2 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -109,7 +109,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:title, :string) field(:desc, :string) field(:company, :string) - field(:company_logo, :string) field(:company_link, :string) field(:digest, :string) field(:length, :integer) @@ -129,13 +128,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:meta, :article_meta) field(:emotions, :article_emotions) - field(:salary, :string) - field(:exp, :string) - field(:education, :string) - field(:field, :string) - field(:finance, :string) - field(:scale, :string) - # comments_count # comments_participators article_comments_fields() diff --git a/lib/groupher_server_web/schema/cms/mutations/job.ex b/lib/groupher_server_web/schema/cms/mutations/job.ex index 7d7dbca34..c76190402 100644 --- a/lib/groupher_server_web/schema/cms/mutations/job.ex +++ b/lib/groupher_server_web/schema/cms/mutations/job.ex @@ -10,20 +10,12 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Job do field :create_job, :job do arg(:title, non_null(:string)) arg(:company, non_null(:string)) - arg(:company_logo, non_null(:string)) arg(:company_link, :string) arg(:body, non_null(:string)) arg(:digest, non_null(:string)) arg(:length, non_null(:integer)) arg(:community_id, non_null(:id)) - arg(:salary, non_null(:string)) - arg(:exp, non_null(:string)) - arg(:education, non_null(:string)) - arg(:finance, non_null(:string)) - arg(:scale, non_null(:string)) - arg(:field, non_null(:string)) - arg(:desc, :string) arg(:link_addr, :string) arg(:copy_right, :string) @@ -45,20 +37,12 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Job do arg(:body, :string) arg(:digest, :string) arg(:length, :integer) - arg(:salary, :string) arg(:copy_right, :string) arg(:desc, :string) arg(:link_addr, :string) arg(:company, :string) - arg(:company_logo, :string) arg(:company_link, :string) - - arg(:exp, :string) - arg(:education, :string) - arg(:field, :string) - arg(:finance, :string) - arg(:scale, :string) arg(:article_tags, list_of(:ids)) # ... diff --git a/lib/helper/query_builder.ex b/lib/helper/query_builder.ex index 31e0a68c7..7c1f921be 100644 --- a/lib/helper/query_builder.ex +++ b/lib/helper/query_builder.ex @@ -170,10 +170,6 @@ defmodule Helper.QueryBuilder do |> where([p], p.inserted_at >= ^Timex.beginning_of_year(date)) |> where([p], p.inserted_at <= ^Timex.end_of_year(date)) - # TODO: remove - {_, :all}, queryable -> - queryable - {:article_tag, tag_name}, queryable -> from( q in queryable, @@ -181,6 +177,15 @@ defmodule Helper.QueryBuilder do where: t.title == ^tag_name ) + {:article_tags, tag_name_list}, queryable -> + from( + q in queryable, + join: t in assoc(q, :article_tags), + where: t.title in ^tag_name_list, + distinct: q.id, + group_by: q.id + ) + {:category, catetory_raw}, queryable -> from( q in queryable, diff --git a/priv/repo/migrations/20210531024825_remove_domain_fields_on_jobs.exs b/priv/repo/migrations/20210531024825_remove_domain_fields_on_jobs.exs new file mode 100644 index 000000000..1fab83376 --- /dev/null +++ b/priv/repo/migrations/20210531024825_remove_domain_fields_on_jobs.exs @@ -0,0 +1,14 @@ +defmodule GroupherServer.Repo.Migrations.RemoveDomainFieldsOnJobs do + use Ecto.Migration + + def change do + alter(table(:cms_jobs), do: remove(:salary)) + alter(table(:cms_jobs), do: remove(:exp)) + alter(table(:cms_jobs), do: remove(:education)) + alter(table(:cms_jobs), do: remove(:field)) + alter(table(:cms_jobs), do: remove(:finance)) + alter(table(:cms_jobs), do: remove(:scale)) + + alter(table(:cms_jobs), do: remove(:company_logo)) + end +end diff --git a/test/groupher_server/accounts/reacted_articles_test.exs b/test/groupher_server/accounts/reacted_articles_test.exs index 43237e749..cbcaa8cf3 100644 --- a/test/groupher_server/accounts/reacted_articles_test.exs +++ b/test/groupher_server/accounts/reacted_articles_test.exs @@ -14,7 +14,6 @@ defmodule GroupherServer.Test.Accounts.ReactedContents do end describe "[user upvoted articles]" do - @tag :wip2 test "user can get paged upvoted common articles", ~m(user post job)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) {:ok, _} = CMS.upvote_article(:job, job.id, 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 0ba8bd16a..fee3b699e 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -24,13 +24,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do $length: Int!, $communityId: ID!, $company: String!, - $companyLogo: String! - $salary: String!, - $exp: String!, - $education: String!, - $finance: String!, - $scale: String!, - $field: String!, $mentionUsers: [Ids], $articleTags: [Ids] ) { @@ -41,23 +34,12 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do length: $length, communityId: $communityId, company: $company, - companyLogo: $companyLogo, - salary: $salary, - exp: $exp, - education: $education, - finance: $finance, - scale: $scale, - field: $field, mentionUsers: $mentionUsers, articleTags: $articleTags ) { id title body - salary - exp - education - field originalCommunity { id } @@ -80,11 +62,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do created = user_conn |> mutation_result(@create_job_query, variables, "createJob") - assert created["salary"] == variables["salary"] - assert created["exp"] == variables["exp"] - assert created["field"] == variables["field"] - assert created["education"] == variables["education"] - {:ok, found} = ORM.find(CMS.Job, created["id"]) assert created["id"] == to_string(found.id) @@ -136,12 +113,11 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do end @query """ - mutation($id: ID!, $title: String, $body: String, $salary: String, $articleTags: [Ids]){ - updateJob(id: $id, title: $title, body: $body, salary: $salary, articleTags: $articleTags) { + mutation($id: ID!, $title: String, $body: String, $articleTags: [Ids]){ + updateJob(id: $id, title: $title, body: $body, articleTags: $articleTags) { id title body - salary articleTags { id } @@ -154,8 +130,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do variables = %{ id: job.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}", - salary: "15k-20k" + body: "updated body #{unique_num}" } assert guest_conn |> mutation_get_error?(@query, variables, ecode(:account_login)) @@ -167,15 +142,13 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do variables = %{ id: job.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}", - salary: "15k-20k" + body: "updated body #{unique_num}" } updated = owner_conn |> mutation_result(@query, variables, "updateJob") assert updated["title"] == variables.title assert updated["body"] == variables.body - assert updated["salary"] == variables.salary end test "login user with auth passport update a job", ~m(job)a do diff --git a/test/groupher_server_web/mutation/statistics/statistics_test.exs b/test/groupher_server_web/mutation/statistics/statistics_test.exs index 5080ae7ec..e9d45abe0 100644 --- a/test/groupher_server_web/mutation/statistics/statistics_test.exs +++ b/test/groupher_server_web/mutation/statistics/statistics_test.exs @@ -68,13 +68,6 @@ defmodule GroupherServer.Test.Mutation.Statistics do $length: Int!, $communityId: ID!, $company: String!, - $companyLogo: String! - $salary: String!, - $exp: String!, - $education: String!, - $finance: String!, - $scale: String!, - $field: String!, $articleTags: [Ids] ) { createJob( @@ -84,22 +77,11 @@ defmodule GroupherServer.Test.Mutation.Statistics do length: $length, communityId: $communityId, company: $company, - companyLogo: $companyLogo, - salary: $salary, - exp: $exp, - education: $education, - finance: $finance, - scale: $scale, - field: $field, articleTags: $articleTags ) { id title body - salary - exp - education - field communities { id title diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs index 9f71a0c3d..d998388f6 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs @@ -86,6 +86,66 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do assert exist_in?(article_tag, job["articleTags"], :string_key) end + test "support multi-tag (article_tags) filter", ~m(guest_conn user)a do + {:ok, community} = db_insert(:community) + job_attrs = mock_attrs(:job, %{community_id: community.id}) + {:ok, job} = CMS.create_article(community, :job, job_attrs, user) + + article_tag_attrs = mock_attrs(:article_tag) + + {:ok, article_tag} = CMS.create_article_tag(community, :job, article_tag_attrs, user) + {:ok, article_tag2} = CMS.create_article_tag(community, :job, article_tag_attrs, user) + {:ok, article_tag3} = CMS.create_article_tag(community, :job, article_tag_attrs, user) + + {:ok, _} = CMS.set_article_tag(:job, job.id, article_tag.id) + {:ok, _} = CMS.set_article_tag(:job, job.id, article_tag2.id) + + variables = %{ + filter: %{page: 1, size: 10, article_tags: [article_tag.title, article_tag2.title]} + } + + results = guest_conn |> query_result(@query, variables, "pagedJobs") + + job = results["entries"] |> List.first() + assert results["totalCount"] == 1 + assert exist_in?(article_tag, job["articleTags"], :string_key) + assert exist_in?(article_tag2, job["articleTags"], :string_key) + assert not exist_in?(article_tag3, job["articleTags"], :string_key) + end + + @tag :wip2 + test "should not have pined jobs when filter have article_tag or article_tags", + ~m(guest_conn user)a do + {:ok, community} = db_insert(:community) + job_attrs = mock_attrs(:job, %{community_id: community.id}) + {:ok, pinned_job} = CMS.create_article(community, :job, job_attrs, user) + {:ok, job} = CMS.create_article(community, :job, job_attrs, user) + + {:ok, _} = CMS.pin_article(:job, pinned_job.id, community.id) + + article_tag_attrs = mock_attrs(:article_tag) + {:ok, article_tag} = CMS.create_article_tag(community, :job, article_tag_attrs, user) + {:ok, _} = CMS.set_article_tag(:job, job.id, article_tag.id) + + variables = %{ + filter: %{page: 1, size: 10, community: community.raw, article_tag: article_tag.title} + } + + results = guest_conn |> query_result(@query, variables, "pagedJobs") + + assert not exist_in?(pinned_job, results["entries"], :string_key) + assert exist_in?(job, results["entries"], :string_key) + + variables = %{ + filter: %{page: 1, size: 10, community: community.raw, article_tags: [article_tag.title]} + } + + results = guest_conn |> query_result(@query, variables, "pagedJobs") + + assert not exist_in?(pinned_job, results["entries"], :string_key) + assert exist_in?(job, results["entries"], :string_key) + end + test "support community filter", ~m(guest_conn user)a do {:ok, community} = db_insert(:community) @@ -303,169 +363,22 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do pagedJobs(filter: $filter) { entries { id - salary - exp - field - finance - scale - education + title } totalCount } } """ - test "salary option should work", ~m(guest_conn)a do - {:ok, job} = db_insert(:job, %{salary: "2k-5k"}) - {:ok, job2} = db_insert(:job, %{salary: "5k-10k"}) - - variables = %{filter: %{page: 1, size: 20, salary: "2k-5k"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["totalCount"] >= 1 - assert results["entries"] |> Enum.all?(&(&1["salary"] == "2k-5k")) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job2.id))) - end - - test "field option should work", ~m(guest_conn)a do - {:ok, job} = db_insert(:job, %{field: "互联网"}) - {:ok, job2} = db_insert(:job, %{field: "电子商务"}) - - variables = %{filter: %{page: 1, size: 20, field: "互联网"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["totalCount"] >= 1 - assert results["entries"] |> Enum.all?(&(&1["field"] == "互联网")) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job2.id))) - end - - test "finance option should work", ~m(guest_conn)a do - {:ok, job} = db_insert(:job, %{finance: "未融资"}) - {:ok, job2} = db_insert(:job, %{finance: "天使轮"}) - - variables = %{filter: %{page: 1, size: 20, finance: "未融资"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["totalCount"] >= 1 - assert results["entries"] |> Enum.all?(&(&1["finance"] == "未融资")) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job2.id))) - end - - test "scale option should work", ~m(guest_conn)a do - {:ok, job} = db_insert(:job, %{scale: "少于15人"}) - {:ok, job2} = db_insert(:job, %{scale: "15-50人"}) - - variables = %{filter: %{page: 1, size: 20, scale: "少于15人"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["totalCount"] >= 1 - assert results["entries"] |> Enum.all?(&(&1["scale"] == "少于15人")) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job2.id))) - end + test "basic filter should work", ~m(guest_conn)a do + {:ok, job} = db_insert(:job) + {:ok, job2} = db_insert(:job) - test "exp option should work", ~m(guest_conn)a do - {:ok, job} = db_insert(:job, %{exp: "应届"}) - {:ok, job2} = db_insert(:job, %{exp: "3年以下"}) - - variables = %{filter: %{page: 1, size: 20, exp: "应届"}} + variables = %{filter: %{page: 1, size: 20}} results = guest_conn |> query_result(@query, variables, "pagedJobs") assert results["totalCount"] >= 1 - assert results["entries"] |> Enum.all?(&(&1["exp"] == "应届")) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job2.id))) - - variables = %{filter: %{page: 1, size: 20, exp: "不限"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["totalCount"] > @total_count - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job2.id))) - end - - test "education option should work", ~m(guest_conn)a do - {:ok, job} = db_insert(:job, %{education: "不限"}) - {:ok, job2} = db_insert(:job, %{education: "大专"}) - {:ok, job3} = db_insert(:job, %{education: "本科"}) - {:ok, job4} = db_insert(:job, %{education: "硕士"}) - {:ok, job5} = db_insert(:job, %{education: "博士"}) - - variables = %{filter: %{page: 1, size: 30, education: "不限"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job2.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job3.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job4.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job5.id))) - - variables = %{filter: %{page: 1, size: 30, education: "大专"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job2.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job3.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job4.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job5.id))) - - variables = %{filter: %{page: 1, size: 30, education: "本科"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job2.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job3.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job4.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job5.id))) - - variables = %{filter: %{page: 1, size: 30, education: "硕士"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job2.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job3.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job4.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job5.id))) - - variables = %{filter: %{page: 1, size: 30, education: "博士"}} - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job.id))) assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job2.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job3.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] != to_string(job4.id))) - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job5.id))) - end - - test "multi filter should work together", ~m(guest_conn)a do - {:ok, job} = - db_insert(:job, %{ - title: "hehe", - scale: "少于15人", - exp: "本科", - field: "教育", - finance: "D轮以上", - salary: "20k-50k" - }) - - variables = %{ - filter: %{ - page: 1, - size: 20, - scale: "少于15人", - exp: "本科", - field: "教育", - finance: "D轮以上", - salary: "20k-50k" - } - } - - results = guest_conn |> query_result(@query, variables, "pagedJobs") - - assert results["totalCount"] >= 1 - assert results["entries"] |> Enum.any?(&(&1["id"] == to_string(job.id))) end end end diff --git a/test/support/factory.ex b/test/support/factory.ex index b920a800b..db0c5e771 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -102,29 +102,15 @@ defmodule GroupherServer.Support.Factory do defp mock_meta(:job) do body = Faker.Lorem.sentence(%Range{first: 80, last: 120}) - salary_enum = ["2k以下", "2k-5k", "5k-10k", "10k-15k", "15k-25k", "20k-50k", "50k以上"] - exp_enum = ["不限", "应届", "3年以下", "3-5年", "5-10年", "10年以上"] - education_enum = ["不限", "大专", "本科", "硕士", "博士"] - field_enum = ["互联网", "电子商务", "金融", "企业服务", "教育", "游戏", "O2O", "区块链"] - finance_enum = ["未融资", "天使轮", "A轮", "B轮", "C轮", "D轮以上", "已上市", "不需融资"] - scale_enum = ["少于15人", "15-50人", "50-150人", "150-500人", "500-2000人", "2000人以上"] - %{ title: String.slice(body, 1, 49), company: Faker.Company.name(), - company_logo: Faker.Avatar.image_url(), body: body, desc: "活少, 美女多", digest: String.slice(body, 1, 150), length: String.length(body), author: mock(:author), views: Enum.random(0..2000), - salary: salary_enum |> Enum.at(Enum.random(0..(length(salary_enum) - 1))), - exp: exp_enum |> Enum.at(Enum.random(0..(length(exp_enum) - 1))), - education: education_enum |> Enum.at(Enum.random(0..(length(education_enum) - 1))), - field: field_enum |> Enum.at(Enum.random(0..(length(field_enum) - 1))), - finance: finance_enum |> Enum.at(Enum.random(0..(length(finance_enum) - 1))), - scale: scale_enum |> Enum.at(Enum.random(0..(length(scale_enum) - 1))), original_community: mock(:community), communities: [ mock(:community)