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.

Commit78729d6

Browse files
committed
refactor(article-tags): add article_tag & community filter test
1 parent6af8b93 commit78729d6

File tree

7 files changed

+117
-9
lines changed

7 files changed

+117
-9
lines changed

‎lib/helper/query_builder.ex‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ defmodule Helper.QueryBuilder do
174174
{_,:all},queryable->
175175
queryable
176176

177-
# TODO: use raw instead title
178177
{:article_tag,tag_name},queryable->
179178
from(
180179
qinqueryable,
@@ -189,17 +188,17 @@ defmodule Helper.QueryBuilder do
189188
where:t.raw==^catetory_raw
190189
)
191190

191+
{:thread,thread},queryable->
192+
thread=thread|>to_string|>String.upcase()
193+
from(qinqueryable,where:q.thread==^thread)
194+
192195
{:community_id,community_id},queryable->
193196
from(
194197
qinqueryable,
195198
join:tinassoc(q,:community),
196199
where:t.id==^community_id
197200
)
198201

199-
{:thread,thread},queryable->
200-
thread=thread|>to_string|>String.upcase()
201-
from(qinqueryable,where:q.thread==^thread)
202-
203202
{:community,community_raw},queryable->
204203
from(
205204
qinqueryable,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ defmodule GroupherServer.Test.CMS.ArticleTag.PostTag do
1818
end
1919

2020
describe"[post tag CURD]"do
21-
@tag:wip2
2221
test"create article tag with valid data",~m(community article_tag_attrs user)ado
2322
{:ok,article_tag}=CMS.create_article_tag(community,:post,article_tag_attrs,user)
2423
assertarticle_tag.title==article_tag_attrs.title

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.CMS.ArticleArticleTags.CURD do
3838
}
3939
}
4040
"""
41-
@tag:wip2
41+
4242
test"create tag with valid attrs, has default POST thread and default posts",
4343
~m(community)ado
4444
variables=%{

‎test/groupher_server_web/query/accounts/colleced_articles_test.exs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ defmodule GroupherServer.Test.Query.Accounts.CollectedArticles do
4949
assertresults2|>is_valid_pagination?()
5050
end
5151

52-
@tag:wip2
5352
test"other user can get other user's paged collect folders filter by thread",
5453
~m(guest_conn)ado
5554
{:ok,user}=db_insert(:user)

‎test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do
4444
pagedJobs(filter: $filter) {
4545
entries {
4646
id
47+
communities {
48+
id
49+
raw
50+
}
4751
articleTags {
4852
id
4953
}
@@ -65,6 +69,41 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do
6569
assertresults["entries"]|>List.first()|>Map.get("articleTags")|>is_list
6670
end
6771

72+
@tag:wip2
73+
test"support article_tag filter",~m(guest_conn user)ado
74+
{:ok,community}=db_insert(:community)
75+
job_attrs=mock_attrs(:job,%{community_id:community.id})
76+
{:ok,job}=CMS.create_article(community,:job,job_attrs,user)
77+
78+
article_tag_attrs=mock_attrs(:article_tag)
79+
{:ok,article_tag}=CMS.create_article_tag(community,:job,article_tag_attrs,user)
80+
{:ok,_}=CMS.set_article_tag(:job,job.id,article_tag.id)
81+
82+
variables=%{filter:%{page:1,size:10,article_tag:article_tag.title}}
83+
results=guest_conn|>query_result(@query,variables,"pagedJobs")
84+
85+
job=results["entries"]|>List.first()
86+
assertresults["totalCount"]==1
87+
assertexist_in?(article_tag,job["articleTags"],:string_key)
88+
end
89+
90+
@tag:wip2
91+
test"support community filter",~m(guest_conn user)ado
92+
{:ok,community}=db_insert(:community)
93+
94+
job_attrs=mock_attrs(:job,%{community_id:community.id})
95+
{:ok,_job}=CMS.create_article(community,:job,job_attrs,user)
96+
job_attrs2=mock_attrs(:job,%{community_id:community.id})
97+
{:ok,_job}=CMS.create_article(community,:job,job_attrs2,user)
98+
99+
variables=%{filter:%{page:1,size:10,community:community.raw}}
100+
results=guest_conn|>query_result(@query,variables,"pagedJobs")
101+
102+
job=results["entries"]|>List.first()
103+
assertresults["totalCount"]==2
104+
assertexist_in?(%{id:to_string(community.id)},job["communities"],:string_key)
105+
end
106+
68107
test"request large size fails",~m(guest_conn)ado
69108
variables=%{filter:%{page:1,size:200}}
70109
assertguest_conn|>query_get_error?(@query,variables,ecode(:pagination))

‎test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do
4646
entries {
4747
id
4848
communities {
49+
id
4950
raw
5051
}
5152
articleTags {
@@ -59,7 +60,6 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do
5960
}
6061
}
6162
"""
62-
6363
test"should get pagination info",~m(guest_conn)ado
6464
variables=%{filter:%{page:1,size:10}}
6565
results=guest_conn|>query_result(@query,variables,"pagedPosts")
@@ -70,6 +70,39 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do
7070
assertresults["entries"]|>List.first()|>Map.get("articleTags")|>is_list
7171
end
7272

