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.

Commitf13d7b7

Browse files
committed
use ShortMaps to refactor %{..}
1 parent5fb168a commitf13d7b7

File tree

3 files changed

+51
-53
lines changed

3 files changed

+51
-53
lines changed

‎mix.exs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ defmodule MastaniServer.Mixfile do
6363
{:ex_unit_notifier,"~> 0.1",only::test},
6464
{:apollo_tracing,"~> 0.4.1"},
6565
{:pre_commit,"~> 0.2.4"},
66-
{:inch_ex,"~> 0.5",only:[:dev,:test]}
66+
{:inch_ex,"~> 0.5",only:[:dev,:test]},
67+
{:short_maps,"~> 0.1.1"}
6768
]
6869
end
6970

‎mix.lock‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"ranch":{:hex,:ranch,"1.3.2","e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986",[:rebar3],[],"hexpm"},
4444
"scrivener":{:hex,:scrivener,"2.4.0","c9431804b13ac6a5c4b01eb32188c1ff926898a2d684244d021706841f022e66",[:mix],[],"hexpm"},
4545
"scrivener_ecto":{:hex,:scrivener_ecto,"1.3.0","69698428e22810ac8a47abc12d1df5b2f5d8f6b36dc5d5bfe6dd93fde857c576",[:mix],[{:ecto,"~> 2.0",[hex::ecto,repo:"hexpm",optional:false]},{:postgrex,"~> 0.11.0 or ~> 0.12.0 or ~> 0.13.0",[hex::postgrex,repo:"hexpm",optional:true]},{:scrivener,"~> 2.4",[hex::scrivener,repo:"hexpm",optional:false]}],"hexpm"},
46+
"short_maps":{:hex,:short_maps,"0.1.2","a7c2bfd91179cdbdfe90e74a023992335d116982fa672612c74776b2e9257a7b",[:mix],[],"hexpm"},
4647
"ssl_verify_fun":{:hex,:ssl_verify_fun,"1.1.1","28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe",[:make,:rebar],[],"hexpm"},
4748
"tesla":{:hex,:tesla,"0.10.0","e588c7e7f1c0866c81eeed5c38f02a4a94d6309eede336c1e6ca08b0a95abd3f",[:mix],[{:exjsx,">= 0.1.0",[hex::exjsx,repo:"hexpm",optional:true]},{:fuse,"~> 2.4",[hex::fuse,repo:"hexpm",optional:true]},{:hackney,"~> 1.6",[hex::hackney,repo:"hexpm",optional:true]},{:ibrowse,"~> 4.2",[hex::ibrowse,repo:"hexpm",optional:true]},{:mime,"~> 1.0",[hex::mime,repo:"hexpm",optional:false]},{:poison,">= 1.0.0",[hex::poison,repo:"hexpm",optional:true]}],"hexpm"},
4849
"timex":{:hex,:timex,"3.2.1","639975eac45c4c08c2dbf7fc53033c313ff1f94fad9282af03619a3826493612",[:mix],[{:combine,"~> 0.10",[hex::combine,repo:"hexpm",optional:false]},{:gettext,"~> 0.10",[hex::gettext,repo:"hexpm",optional:false]},{:tzdata,"~> 0.1.8 or ~> 0.5",[hex::tzdata,repo:"hexpm",optional:false]}],"hexpm"},

‎test/mastani_server_web/mutaion/post_test.exs‎

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ defmodule MastaniServer.Test.Mutation.PostTest do
44
importMastaniServer.Factory
55
importMastaniServer.Test.ConnBuilder
66
importMastaniServer.Test.AssertHelper
7+
importShortMaps
78

89
aliasMastaniServer.Repo
9-
aliasMastaniServer.Accounts.User
10+
#alias MastaniServer.Accounts.User
1011
aliasMastaniServer.CMS
1112
aliasHelper.ORM
1213

@@ -29,9 +30,10 @@ defmodule MastaniServer.Test.Mutation.PostTest do
2930
}
3031
}
3132
"""
32-
test"create comment to a exsit post",%{post:post,user_conn:conn}do
33+
# test "create comment to a exsit post", %{post: post, user_conn: user_conn} do
34+
test"create comment to a exsit post",~m(post user_conn)ado
3335
variables=%{type:"POST",id:post.id,body:"a test comment"}
34-
created=conn|>mutation_result(@create_comment_query,variables,"createComment")
36+
created=user_conn|>mutation_result(@create_comment_query,variables,"createComment")
3537

3638
assertcreated["body"]==variables.body
3739
end
@@ -43,15 +45,15 @@ defmodule MastaniServer.Test.Mutation.PostTest do
4345
}
4446
}
4547
"""
46-
test"delete a comment",%{post:post,user_conn:conn}do
48+
test"delete a comment",~m(postuser_conn)ado
4749
variables1=%{type:"POST",id:post.id,body:"a test comment"}
48-
created=conn|>mutation_result(@create_comment_query,variables1,"createComment")
50+
created=user_conn|>mutation_result(@create_comment_query,variables1,"createComment")
4951
assertcreated["body"]==variables1.body
5052

5153
variables2=%{id:created["id"]}
5254

5355
deleted_comment=
54-
conn|>mutation_result(@delete_comment_query,variables2,"deleteComment")
56+
user_conn|>mutation_result(@delete_comment_query,variables2,"deleteComment")
5557

5658
assertdeleted_comment["id"]==created["id"]
5759

@@ -69,12 +71,12 @@ defmodule MastaniServer.Test.Mutation.PostTest do
6971
}
7072
}
7173
"""
72-
test"create post with valid attrs",%{user_conn:conn}do
74+
test"create post with valid attrs",~m(user_conn)ado
7375
{:ok,community}=db_insert(:community)
7476
post_attr=mock_attrs(:post)
7577

7678
variables=post_attr|>Map.merge(%{community:community.title})
77-
created=conn|>mutation_result(@create_post_query,variables,"createPost")
79+
created=user_conn|>mutation_result(@create_post_query,variables,"createPost")
7880
post=Repo.get_by(CMS.Post,title:post_attr.title)
7981

8082
assertcreated["id"]==to_string(post.id)
@@ -87,31 +89,31 @@ defmodule MastaniServer.Test.Mutation.PostTest do
8789
}
8890
}
8991
"""
90-
test"delete a post by post's owner",%{owner_conn:conn,post:post}do
91-
deleted=conn|>mutation_result(@query,%{id:post.id},"deletePost")
92+
test"delete a post by post's owner",~m(owner_connpost)ado
93+
deleted=owner_conn|>mutation_result(@query,%{id:post.id},"deletePost")
9294

9395
assertdeleted["id"]==to_string(post.id)
9496
assertnil==Repo.get(CMS.Post,deleted["id"])
9597
end
9698

97-
test"delete a post without login user fails",%{guest_conn:conn,post:post}do
98-
assertconn|>mutation_get_error?(@query,%{id:post.id})
99+
test"delete a post without login user fails",~m(guest_connpost)ado
100+
assertguest_conn|>mutation_get_error?(@query,%{id:post.id})
99101
end
100102

101-
test"login user with auth passport delete a post",%{post:post}do
103+
test"login user with auth passport delete a post",~m(post)ado
102104
post_communities_0=post.communities|>List.first()|>Map.get(:title)
103105
passport_rules=%{"cms"=>%{post_communities_0=>%{"post.article.delete"=>true}}}
104-
conn=mock_conn(:user,passport_rules)
106+
rule_conn=mock_conn(:user,passport_rules)
105107

106108
# assert conn |> mutation_get_error?(@query, %{id: post.id})
107109

108-
deleted=conn|>mutation_result(@query,%{id:post.id},"deletePost")
110+
deleted=rule_conn|>mutation_result(@query,%{id:post.id},"deletePost")
109111

110112
assertdeleted["id"]==to_string(post.id)
111113
end
112114

113-
test"login user with wrong passport delete a post fails",%{user_conn:conn,post:post}do
114-
post_communities_0=post.communities|>List.first()|>Map.get(:title)
115+
test"login user with wrong passport delete a post fails",~m(post)ado
116+
#post_communities_0 = post.communities |> List.first() |> Map.get(:title)
115117
# IO.inspect(post_communities_0, label: "hello")
116118
# CMS.stamp_passport(%User{id: user.id}, community_rules)
117119

@@ -121,8 +123,8 @@ defmodule MastaniServer.Test.Mutation.PostTest do
121123
assertconn|>mutation_get_error?(@query,%{id:post.id})
122124
end
123125

124-
test"login user without passport delete a post fails",%{user_conn:conn,post:post}do
125-
assertconn|>mutation_get_error?(@query,%{id:post.id})
126+
test"login user without passport delete a post fails",~m(user_connpost)ado
127+
assertuser_conn|>mutation_get_error?(@query,%{id:post.id})
126128
end
127129

128130
@query"""
@@ -134,7 +136,7 @@ defmodule MastaniServer.Test.Mutation.PostTest do
134136
}
135137
}
136138
"""
137-
test"update a post without login user fails",%{guest_conn:conn,post:post}do
139+
test"update a post without login user fails",~m(guest_connpost)ado
138140
unique_num=System.unique_integer([:positive,:monotonic])
139141

140142
variables=%{
@@ -143,10 +145,10 @@ defmodule MastaniServer.Test.Mutation.PostTest do
143145
body:"updated body#{unique_num}"
144146
}
145147

146-
assertconn|>mutation_get_error?(@query,variables)
148+
assertguest_conn|>mutation_get_error?(@query,variables)
147149
end
148150

149-
test"update a post with by post's owner",%{owner_conn:conn,post:post}do
151+
test"update a post with by post's owner",~m(owner_connpost)ado
150152
unique_num=System.unique_integer([:positive,:monotonic])
151153

152154
variables=%{
@@ -155,16 +157,16 @@ defmodule MastaniServer.Test.Mutation.PostTest do
155157
body:"updated body#{unique_num}"
156158
}
157159

158-
updated_post=conn|>mutation_result(@query,variables,"updatePost")
160+
updated_post=owner_conn|>mutation_result(@query,variables,"updatePost")
159161

160162
assertupdated_post["title"]==variables.title
161163
assertupdated_post["body"]==variables.body
162164
end
163165

164-
test"login user with auth passport update a post",%{post:post}do
166+
test"login user with auth passport update a post",~m(post)ado
165167
post_communities_0=post.communities|>List.first()|>Map.get(:title)
166168
passport_rules=%{"cms"=>%{post_communities_0=>%{"post.article.edit"=>true}}}
167-
conn=mock_conn(:user,passport_rules)
169+
rule_conn=mock_conn(:user,passport_rules)
168170

169171
# assert conn |> mutation_get_error?(@query, %{id: post.id})
170172
unique_num=System.unique_integer([:positive,:monotonic])
@@ -175,12 +177,12 @@ defmodule MastaniServer.Test.Mutation.PostTest do
175177
body:"updated body#{unique_num}"
176178
}
177179

178-
updated_post=conn|>mutation_result(@query,variables,"updatePost")
180+
updated_post=rule_conn|>mutation_result(@query,variables,"updatePost")
179181

180182
assertupdated_post["id"]==to_string(post.id)
181183
end
182184

183-
test"login user without passport update post fails",%{user_conn:conn,post:post}do
185+
test"login user without passport update post fails",~m(user_connpost)ado
184186
unique_num=System.unique_integer([:positive,:monotonic])
185187

186188
variables=%{
@@ -189,7 +191,7 @@ defmodule MastaniServer.Test.Mutation.PostTest do
189191
body:"updated body#{unique_num}"
190192
}
191193

192-
assertconn|>mutation_get_error?(@query,variables)
194+
assertuser_conn|>mutation_get_error?(@query,variables)
193195
end
194196
end
195197

@@ -202,25 +204,25 @@ defmodule MastaniServer.Test.Mutation.PostTest do
202204
}
203205
}
204206
"""
205-
test"can set a tag to post",%{user_conn:conn,post:post}do
207+
test"can set a tag to post",~m(user_connpost)ado
206208
{:ok,tag}=db_insert(:tag)
207209
variables=%{id:post.id,tagId:tag.id}
208-
conn|>mutation_result(@set_tag_query,variables,"setTag")
210+
user_conn|>mutation_result(@set_tag_query,variables,"setTag")
209211
{:ok,found}=ORM.find(CMS.Post,post.id,preload::tags)
210212

211213
assoc_tags=found.tags|>Enum.map(&&1.id)
212214
asserttag.idinassoc_tags
213215
end
214216

215-
test"can set multi tag to a post",%{user_conn:conn,post:post}do
217+
test"can set multi tag to a post",~m(user_connpost)ado
216218
{:ok,tag}=db_insert(:tag)
217219
{:ok,tag2}=db_insert(:tag)
218220

219221
variables=%{id:post.id,tagId:tag.id}
220-
conn|>mutation_result(@set_tag_query,variables,"setTag")
222+
user_conn|>mutation_result(@set_tag_query,variables,"setTag")
221223

222224
variables2=%{id:post.id,tagId:tag2.id}
223-
conn|>mutation_result(@set_tag_query,variables2,"setTag")
225+
user_conn|>mutation_result(@set_tag_query,variables2,"setTag")
224226

225227
{:ok,found}=ORM.find(CMS.Post,post.id,preload::tags)
226228

@@ -237,23 +239,23 @@ defmodule MastaniServer.Test.Mutation.PostTest do
237239
}
238240
}
239241
"""
240-
test"can unset tag from a post",%{user_conn:conn,post:post}do
242+
test"can unset tag from a post",~m(user_connpost)ado
241243
{:ok,tag}=db_insert(:tag)
242244
{:ok,tag2}=db_insert(:tag)
243245

244246
variables=%{id:post.id,tagId:tag.id}
245-
conn|>mutation_result(@set_tag_query,variables,"setTag")
247+
user_conn|>mutation_result(@set_tag_query,variables,"setTag")
246248

247249
variables2=%{id:post.id,tagId:tag2.id}
248-
conn|>mutation_result(@set_tag_query,variables2,"setTag")
250+
user_conn|>mutation_result(@set_tag_query,variables2,"setTag")
249251

250252
{:ok,found}=ORM.find(CMS.Post,post.id,preload::tags)
251253

252254
assoc_tags=found.tags|>Enum.map(&&1.id)
253255
asserttag.idinassoc_tags
254256
asserttag2.idinassoc_tags
255257

256-
conn|>mutation_result(@unset_tag_query,variables,"unsetTag")
258+
user_conn|>mutation_result(@unset_tag_query,variables,"unsetTag")
257259
{:ok,found}=ORM.find(CMS.Post,post.id,preload::tags)
258260
assoc_tags=found.tags|>Enum.map(&&1.id)
259261

@@ -271,28 +273,25 @@ defmodule MastaniServer.Test.Mutation.PostTest do
271273
}
272274
}
273275
"""
274-
test"can set a community to post",%{user_conn:conn,post:post}do
276+
test"can set a community to post",~m(user_connpost)ado
275277
{:ok,community}=db_insert(:community)
276278
variables=%{id:post.id,communityId:community.id}
277-
conn|>mutation_result(@set_community_query,variables,"setCommunity")
279+
user_conn|>mutation_result(@set_community_query,variables,"setCommunity")
278280
{:ok,found}=ORM.find(CMS.Post,post.id,preload::communities)
279281

280282
assoc_communities=found.communities|>Enum.map(&&1.id)
281283
assertcommunity.idinassoc_communities
282284
end
283285

284-
test"can set multi community to a post",%{
285-
user_conn:conn,
286-
post:post
287-
}do
286+
test"can set multi community to a post",~m(user_conn post)ado
288287
{:ok,community}=db_insert(:community)
289288
{:ok,community2}=db_insert(:community)
290289

291290
variables=%{id:post.id,communityId:community.id}
292-
conn|>mutation_result(@set_community_query,variables,"setCommunity")
291+
user_conn|>mutation_result(@set_community_query,variables,"setCommunity")
293292

294293
variables2=%{id:post.id,communityId:community2.id}
295-
conn|>mutation_result(@set_community_query,variables2,"setCommunity")
294+
user_conn|>mutation_result(@set_community_query,variables2,"setCommunity")
296295

297296
{:ok,found}=ORM.find(CMS.Post,post.id,preload::communities)
298297

@@ -308,26 +307,23 @@ defmodule MastaniServer.Test.Mutation.PostTest do
308307
}
309308
}
310309
"""
311-
test"can unset community from a post",%{
312-
user_conn:conn,
313-
post:post
314-
}do
310+
test"can unset community from a post",~m(user_conn post)ado
315311
{:ok,community}=db_insert(:community)
316312
{:ok,community2}=db_insert(:community)
317313

318314
variables=%{id:post.id,communityId:community.id}
319-
conn|>mutation_result(@set_community_query,variables,"setCommunity")
315+
user_conn|>mutation_result(@set_community_query,variables,"setCommunity")
320316

321317
variables2=%{id:post.id,communityId:community2.id}
322-
conn|>mutation_result(@set_community_query,variables2,"setCommunity")
318+
user_conn|>mutation_result(@set_community_query,variables2,"setCommunity")
323319

324320
{:ok,found}=ORM.find(CMS.Post,post.id,preload::communities)
325321

326322
assoc_communities=found.communities|>Enum.map(&&1.id)
327323
assertcommunity.idinassoc_communities
328324
assertcommunity2.idinassoc_communities
329325

330-
conn|>mutation_result(@unset_community_query,variables,"unsetCommunity")
326+
user_conn|>mutation_result(@unset_community_query,variables,"unsetCommunity")
331327
{:ok,found}=ORM.find(CMS.Post,post.id,preload::communities)
332328
assoc_communities=found.communities|>Enum.map(&&1.id)
333329
assertcommunity.idnot inassoc_communities

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp