Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: signup api requires password field
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Apr 20, 2022
1 parent 742be87 commit a793761
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
4 changes: 2 additions & 2 deletions internal/adapter/http/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func (c *UserController) Signup(ctx context.Context, input SignupInput) (SignupO
Theme: input.Theme,
},
})
} else if input.Name != nil && input.Email != nil && input.Password != nil {
} else if input.Name != nil && input.Email != nil {
u, _, err = c.usecase.Signup(ctx, interfaces.SignupParam{
Sub: input.Sub,
Name: *input.Name,
Email: *input.Email,
Password: *input.Password,
Password: input.Password,
Secret: input.Secret,
User: interfaces.SignupUserParam{
UserID: input.UserID,
Expand Down
5 changes: 1 addition & 4 deletions internal/usecase/interactor/user_signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import (
)

func (i *User) Signup(ctx context.Context, inp interfaces.SignupParam) (*user.User, *user.Team, error) {
if inp.Password == "" {
return nil, nil, interfaces.ErrSignupInvalidPassword
}
if inp.Name == "" {
return nil, nil, interfaces.ErrSignupInvalidName
}
Expand Down Expand Up @@ -66,7 +63,7 @@ func (i *User) Signup(ctx context.Context, inp interfaces.SignupParam) (*user.Us
Email: inp.Email,
Name: inp.Name,
Sub: auth,
Password: &inp.Password,
Password: inp.Password,
Lang: inp.User.Lang,
Theme: inp.User.Theme,
UserID: inp.User.UserID,
Expand Down
47 changes: 22 additions & 25 deletions internal/usecase/interactor/user_signup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/reearth/reearth-backend/internal/usecase/interfaces"
"github.com/reearth/reearth-backend/pkg/id"
"github.com/reearth/reearth-backend/pkg/user"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
)
Expand Down Expand Up @@ -47,10 +48,10 @@ func TestUser_Signup(t *testing.T) {
signupSecret: "",
authSrvUIDomain: "https://reearth.io",
args: interfaces.SignupParam{
Sub: sr("SUB"),
Sub: lo.ToPtr("SUB"),
Email: "aaa@bbb.com",
Name: "NAME",
Password: "PAss00!!",
Password: lo.ToPtr("PAss00!!"),
User: interfaces.SignupUserParam{
UserID: &uid,
TeamID: &tid,
Expand Down Expand Up @@ -88,7 +89,7 @@ func TestUser_Signup(t *testing.T) {
args: interfaces.SignupParam{
Email: "aaa@bbb.com",
Name: "NAME",
Password: "PAss00!!",
Password: lo.ToPtr("PAss00!!"),
User: interfaces.SignupUserParam{
UserID: &uid,
TeamID: &tid,
Expand Down Expand Up @@ -117,10 +118,10 @@ func TestUser_Signup(t *testing.T) {
Verification(user.VerificationFrom(mockcode, mocktime, true)).
MustBuild(),
args: interfaces.SignupParam{
Sub: sr("SUB"),
Sub: lo.ToPtr("SUB"),
Email: "aaa@bbb.com",
Name: "NAME",
Password: "PAss00!!",
Password: lo.ToPtr("PAss00!!"),
User: interfaces.SignupUserParam{
UserID: &uid,
TeamID: &tid,
Expand All @@ -135,11 +136,11 @@ func TestUser_Signup(t *testing.T) {
signupSecret: "",
authSrvUIDomain: "",
args: interfaces.SignupParam{
Sub: sr("SUB"),
Sub: lo.ToPtr("SUB"),
Email: "aaa@bbb.com",
Name: "NAME",
Password: "PAss00!!",
Secret: sr("hogehoge"),
Password: lo.ToPtr("PAss00!!"),
Secret: lo.ToPtr("hogehoge"),
User: interfaces.SignupUserParam{
UserID: &uid,
TeamID: &tid,
Expand Down Expand Up @@ -170,11 +171,11 @@ func TestUser_Signup(t *testing.T) {
signupSecret: "SECRET",
authSrvUIDomain: "",
args: interfaces.SignupParam{
Sub: sr("SUB"),
Sub: lo.ToPtr("SUB"),
Email: "aaa@bbb.com",
Name: "NAME",
Password: "PAss00!!",
Secret: sr("SECRET"),
Password: lo.ToPtr("PAss00!!"),
Secret: lo.ToPtr("SECRET"),
User: interfaces.SignupUserParam{
UserID: &uid,
TeamID: &tid,
Expand Down Expand Up @@ -209,11 +210,11 @@ func TestUser_Signup(t *testing.T) {
signupSecret: "SECRET",
authSrvUIDomain: "",
args: interfaces.SignupParam{
Sub: sr("SUB"),
Sub: lo.ToPtr("SUB"),
Email: "aaa@bbb.com",
Name: "NAME",
Password: "PAss00!!",
Secret: sr("SECRET!"),
Password: lo.ToPtr("PAss00!!"),
Secret: lo.ToPtr("SECRET!"),
},
wantError: interfaces.ErrSignupInvalidSecret,
},
Expand All @@ -222,10 +223,10 @@ func TestUser_Signup(t *testing.T) {
signupSecret: "SECRET",
authSrvUIDomain: "",
args: interfaces.SignupParam{
Sub: sr("SUB"),
Sub: lo.ToPtr("SUB"),
Email: "aaa@bbb.com",
Name: "NAME",
Password: "PAss00!!",
Password: lo.ToPtr("PAss00!!"),
},
wantError: interfaces.ErrSignupInvalidSecret,
},
Expand All @@ -234,7 +235,7 @@ func TestUser_Signup(t *testing.T) {
args: interfaces.SignupParam{
Email: "aaa",
Name: "NAME",
Password: "PAss00!!",
Password: lo.ToPtr("PAss00!!"),
},
wantError: user.ErrInvalidEmail,
},
Expand All @@ -243,7 +244,7 @@ func TestUser_Signup(t *testing.T) {
args: interfaces.SignupParam{
Email: "aaa@bbb.com",
Name: "NAME",
Password: "PAss00",
Password: lo.ToPtr("PAss00"),
},
wantError: user.ErrPasswordLength,
},
Expand All @@ -252,7 +253,7 @@ func TestUser_Signup(t *testing.T) {
args: interfaces.SignupParam{
Email: "aaa@bbb.com",
Name: "",
Password: "PAss00!!",
Password: lo.ToPtr("PAss00!!"),
},
wantError: interfaces.ErrSignupInvalidName,
},
Expand Down Expand Up @@ -400,7 +401,7 @@ func TestUser_SignupOIDC(t *testing.T) {
AccessToken: "accesstoken",
Issuer: "https://issuer",
Sub: "sub",
Secret: sr("SECRET"),
Secret: lo.ToPtr("SECRET"),
User: interfaces.SignupUserParam{
UserID: &uid,
TeamID: &tid,
Expand Down Expand Up @@ -468,7 +469,7 @@ func TestUser_SignupOIDC(t *testing.T) {
AccessToken: "accesstoken",
Issuer: "https://issuer",
Sub: "sub",
Secret: sr("SECRET!"),
Secret: lo.ToPtr("SECRET!"),
User: interfaces.SignupUserParam{
UserID: &uid,
TeamID: &tid,
Expand Down Expand Up @@ -543,7 +544,3 @@ func TestIssToURL(t *testing.T) {
assert.Equal(t, &url.URL{Scheme: "https", Host: "iss.com", Path: "/hoge"}, issToURL("https://iss.com/hoge", ""))
assert.Equal(t, &url.URL{Scheme: "https", Host: "iss.com", Path: "/hoge/foobar"}, issToURL("https://iss.com/hoge", "foobar"))
}

func sr(s string) *string {
return &s
}
2 changes: 1 addition & 1 deletion internal/usecase/interfaces/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type SignupParam struct {
Sub *string // required by Auth0
Email string
Name string
Password string
Password *string
Secret *string
User SignupUserParam
}
Expand Down

0 comments on commit a793761

Please sign in to comment.