Skip to content

Commit

Permalink
EPMUII-7850 make "name" not mandarory at registration
Browse files Browse the repository at this point in the history
  • Loading branch information
wvxiw8 committed Jun 5, 2024
1 parent fea5948 commit da17a8d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 15 deletions.
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,8 @@ github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHN
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
Expand Down Expand Up @@ -1864,6 +1866,8 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion internal/ent/schema/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (User) Fields() []ent.Field {
field.String("login").Unique(),
field.String("email").NotEmpty(),
field.String("password").NotEmpty(),
field.String("name").NotEmpty(),
field.String("name").Optional().Nillable(),
field.String("surname").Optional().Nillable(),
field.String("patronymic").Optional().Nillable(),
field.String("passport_series").Optional().Nillable(),
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func mapUserInfoWoRole(user *ent.User) *models.UserInfo {
ID: &userID,
IsReadonly: &user.IsReadonly,
Login: &user.Login,
Name: &user.Name,
Name: user.Name,
OrgName: user.OrgName,
PassportAuthority: user.PassportAuthority,
PassportIssueDate: &passportDate,
Expand Down
3 changes: 2 additions & 1 deletion internal/handlers/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1487,9 +1487,10 @@ func (s *UserTestSuite) TestUser_UpdateReadonlyAccess_InternalError() {

func validUser(t *testing.T, id int) *ent.User {
t.Helper()
name := fmt.Sprintf("User%d", id)
return &ent.User{
ID: id,
Name: fmt.Sprintf("User%d", id),
Name: &name,
Login: fmt.Sprintf("user_%d", id),
Email: fmt.Sprintf("user_%[email protected]", id),
Edges: ent.UserEdges{
Expand Down
2 changes: 1 addition & 1 deletion internal/middlewares/api_key_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func createPrincipal(user *ent.User) *models.Principal {

func isPersonalDataConfirmed(user *ent.User) bool {
return user != nil &&
user.Name != "" &&
user.Name != nil && *user.Name != "" &&
user.Surname != nil && *user.Surname != "" &&
user.Phone != nil && *user.Phone != ""
}
5 changes: 3 additions & 2 deletions internal/repositories/equipment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ func (s *EquipmentSuite) SetupTest() {
t.Fatal(err)
}

name := "admin"
s.user = &ent.User{
Login: "admin", Email: "[email protected]", Password: "12345", Name: "admin",
Login: "admin", Email: "[email protected]", Password: "12345", Name: &name,
}
_, err = s.client.User.Delete().Exec(s.ctx)
if err != nil {
t.Fatal(err)
}
u, err := s.client.User.Create().
SetLogin(s.user.Login).SetEmail(s.user.Email).
SetPassword(s.user.Password).SetName(s.user.Name).
SetPassword(s.user.Password).SetName(*s.user.Name).
Save(s.ctx)
if err != nil {
t.Fatal(err)
Expand Down
5 changes: 3 additions & 2 deletions internal/repositories/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ func (s *OrderSuite) SetupTest() {
s.orderRepository = NewOrderRepository()
s.orderStatusRepository = NewOrderStatusRepository()

name := "user1"
s.user = &ent.User{
Login: "user1", Email: "[email protected]", Password: "1234", Name: "user1",
Login: "user1", Email: "[email protected]", Password: "1234", Name: &name,
}
_, err := s.client.User.Delete().Exec(s.ctx)
if err != nil {
t.Fatal(err)
}
u, err := s.client.User.Create().
SetLogin(s.user.Login).SetEmail(s.user.Email).
SetPassword(s.user.Password).SetName(s.user.Name).
SetPassword(s.user.Password).SetName(*s.user.Name).
Save(s.ctx)
if err != nil {
t.Fatal(err)
Expand Down
15 changes: 8 additions & 7 deletions internal/repositories/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ func (s *UserSuite) SetupTest() {

s.users = make(map[int]*ent.User)
for i := 1; i <= 12; i++ {
name := fmt.Sprintf("user%d", i)
s.users[i] = &ent.User{
Login: fmt.Sprintf("user_%d", i),
Email: fmt.Sprintf("user_%[email protected]", i),
Password: "password",
Name: fmt.Sprintf("user%d", i),
Name: &name,
}
}

Expand All @@ -53,7 +54,7 @@ func (s *UserSuite) SetupTest() {
}
for i, value := range s.users {
user, errCreate := s.client.User.Create().
SetName(value.Name).
SetName(*value.Name).
SetLogin(value.Login).
SetPassword(value.Password).
SetEmail(value.Email).
Expand Down Expand Up @@ -240,8 +241,8 @@ func (s *UserSuite) TestUserRepository_UserList_OrderByNameDesc() {
prevUserName := "zzzzzzzzzzzzzzzzzzzzz"
for _, value := range users {
require.True(t, mapContainsUser(t, value, s.users))
require.LessOrEqual(t, value.Name, prevUserName)
prevUserName = value.Name
require.LessOrEqual(t, *value.Name, prevUserName)
prevUserName = *value.Name
}
}

Expand Down Expand Up @@ -286,8 +287,8 @@ func (s *UserSuite) TestUserRepository_UserList_OrderByNameAsc() {
prevUserName := ""
for _, value := range users {
require.True(t, mapContainsUser(t, value, s.users))
require.GreaterOrEqual(t, value.Name, prevUserName)
prevUserName = value.Name
require.GreaterOrEqual(t, *value.Name, prevUserName)
prevUserName = *value.Name
}
}

Expand Down Expand Up @@ -431,7 +432,7 @@ func (s *UserSuite) TestUserRepository_DeleteUser_OK() {
func mapContainsUser(t *testing.T, eq *ent.User, m map[int]*ent.User) bool {
t.Helper()
for _, v := range m {
if eq.Name == v.Name && eq.ID == v.ID && eq.Login == v.Login && eq.Email == v.Email {
if *eq.Name == *v.Name && eq.ID == v.ID && eq.Login == v.Login && eq.Email == v.Email {
return true
}
}
Expand Down

0 comments on commit da17a8d

Please sign in to comment.