Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 165a6ba

Browse files
committed
fix(test error): cause by geo remote_ip
1 parent 2b0295a commit 165a6ba

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

lib/helper/radar_search.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule Helper.RadarSearch do
2424
end
2525

2626
def locate_city(:localhost) do
27-
{:error, "localhost"}
27+
{:ok, "成都"}
2828
end
2929

3030
# http://ip.yqie.com/search.aspx?searchword=%E6%88%90%E9%83%BD%E5%B8%82

lib/mastani_server/cms/delegates/community_curd.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ defmodule MastaniServer.CMS.Delegate.CommunityCURD do
5252
@doc """
5353
create a Tag base on type: post / tuts / videos ...
5454
"""
55+
# TODO: change to create_tag(community, thread, attrs, ....)
5556
def create_tag(thread, attrs, %Accounts.User{id: user_id}) do
5657
with {:ok, action} <- match_action(thread, :tag),
5758
{:ok, author} <- ensure_author_exists(%Accounts.User{id: user_id}),

lib/mastani_server/cms/delegates/community_operation.ex

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,8 @@ defmodule MastaniServer.CMS.Delegate.CommunityOperation do
102102
def subscribe_community(
103103
%Community{id: community_id},
104104
%User{id: user_id},
105-
remote_ip \\ {127, 0, 0, 1}
105+
remote_ip \\ :localhost
106106
) do
107-
remote_ip = Enum.join(Tuple.to_list(remote_ip), ".")
108-
109107
with {:ok, record} <- CommunitySubscriber |> ORM.create(~m(user_id community_id)a) do
110108
update_geo_info(community_id, user_id, remote_ip, :inc)
111109
Community |> ORM.find(record.community_id)
@@ -115,10 +113,8 @@ defmodule MastaniServer.CMS.Delegate.CommunityOperation do
115113
def unsubscribe_community(
116114
%Community{id: community_id},
117115
%User{id: user_id},
118-
remote_ip \\ {127, 0, 0, 1}
116+
remote_ip \\ :localhost
119117
) do
120-
remote_ip = Enum.join(Tuple.to_list(remote_ip), ".")
121-
122118
with {:ok, record} <-
123119
CommunitySubscriber |> ORM.findby_delete(community_id: community_id, user_id: user_id) do
124120
update_geo_info(community_id, user_id, remote_ip, :dec)

lib/mastani_server_web/resolvers/cms_resolver.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defmodule MastaniServerWeb.Resolvers.CMS do
3737
end
3838

3939
def post(_root, %{id: id}, _info),
40-
do: Post |> ORM.read(id, inc: :views) |> IO.inspect(label: "read done")
40+
do: Post |> ORM.read(id, inc: :views)
4141

4242
def job(_root, %{id: id}, %{context: %{cur_user: user}}) do
4343
CMS.read_content(:job, id, user)
@@ -267,6 +267,10 @@ defmodule MastaniServerWeb.Resolvers.CMS do
267267
CMS.subscribe_community(%Community{id: community_id}, cur_user, remote_ip)
268268
end
269269

270+
def subscribe_community(_root, ~m(community_id)a, %{context: %{cur_user: cur_user}}) do
271+
CMS.subscribe_community(%Community{id: community_id}, cur_user)
272+
end
273+
270274
def unsubscribe_community(_root, ~m(community_id)a, %{context: %{cur_user: cur_user}}) do
271275
CMS.unsubscribe_community(%Community{id: community_id}, cur_user)
272276
end

test/mastani_server/accounts/accounts_test.exs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,11 @@ defmodule MastaniServer.Test.Accounts do
149149
assert ORM.count(GithubUser) == 1
150150
end
151151

152-
test "github signin user should be locate geo city info" do
152+
test "github signin user should not locate geo city info" do
153153
{:ok, guser} = Accounts.github_signin(@valid_github_profile)
154154
{:ok, user} = ORM.find(User, guser.user.id)
155155

156-
assert user.geo_city !== nil
157-
end
158-
159-
test "github signin user from invalid ip locate geo city fails" do
160-
{:ok, guser} = Accounts.github_signin(@valid_github_profile, :fake_ip)
161-
{:ok, user} = ORM.find(User, guser.user.id)
162-
163-
assert user.geo_city == nil
156+
assert user.geo_city === nil
164157
end
165158
end
166159
end

0 commit comments

Comments
 (0)