satellite/satellitedb: add professional user fields to db interface (#4034)

This commit is contained in:
Malcolm Bouzi 2021-02-04 10:00:15 -05:00 committed by GitHub
parent 615586a471
commit db3a3088f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 21 deletions

View File

@ -54,6 +54,11 @@ type CreateUser struct {
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"`
}

View File

@ -26,6 +26,11 @@ const (
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) {

View File

@ -55,6 +55,7 @@ func (users *users) Insert(ctx context.Context, user *console.User) (_ *console.
optional := dbx.User_Create_Fields{
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[:]),
@ -150,6 +157,7 @@ func userFromDBX(ctx context.Context, user *dbx.User) (_ *console.User, err erro
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
}