73+
test"support article_tag filter",~m(guest_conn user)ado
74+
{:ok,community}=db_insert(:community)
75+
post_attrs=mock_attrs(:post,%{community_id:community.id})
76+
{:ok,post}=CMS.create_article(community,:post,post_attrs,user)
77+
78+
article_tag_attrs=mock_attrs(:article_tag)
79+
{:ok,article_tag}=CMS.create_article_tag(community,:post,article_tag_attrs,user)
80+
{:ok,_}=CMS.set_article_tag(:post,post.id,article_tag.id)
81+
82+
variables=%{filter:%{page:1,size:10,article_tag:article_tag.title}}
83+
results=guest_conn|>query_result(@query,variables,"pagedPosts")
84+
85+
post=results["entries"]|>List.first()
86+
assertresults["totalCount"]==1
87+
assertexist_in?(article_tag,post["articleTags"],:string_key)
88+
end
89+
90+
test"support community filter",~m(guest_conn user)ado
91+
{:ok,community}=db_insert(:community)
92+
93+
post_attrs=mock_attrs(:post,%{community_id:community.id})
94+
{:ok,_post}=CMS.create_article(community,:post,post_attrs,user)
95+
post_attrs2=mock_attrs(:post,%{community_id:community.id})
96+
{:ok,_post}=CMS.create_article(community,:post,post_attrs2,user)
97+
98+
variables=%{filter:%{page:1,size:10,community:community.raw}}
99+
results=guest_conn|>query_result(@query,variables,"pagedPosts")
100+
101+
post=results["entries"]|>List.first()
102+
assertresults["totalCount"]==2
103+
assertexist_in?(%{id:to_string(community.id)},post["communities"],:string_key)
104+
end
105+
73106
test"request large size fails",~m(guest_conn)ado
74107
variables=%{filter:%{page:1,size:200}}
75108
assertguest_conn|>query_get_error?(@query,variables,ecode(:pagination))

‎test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedRepos do
4040
pagedRepos(filter: $filter) {
4141
entries {
4242
id
43+
communities {
44+
id
45+
raw
46+
}
4347
articleTags {
4448
id
4549
}
@@ -62,6 +66,41 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedRepos do
6266
assertresults["entries"]|>List.first()|>Map.get("articleTags")|>is_list
6367
end
6468

69+
@tag:wip2
70+
test"support article_tag filter",~m(guest_conn user)ado
71+
{:ok,community}=db_insert(:community)
72+
repo_attrs=mock_attrs(:repo,%{community_id:community.id})
73+
{:ok,repo}=CMS.create_article(community,:repo,repo_attrs,user)
74+
75+
article_tag_attrs=mock_attrs(:article_tag)
76+
{:ok,article_tag}=CMS.create_article_tag(community,:repo,article_tag_attrs,user)
77+
{:ok,_}=CMS.set_article_tag(:repo,repo.id,article_tag.id)
78+
79+
variables=%{filter:%{page:1,size:10,article_tag:article_tag.title}}
80+
results=guest_conn|>query_result(@query,variables,"pagedRepos")
81+
82+
repo=results["entries"]|>List.first()
83+
assertresults["totalCount"]==1
84+
assertexist_in?(article_tag,repo["articleTags"],:string_key)
85+
end
86+
87+
@tag:wip2
88+
test"support community filter",~m(guest_conn user)ado
89+
{:ok,community}=db_insert(:community)
90+
91+
repo_attrs=mock_attrs(:repo,%{community_id:community.id})
92+
{:ok,_repo}=CMS.create_article(community,:repo,repo_attrs,user)
93+
repo_attrs2=mock_attrs(:repo,%{community_id:community.id})
94+
{:ok,_repo}=CMS.create_article(community,:repo,repo_attrs2,user)
95+
96+
variables=%{filter:%{page:1,size:10,community:community.raw}}
97+
results=guest_conn|>query_result(@query,variables,"pagedRepos")
98+
99+
repo=results["entries"]|>List.first()
100+
assertresults["totalCount"]==2
101+
assertexist_in?(%{id:to_string(community.id)},repo["communities"],:string_key)
102+
end
103+
65104
test"request large size fails",~m(guest_conn)ado
66105
variables=%{filter:%{page:1,size:200}}
67106
assertguest_conn|>query_get_error?(@query,variables,ecode(:pagination))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp