Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Provide feedback

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

Saved searches

Use saved searches to filter your results more quickly

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

refactor(tags): add extra when create/update tags#426

Merged
mydearxym merged 1 commit intodevfromtags-with-menu
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletionlib/groupher_server/cms/models/article_tag.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,14 +11,15 @@ defmodule GroupherServer.CMS.Model.ArticleTag do
alias CMS.Model.{Author, Community}

@required_fields ~w(thread title color author_id community_id)a
@updatable_fields ~w(thread title color community_id group)a
@updatable_fields ~w(thread title color community_id group extra)a

@type t :: %ArticleTag{}
schema "article_tags" do
field(:title, :string)
field(:color, :string)
field(:thread, :string)
field(:group, :string)
field(:extra, {:array, :string})

belongs_to(:community, Community)
belongs_to(:author, Author)
Expand Down
1 change: 1 addition & 0 deletionslib/groupher_server_web/schema/cms/cms_types.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -279,6 +279,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
field(:color, :string)
field(:thread, :string)
field(:group, :string)
field(:extra, list_of(:string))

field(:author, :user, resolve: dataloader(CMS, :author))
field(:community, :community, resolve: dataloader(CMS, :community))
Expand Down
2 changes: 2 additions & 0 deletionslib/groupher_server_web/schema/cms/mutations/community.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -133,6 +133,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Community do
arg(:community_id, non_null(:id))
arg(:group, :string)
arg(:thread, :thread, default_value: :post)
arg(:extra, list_of(:string))

middleware(M.Authorize, :login)
middleware(M.PassportLoader, source: :community)
Expand All@@ -149,6 +150,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Community do
arg(:color, :rainbow_color)
arg(:group, :string)
arg(:thread, :thread, default_value: :post)
arg(:extra, list_of(:string))

middleware(M.Authorize, :login)
middleware(M.PassportLoader, source: :community)
Expand Down
9 changes: 9 additions & 0 deletionspriv/repo/migrations/20210816040543_add_extra_to_tags.exs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
defmodule GroupherServer.Repo.Migrations.AddExtraToTags do
use Ecto.Migration

def change do
alter table(:article_tags) do
add(:extra, {:array, :string})
end
end
end
7 changes: 7 additions & 0 deletionstest/groupher_server/cms/article_tags/post_tag_test.exs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,13 @@ defmodule GroupherServer.Test.CMS.ArticleTag.PostTag do
assert article_tag.group == article_tag_attrs.group
end

test "create article tag with extra data", ~m(community article_tag_attrs user)a do
tag_attrs = Map.merge(article_tag_attrs, %{extra: ["menuID", "menuID2"]})
{:ok, article_tag} = CMS.create_article_tag(community, :post, tag_attrs, user)

assert article_tag.extra == ["menuID", "menuID2"]
end

test "can update an article tag", ~m(community article_tag_attrs user)a do
{:ok, article_tag} = CMS.create_article_tag(community, :post, article_tag_attrs, user)

Expand Down
3 changes: 0 additions & 3 deletionstest/groupher_server/cms/comments/archive_test.exs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,7 +27,6 @@ defmodule GroupherServer.Test.CMS.Comments.Archive do
end

describe "[cms comment archive]" do
@tag :wip
test "can archive comments", ~m(comment_long_ago)a do
{:ok, _} = CMS.archive_articles(:comment)

Expand All@@ -41,7 +40,6 @@ defmodule GroupherServer.Test.CMS.Comments.Archive do
assert archived_comment.id == comment_long_ago.id
end

@tag :wip
test "can not edit archived comment" do
{:ok, _} = CMS.archive_articles(:comment)

Expand All@@ -55,7 +53,6 @@ defmodule GroupherServer.Test.CMS.Comments.Archive do
assert reason |> is_error?(:archived)
end

@tag :wip
test "can not delete archived comment" do
{:ok, _} = CMS.archive_articles(:comment)

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,13 +23,14 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do

describe "[mutation cms tag]" do
@create_tag_query """
mutation($thread: Thread!, $title: String!, $color: RainbowColor!, $group: String, $communityId: ID!) {
createArticleTag(thread: $thread, title: $title, color: $color, group: $group, communityId: $communityId) {
mutation($thread: Thread!, $title: String!, $color: RainbowColor!, $group: String, $communityId: ID!, $extra: [String]) {
createArticleTag(thread: $thread, title: $title, color: $color, group: $group, communityId: $communityId, extra: $extra) {
id
title
color
thread
group
extra
community {
id
logo
Expand All@@ -38,7 +39,6 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do
}
}
"""

test "create tag with valid attrs, has default POST thread and default posts",
~m(community)a do
variables = %{
Expand All@@ -64,6 +64,24 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do
assert belong_community["id"] == to_string(community.id)
end

test "create tag with extra", ~m(community)a do
variables = %{
title: "tag title",
communityId: community.id,
thread: "POST",
color: "GREEN",
group: "awesome",
extra: ["menuID", "menuID2"]
}

passport_rules = %{community.title => %{"post.article_tag.create" => true}}
rule_conn = simu_conn(:user, cms: passport_rules)

created = rule_conn |> mutation_result(@create_tag_query, variables, "createArticleTag")

assert created["extra"] == ["menuID", "menuID2"]
end

test "unauth user create tag fails", ~m(community user_conn guest_conn)a do
variables = %{
title: "tag title",
Expand All@@ -83,23 +101,25 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do
end

@update_tag_query """
mutation($id: ID!, $color: RainbowColor, $title: String, $communityId: ID!) {
updateArticleTag(id: $id, color: $color, title: $title, communityId: $communityId) {
mutation($id: ID!, $color: RainbowColor, $title: String, $communityId: ID!, $extra: [String]) {
updateArticleTag(id: $id, color: $color, title: $title, communityId: $communityId, extra: $extra) {
id
title
color
extra
}
}
"""

@tag :wip
test "auth user can update a tag", ~m(article_tag_attrs community user)a do
{:ok, article_tag} = CMS.create_article_tag(community, :post, article_tag_attrs, user)

variables = %{
id: article_tag.id,
color: "YELLOW",
title: "new title",
communityId: community.id
communityId: community.id,
extra: ["newMenuID"]
}

passport_rules = %{community.title => %{"post.article_tag.update" => true}}
Expand All@@ -109,6 +129,7 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do

assert updated["color"] == "YELLOW"
assert updated["title"] == "new title"
assert updated["extra"] == ["newMenuID"]
end

@delete_tag_query """
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,7 @@ defmodule GroupherServer.Test.Query.CMS.ArticleTags do
title
color
thread
extra
community {
id
title
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
}
}
"""
@tag :wip

test "guest user can get basic archive info", ~m(guest_conn post user)a do
thread = :post

Expand Down
3 changes: 2 additions & 1 deletiontest/support/factory.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -386,7 +386,8 @@ defmodule GroupherServer.Support.Factory do
group: "cool",
# community: Faker.Pizza.topping(),
community: mock(:community),
author: mock(:author)
author: mock(:author),
extra: []
# user_id: 1
}
end
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp