Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ launch.prod:

migrate:
mix ecto.migrate
migrate.mock:
MIX_ENV=mock mix ecto.migrate
rollback:
mix ecto.rollback
migrate.mock:
Expand All @@ -63,6 +65,8 @@ gen:
@echo "\n"
gen.migration:
mix ecto.gen.migration $(arg)
gen.migration.mock:
MIX_ENV=mock mix ecto.gen.migration $(arg)
gen.context:
mix phx.gen.context $(arg)

Expand Down Expand Up @@ -117,6 +121,8 @@ test.watch:
mix test.watch
test.watch.wip:
mix test.watch --only wip
test.watch.wip2:
mix test.watch --only wip2
test.db_reset:
env MIX_ENV=test mix ecto.drop
env MIX_ENV=test mix ecto.create
Expand Down
28 changes: 19 additions & 9 deletions lib/mastani_server/accounts/delegates/profile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,28 @@ defmodule MastaniServer.Accounts.Delegate.Profile do
end
end

defp create_user(user, :github) do
user = %User{
nickname: user["login"],
avatar: user["avatar_url"],
bio: user["bio"],
location: user["location"],
email: user["email"],
company: user["company"],
defp create_user(profile, :github) do
attrs = %{
nickname: profile["login"],
avatar: profile["avatar_url"],
bio: profile["bio"],
location: profile["location"],
email: profile["email"],
from_github: true
}

Repo.insert(user)
changeset =
case profile |> Map.has_key?("company") do
true ->
%User{}
|> Ecto.Changeset.change(attrs)
|> Ecto.Changeset.put_embed(:work_backgrounds, [%{company: profile["company"]}])

false ->
%User{} |> Ecto.Changeset.change(attrs)
end

Repo.insert(changeset)
end

defp create_profile(user, github_profile, :github) do
Expand Down
7 changes: 1 addition & 6 deletions lib/mastani_server/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule MastaniServer.Accounts.User do
alias MastaniServer.CMS

@required_fields ~w(nickname avatar)a
@optional_fields ~w(nickname bio sex location email company education qq weichat weibo)a
@optional_fields ~w(nickname bio sex location email qq weichat weibo)a

@type t :: %User{}
schema "users" do
Expand All @@ -32,9 +32,6 @@ defmodule MastaniServer.Accounts.User do
field(:email, :string)
field(:location, :string)

field(:education, :string)
field(:company, :string)

# TODO
# field(:twitter, :string)
# field(:facebook, :string)
Expand Down Expand Up @@ -72,7 +69,6 @@ defmodule MastaniServer.Accounts.User do
@doc false
def changeset(%User{} = user, attrs) do
user
|> cast(attrs, @optional_fields ++ @required_fields)
|> update_changeset(attrs)
|> validate_required(@required_fields)

Expand All @@ -89,7 +85,6 @@ defmodule MastaniServer.Accounts.User do
|> validate_inclusion(:sex, ["dude", "girl"])
|> validate_format(:email, ~r/@/)
|> validate_length(:location, min: 2, max: 30)
|> validate_length(:company, min: 3, max: 30)
|> validate_length(:qq, min: 8, max: 15)
|> validate_length(:weichat, min: 3, max: 30)
|> validate_length(:weibo, min: 3, max: 30)
Expand Down
2 changes: 0 additions & 2 deletions lib/mastani_server_web/schema/account/account_misc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ defmodule MastaniServerWeb.Schema.Account.Misc do
field(:nickname, :string)
field(:bio, :string)
field(:sex, :string)
field(:education, :string)
field(:location, :string)
field(:company, :string)
field(:email, :string)
field(:qq, :string)
field(:weibo, :string)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule MastaniServer.Repo.Migrations.RemoveEducationCompanyInUsers do
use Ecto.Migration

def change do
alter table(:users) do
remove(:company)
remove(:education)
end
end
end
10 changes: 5 additions & 5 deletions test/mastani_server/accounts/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ defmodule MastaniServer.Test.Accounts do
assert updated.sex == attrs.sex
end

@tag :wip
test "update user education backgorunds with valid attrs" do
{:ok, user} = db_insert(:user)

Expand All @@ -57,7 +56,6 @@ defmodule MastaniServer.Test.Accounts do
assert updated.education_backgrounds |> Enum.any?(&(&1.major == "bad ass"))
end

@tag :wip
test "update user work backgorunds with valid attrs" do
{:ok, user} = db_insert(:user)

Expand All @@ -79,7 +77,6 @@ defmodule MastaniServer.Test.Accounts do
assert updated.work_backgrounds |> Enum.any?(&(&1.title == "bad ass"))
end

@tag :wip
test "update user with invalid attrs fails ?" do
{:ok, user} = db_insert(:user)

Expand All @@ -90,7 +87,7 @@ defmodule MastaniServer.Test.Accounts do
end

describe "[github login]" do
alias Accounts.{User, GithubUser}
alias Accounts.{GithubUser, User}

test "register a valid github user with non-exist in db" do
assert {:error, _} =
Expand All @@ -109,7 +106,10 @@ defmodule MastaniServer.Test.Accounts do
assert created_user.bio == @valid_github_profile["bio"]

assert created_user.email == @valid_github_profile["email"]
assert created_user.company == @valid_github_profile["company"]

company_title = created_user.work_backgrounds |> List.first() |> Map.get(:company)
assert company_title == @valid_github_profile["company"]

assert created_user.location == @valid_github_profile["location"]
assert created_user.from_github == true

Expand Down
4 changes: 0 additions & 4 deletions test/mastani_server_web/mutation/accounts/account_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ defmodule MastaniServer.Test.Mutation.Account.Basic do
assert updated["nickname"] == "new nickname"
end

@tag :wip
test "user can update it's own education_backgrounds", ~m(user)a do
ownd_conn = simu_conn(:user, user)

Expand Down Expand Up @@ -75,7 +74,6 @@ defmodule MastaniServer.Test.Mutation.Account.Basic do
assert updated["education_backgrounds"] |> Enum.any?(&(&1["major"] == "bad ass"))
end

@tag :wip
test "user update education_backgrounds with invalid data fails", ~m(user)a do
ownd_conn = simu_conn(:user, user)

Expand All @@ -97,7 +95,6 @@ defmodule MastaniServer.Test.Mutation.Account.Basic do
assert ownd_conn |> mutation_get_error?(@update_query, variables)
end

@tag :wip
test "user can update it's own work backgrounds", ~m(user)a do
ownd_conn = simu_conn(:user, user)

Expand Down Expand Up @@ -128,7 +125,6 @@ defmodule MastaniServer.Test.Mutation.Account.Basic do
assert updated["work_backgrounds"] |> Enum.any?(&(&1["title"] == "bad ass"))
end

@tag :wip
test "user update work backgrounds with invalid data fails", ~m(user)a do
ownd_conn = simu_conn(:user, user)

Expand Down
1 change: 0 additions & 1 deletion test/mastani_server_web/query/accounts/account_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ defmodule MastaniServer.Test.Query.Account.Basic do
}
}
"""
@tag :wip
test "guest user can get specific user's info by user's id", ~m(guest_conn user)a do
variables = %{id: user.id}
results = guest_conn |> query_result(@query, variables, "user")
Expand Down