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.

Commitbb6fd46

Browse files
authored
refactor(tags): add extra when create/update tags (#426)
1 parent6a9e464 commitbb6fd46

File tree

10 files changed

+53
-13
lines changed

10 files changed

+53
-13
lines changed

‎lib/groupher_server/cms/models/article_tag.ex‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ defmodule GroupherServer.CMS.Model.ArticleTag do
1111
aliasCMS.Model.{Author,Community}
1212

1313
@required_fields~w(thread title color author_id community_id)a
14-
@updatable_fields~w(thread title color community_id group)a
14+
@updatable_fields~w(thread title color community_id group extra)a
1515

1616
@typet::%ArticleTag{}
1717
schema"article_tags"do
1818
field(:title,:string)
1919
field(:color,:string)
2020
field(:thread,:string)
2121
field(:group,:string)
22+
field(:extra,{:array,:string})
2223

2324
belongs_to(:community,Community)
2425
belongs_to(:author,Author)

‎lib/groupher_server_web/schema/cms/cms_types.ex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
279279
field(:color,:string)
280280
field(:thread,:string)
281281
field(:group,:string)
282+
field(:extra,list_of(:string))
282283

283284
field(:author,:user,resolve:dataloader(CMS,:author))
284285
field(:community,:community,resolve:dataloader(CMS,:community))

‎lib/groupher_server_web/schema/cms/mutations/community.ex‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Community do
133133
arg(:community_id,non_null(:id))
134134
arg(:group,:string)
135135
arg(:thread,:thread,default_value::post)
136+
arg(:extra,list_of(:string))
136137

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

153155
middleware(M.Authorize,:login)
154156
middleware(M.PassportLoader,source::community)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmoduleGroupherServer.Repo.Migrations.AddExtraToTagsdo
2+
useEcto.Migration
3+
4+
defchangedo
5+
altertable(:article_tags)do
6+
add(:extra,{:array,:string})
7+
end
8+
end
9+
end

‎test/groupher_server/cms/article_tags/post_tag_test.exs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ defmodule GroupherServer.Test.CMS.ArticleTag.PostTag do
2424
assertarticle_tag.group==article_tag_attrs.group
2525
end
2626

27+
test"create article tag with extra data",~m(community article_tag_attrs user)ado
28+
tag_attrs=Map.merge(article_tag_attrs,%{extra:["menuID","menuID2"]})
29+
{:ok,article_tag}=CMS.create_article_tag(community,:post,tag_attrs,user)
30+
31+
assertarticle_tag.extra==["menuID","menuID2"]
32+
end
33+
2734
test"can update an article tag",~m(community article_tag_attrs user)ado
2835
{:ok,article_tag}=CMS.create_article_tag(community,:post,article_tag_attrs,user)
2936

‎test/groupher_server/cms/comments/archive_test.exs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ defmodule GroupherServer.Test.CMS.Comments.Archive do
2727
end
2828

2929
describe"[cms comment archive]"do
30-
@tag:wip
3130
test"can archive comments",~m(comment_long_ago)ado
3231
{:ok,_}=CMS.archive_articles(:comment)
3332

@@ -41,7 +40,6 @@ defmodule GroupherServer.Test.CMS.Comments.Archive do
4140
assertarchived_comment.id==comment_long_ago.id
4241
end
4342

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

@@ -55,7 +53,6 @@ defmodule GroupherServer.Test.CMS.Comments.Archive do
5553
assertreason|>is_error?(:archived)
5654
end
5755

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

‎test/groupher_server_web/mutation/cms/article_tags/curd_test.exs‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do
2323

2424
describe"[mutation cms tag]"do
2525
@create_tag_query"""
26-
mutation($thread: Thread!, $title: String!, $color: RainbowColor!, $group: String, $communityId: ID!) {
27-
createArticleTag(thread: $thread, title: $title, color: $color, group: $group, communityId: $communityId) {
26+
mutation($thread: Thread!, $title: String!, $color: RainbowColor!, $group: String, $communityId: ID!, $extra: [String]) {
27+
createArticleTag(thread: $thread, title: $title, color: $color, group: $group, communityId: $communityId, extra: $extra) {
2828
id
2929
title
3030
color
3131
thread
3232
group
33+
extra
3334
community {
3435
id
3536
logo
@@ -38,7 +39,6 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do
3839
}
3940
}
4041
"""
41-
4242
test"create tag with valid attrs, has default POST thread and default posts",
4343
~m(community)ado
4444
variables=%{
@@ -64,6 +64,24 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do
6464
assertbelong_community["id"]==to_string(community.id)
6565
end
6666

67+
test"create tag with extra",~m(community)ado
68+
variables=%{
69+
title:"tag title",
70+
communityId:community.id,
71+
thread:"POST",
72+
color:"GREEN",
73+
group:"awesome",
74+
extra:["menuID","menuID2"]
75+
}
76+
77+
passport_rules=%{community.title=>%{"post.article_tag.create"=>true}}
78+
rule_conn=simu_conn(:user,cms:passport_rules)
79+
80+
created=rule_conn|>mutation_result(@create_tag_query,variables,"createArticleTag")
81+
82+
assertcreated["extra"]==["menuID","menuID2"]
83+
end
84+
6785
test"unauth user create tag fails",~m(community user_conn guest_conn)ado
6886
variables=%{
6987
title:"tag title",
@@ -83,23 +101,25 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do
83101
end
84102

85103
@update_tag_query"""
86-
mutation($id: ID!, $color: RainbowColor, $title: String, $communityId: ID!) {
87-
updateArticleTag(id: $id, color: $color, title: $title, communityId: $communityId) {
104+
mutation($id: ID!, $color: RainbowColor, $title: String, $communityId: ID!, $extra: [String]) {
105+
updateArticleTag(id: $id, color: $color, title: $title, communityId: $communityId, extra: $extra) {
88106
id
89107
title
90108
color
109+
extra
91110
}
92111
}
93112
"""
94-
113+
@tag:wip
95114
test"auth user can update a tag",~m(article_tag_attrs community user)ado
96115
{:ok,article_tag}=CMS.create_article_tag(community,:post,article_tag_attrs,user)
97116

98117
variables=%{
99118
id:article_tag.id,
100119
color:"YELLOW",
101120
title:"new title",
102-
communityId:community.id
121+
communityId:community.id,
122+
extra:["newMenuID"]
103123
}
104124

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

110130
assertupdated["color"]=="YELLOW"
111131
assertupdated["title"]=="new title"
132+
assertupdated["extra"]==["newMenuID"]
112133
end
113134

114135
@delete_tag_query"""

‎test/groupher_server_web/query/cms/article_tags_test.exs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ defmodule GroupherServer.Test.Query.CMS.ArticleTags do
2525
title
2626
color
2727
thread
28+
extra
2829
community {
2930
id
3031
title

‎test/groupher_server_web/query/cms/comments/post_comment_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
3030
}
3131
}
3232
"""
33-
@tag:wip
33+
3434
test"guest user can get basic archive info",~m(guest_conn post user)ado
3535
thread=:post
3636

‎test/support/factory.ex‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ defmodule GroupherServer.Support.Factory do
386386
group:"cool",
387387
# community: Faker.Pizza.topping(),
388388
community:mock(:community),
389-
author:mock(:author)
389+
author:mock(:author),
390+
extra:[]
390391
# user_id: 1
391392
}
392393
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp