From db3a3088f9566f51ec5ef7068ed6f49f397ff401 Mon Sep 17 00:00:00 2001 From: Malcolm Bouzi Date: Thu, 4 Feb 2021 10:00:15 -0500 Subject: [PATCH] satellite/satellitedb: add professional user fields to db interface (#4034) --- satellite/console/users.go | 21 ++++++++--- satellite/console/users_test.go | 65 +++++++++++++++++++++++++++++---- satellite/satellitedb/users.go | 40 ++++++++++++++++---- 3 files changed, 105 insertions(+), 21 deletions(-) diff --git a/satellite/console/users.go b/satellite/console/users.go index cee6cc939..5fcba86e9 100644 --- a/satellite/console/users.go +++ b/satellite/console/users.go @@ -49,11 +49,16 @@ func (user *UserInfo) IsValid() error { // CreateUser struct holds info for User creation. type CreateUser struct { - FullName string `json:"fullName"` - ShortName string `json:"shortName"` - Email string `json:"email"` - PartnerID string `json:"partnerId"` - Password string `json:"password"` + FullName string `json:"fullName"` + ShortName string `json:"shortName"` + Email string `json:"email"` + PartnerID string `json:"partnerId"` + Password string `json:"password"` + IsProfessional bool `json:"isProfessional"` + Position string `json:"position"` + CompanyName string `json:"companyName"` + CompanySize int `json:"companySize"` + WorkingOn string `json:"workingOn"` } // IsValid checks CreateUser validity and returns error describing whats wrong. @@ -105,4 +110,10 @@ type User struct { CreatedAt time.Time `json:"createdAt"` ProjectLimit int `json:"projectLimit"` + + IsProfessional bool `json:"isProfessional"` + Position string `json:"position"` + CompanyName string `json:"companyName"` + CompanySize int `json:"companySize"` + WorkingOn string `json:"workingOn"` } diff --git a/satellite/console/users_test.go b/satellite/console/users_test.go index 685b6f7c8..07a3bd205 100644 --- a/satellite/console/users_test.go +++ b/satellite/console/users_test.go @@ -18,14 +18,19 @@ import ( ) const ( - lastName = "lastName" - email = "email@mail.test" - passValid = "123456" - name = "name" - newName = "newName" - newLastName = "newLastName" - newEmail = "newEmail@mail.test" - newPass = "newPass1234567890123456789012345" + lastName = "lastName" + email = "email@mail.test" + passValid = "123456" + name = "name" + newName = "newName" + newLastName = "newLastName" + newEmail = "newEmail@mail.test" + newPass = "newPass1234567890123456789012345" + position = "position" + companyName = "companyName" + companySize = 123 + workingOn = "workingOn" + isProfessional = true ) func TestUserRepository(t *testing.T) { @@ -54,6 +59,22 @@ func TestUserRepository(t *testing.T) { CreatedAt: time.Now(), } testUsers(ctx, t, repository, user) + + // test professional user + user = &console.User{ + ID: testrand.UUID(), + FullName: name, + ShortName: lastName, + Email: email, + PasswordHash: []byte(passValid), + CreatedAt: time.Now(), + IsProfessional: isProfessional, + Position: position, + CompanyName: companyName, + CompanySize: companySize, + WorkingOn: workingOn, + } + testUsers(ctx, t, repository, user) }) } @@ -114,6 +135,17 @@ func testUsers(ctx context.Context, t *testing.T, repository console.Users, user assert.Equal(t, name, userByEmail.FullName) assert.Equal(t, lastName, userByEmail.ShortName) assert.Equal(t, user.PartnerID, userByEmail.PartnerID) + if user.IsProfessional { + assert.Equal(t, workingOn, userByEmail.WorkingOn) + assert.Equal(t, position, userByEmail.Position) + assert.Equal(t, companyName, userByEmail.CompanyName) + assert.Equal(t, companySize, userByEmail.CompanySize) + } else { + assert.Equal(t, "", userByEmail.WorkingOn) + assert.Equal(t, "", userByEmail.Position) + assert.Equal(t, "", userByEmail.CompanyName) + assert.Equal(t, 0, userByEmail.CompanySize) + } userByID, err := repository.Get(ctx, userByEmail.ID) assert.NoError(t, err) @@ -121,6 +153,18 @@ func testUsers(ctx context.Context, t *testing.T, repository console.Users, user assert.Equal(t, lastName, userByID.ShortName) assert.Equal(t, user.PartnerID, userByID.PartnerID) + if user.IsProfessional { + assert.Equal(t, workingOn, userByID.WorkingOn) + assert.Equal(t, position, userByID.Position) + assert.Equal(t, companyName, userByID.CompanyName) + assert.Equal(t, companySize, userByID.CompanySize) + } else { + assert.Equal(t, "", userByID.WorkingOn) + assert.Equal(t, "", userByID.Position) + assert.Equal(t, "", userByID.CompanyName) + assert.Equal(t, 0, userByID.CompanySize) + } + assert.Equal(t, userByID.ID, userByEmail.ID) assert.Equal(t, userByID.FullName, userByEmail.FullName) assert.Equal(t, userByID.ShortName, userByEmail.ShortName) @@ -128,6 +172,11 @@ func testUsers(ctx context.Context, t *testing.T, repository console.Users, user assert.Equal(t, userByID.PasswordHash, userByEmail.PasswordHash) assert.Equal(t, userByID.PartnerID, userByEmail.PartnerID) assert.Equal(t, userByID.CreatedAt, userByEmail.CreatedAt) + assert.Equal(t, userByID.IsProfessional, userByEmail.IsProfessional) + assert.Equal(t, userByID.WorkingOn, userByEmail.WorkingOn) + assert.Equal(t, userByID.Position, userByEmail.Position) + assert.Equal(t, userByID.CompanyName, userByEmail.CompanyName) + assert.Equal(t, userByID.CompanySize, userByEmail.CompanySize) }) t.Run("Update user success", func(t *testing.T) { diff --git a/satellite/satellitedb/users.go b/satellite/satellitedb/users.go index d9db302a7..4424e285b 100644 --- a/satellite/satellitedb/users.go +++ b/satellite/satellitedb/users.go @@ -54,7 +54,8 @@ func (users *users) Insert(ctx context.Context, user *console.User) (_ *console. } optional := dbx.User_Create_Fields{ - ShortName: dbx.User_ShortName(user.ShortName), + ShortName: dbx.User_ShortName(user.ShortName), + IsProfessional: dbx.User_IsProfessional(user.IsProfessional), } if !user.PartnerID.IsZero() { optional.PartnerId = dbx.User_PartnerId(user.PartnerID[:]) @@ -62,6 +63,12 @@ func (users *users) Insert(ctx context.Context, user *console.User) (_ *console. if user.ProjectLimit != 0 { optional.ProjectLimit = dbx.User_ProjectLimit(user.ProjectLimit) } + if user.IsProfessional { + optional.Position = dbx.User_Position(user.Position) + optional.CompanyName = dbx.User_CompanyName(user.CompanyName) + optional.CompanySize = dbx.User_CompanySize(user.CompanySize) + optional.WorkingOn = dbx.User_WorkingOn(user.WorkingOn) + } createdUser, err := users.db.Create_User(ctx, dbx.User_Id(user.ID[:]), @@ -143,13 +150,14 @@ func userFromDBX(ctx context.Context, user *dbx.User) (_ *console.User, err erro } result := console.User{ - ID: id, - FullName: user.FullName, - Email: user.Email, - PasswordHash: user.PasswordHash, - Status: console.UserStatus(user.Status), - CreatedAt: user.CreatedAt, - ProjectLimit: user.ProjectLimit, + ID: id, + FullName: user.FullName, + Email: user.Email, + PasswordHash: user.PasswordHash, + Status: console.UserStatus(user.Status), + CreatedAt: user.CreatedAt, + ProjectLimit: user.ProjectLimit, + IsProfessional: user.IsProfessional, } if user.PartnerId != nil { @@ -163,6 +171,22 @@ func userFromDBX(ctx context.Context, user *dbx.User) (_ *console.User, err erro result.ShortName = *user.ShortName } + if user.Position != nil { + result.Position = *user.Position + } + + if user.CompanyName != nil { + result.CompanyName = *user.CompanyName + } + + if user.CompanySize != nil { + result.CompanySize = *user.CompanySize + } + + if user.WorkingOn != nil { + result.WorkingOn = *user.WorkingOn + } + return &result, nil }