diff --git a/pkg/onboarding/application/dto/input.go b/pkg/onboarding/application/dto/input.go index 25b9e23f..63e6a29c 100644 --- a/pkg/onboarding/application/dto/input.go +++ b/pkg/onboarding/application/dto/input.go @@ -109,8 +109,8 @@ type StaffProfileInput struct { // TODO: the list of facilities to switch between is strictly those that the user is assigned to DefaultFacilityID *string `json:"defaultFacilityID"` - // // there is nothing special about super-admin; just the set of roles they have - // Roles []domain.RoleType `json:"roles"` // TODO: roles are an enum (controlled list), known to both FE and BE + // there is nothing special about super-admin; just the set of roles they have + Roles []enums.RolesType `json:"roles"` // TODO: roles are an enum (controlled list), known to both FE and BE Addresses []*AddressesInput `json:"addresses"` } diff --git a/pkg/onboarding/application/enums/role_type.go b/pkg/onboarding/application/enums/role_type.go new file mode 100644 index 00000000..f06741e2 --- /dev/null +++ b/pkg/onboarding/application/enums/role_type.go @@ -0,0 +1,82 @@ +package enums + +import ( + "fmt" +) + +// RolesType is a list of all the role types. +type RolesType string + +// contacts type constants +const ( + RolesTypeCanRegisterStaff RolesType = "CAN_REGISTER_STAFF" + RolesTypeCanInviteStaff RolesType = "CAN_INVITE_STAFF" + RolesTypeCanSuspendStaff RolesType = "CAN_SUSPEND_STAFF" + RolesTypeCanActivateStaff RolesType = "CAN_ACTIVATE_STAFF" + RolesTypeCanDeleteStaff RolesType = "CAN_DELETE_STAFF" + RolesTypeCanInactivateStaff RolesType = "CAN_INACTIVATE_STAFF" + + RolesTypeCanRegisterClient RolesType = "CAN_REGISTER_CLIENT" + RolesTypeCanInviteClient RolesType = "CAN_INVITE_CLIENT" + RolesTypeCanSuspendClient RolesType = "CAN_SUSPEND_CLIENT" + RolesTypeCanActivateClient RolesType = "CAN_ACTIVATE_CLIENT" + RolesTypeCanDeleteClient RolesType = "CAN_DELETE_CLIENT" + RolesTypeCanInactivateClient RolesType = "CAN_INACTIVATE_CLIENT" +) + +// AllRoles is a set of a valid and known role types. +var AllRoles = []RolesType{ + RolesTypeCanRegisterStaff, + RolesTypeCanInviteStaff, + RolesTypeCanSuspendStaff, + RolesTypeCanActivateStaff, + RolesTypeCanDeleteStaff, + RolesTypeCanInactivateStaff, + + RolesTypeCanRegisterClient, + RolesTypeCanInviteClient, + RolesTypeCanSuspendClient, + RolesTypeCanActivateClient, + RolesTypeCanDeleteClient, + RolesTypeCanInactivateClient, +} + +// IsValid returns true if a role is valid +func (m RolesType) IsValid() bool { + switch m { + case RolesTypeCanRegisterStaff, + RolesTypeCanInviteStaff, + RolesTypeCanSuspendStaff, + RolesTypeCanActivateStaff, + RolesTypeCanDeleteStaff, + RolesTypeCanInactivateStaff, + + RolesTypeCanRegisterClient, + RolesTypeCanInviteClient, + RolesTypeCanSuspendClient, + RolesTypeCanActivateClient, + RolesTypeCanDeleteClient, + RolesTypeCanInactivateClient: + return true + } + return false +} + +// String converts roles to string. +func (m RolesType) String() string { + return string(m) +} + +// UnmarshalGQL converts the supplied value to a role type. +func (m *RolesType) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *m = RolesType(str) + if !m.IsValid() { + return fmt.Errorf("%s is not a valid RolesType", str) + } + return nil +} diff --git a/pkg/onboarding/domain/models.go b/pkg/onboarding/domain/models.go index 7c6cff70..6eb9a685 100644 --- a/pkg/onboarding/domain/models.go +++ b/pkg/onboarding/domain/models.go @@ -265,7 +265,7 @@ type StaffProfile struct { DefaultFacilityID *string // there is nothing special about super-admin; just the set of roles they have - Roles []string // TODO: roles are an enum (controlled list), known to both FE and BE + Roles []enums.RolesType // TODO: roles are an enum (controlled list), known to both FE and BE Addresses []*Addresses } diff --git a/pkg/onboarding/infrastructure/database/postgres/gorm/mock/gorm_mock.go b/pkg/onboarding/infrastructure/database/postgres/gorm/mock/gorm_mock.go index 5f81f0f2..d82f131d 100644 --- a/pkg/onboarding/infrastructure/database/postgres/gorm/mock/gorm_mock.go +++ b/pkg/onboarding/infrastructure/database/postgres/gorm/mock/gorm_mock.go @@ -224,6 +224,8 @@ func NewGormMock() *GormMock { RegisterStaffUserFn: func(ctx context.Context, user *gorm.User, staff *gorm.StaffProfile) (*gorm.StaffUserProfile, error) { ID := uuid.New().String() testTime := time.Now() + roles := []string{enums.RolesTypeCanInviteClient.String()} + languages := []string{string(enumutils.LanguageEn)} return &gorm.StaffUserProfile{ User: &gorm.User{ UserID: &ID, @@ -239,6 +241,7 @@ func NewGormMock() *GormMock { FailedLoginCount: "0", TermsAccepted: true, AcceptedTermsID: ID, + Languages: languages, }, Staff: &gorm.StaffProfile{ StaffProfileID: &ID, @@ -256,6 +259,7 @@ func NewGormMock() *GormMock { Active: true, }, }, + Roles: roles, }, }, nil }, diff --git a/pkg/onboarding/infrastructure/database/postgres/gorm/tables.go b/pkg/onboarding/infrastructure/database/postgres/gorm/tables.go index 11261dec..ae6adbde 100644 --- a/pkg/onboarding/infrastructure/database/postgres/gorm/tables.go +++ b/pkg/onboarding/infrastructure/database/postgres/gorm/tables.go @@ -187,8 +187,8 @@ type StaffProfile struct { DefaultFacilityID *string `gorm:"column:default_facility_id"` // TODO: required, FK to facility Facility Facility `gorm:"foreignKey:default_facility_id;references:facility_id;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` - // // there is nothing special about super-admin; just the set of roles they have - // Roles []string `gorm:"type:text[];column:roles"` // TODO: roles are an enum (controlled list), known to both FE and BE + // there is nothing special about super-admin; just the set of roles they have + Roles pq.StringArray `gorm:"type:text[];column:roles"` // TODO: roles are an enum (controlled list), known to both FE and BE Addresses []*Addresses `gorm:"ForeignKey:StaffProfileID"` } diff --git a/pkg/onboarding/infrastructure/database/postgres/mappers.go b/pkg/onboarding/infrastructure/database/postgres/mappers.go index 1425e982..8b30706c 100644 --- a/pkg/onboarding/infrastructure/database/postgres/mappers.go +++ b/pkg/onboarding/infrastructure/database/postgres/mappers.go @@ -4,6 +4,7 @@ import ( "strconv" "github.com/savannahghi/enumutils" + "github.com/savannahghi/onboarding-service/pkg/onboarding/application/enums" "github.com/savannahghi/onboarding-service/pkg/onboarding/domain" "github.com/savannahghi/onboarding-service/pkg/onboarding/infrastructure/database/postgres/gorm" ) @@ -115,14 +116,20 @@ func (d *OnboardingDb) mapRegisterStaffObjectToDomain(userStaffObject *gorm.Staf addresses = append(addresses, address) } + roles := []enums.RolesType{} + for _, r := range staffObject.Roles { + roles = append(roles, enums.RolesType(r)) + + } + staffProfile := &domain.StaffProfile{ ID: staffObject.StaffProfileID, UserID: userObject.UserID, StaffNumber: staffObject.StaffNumber, // Facilities: staffObject.Facilities, DefaultFacilityID: staffObject.DefaultFacilityID, - // Roles: staffObject.Roles, - Addresses: addresses, + Addresses: addresses, + Roles: roles, } return &domain.StaffUserProfile{ User: user, diff --git a/pkg/onboarding/infrastructure/database/postgres/mock/pg_mock.go b/pkg/onboarding/infrastructure/database/postgres/mock/pg_mock.go index 2291ff4e..1bbef6c2 100644 --- a/pkg/onboarding/infrastructure/database/postgres/mock/pg_mock.go +++ b/pkg/onboarding/infrastructure/database/postgres/mock/pg_mock.go @@ -147,6 +147,8 @@ func NewPostgresMock() *PostgresMock { RegisterStaffUserFn: func(ctx context.Context, user *dto.UserInput, staff *dto.StaffProfileInput) (*domain.StaffUserProfile, error) { ID := uuid.New().String() testTime := time.Now() + roles := []enums.RolesType{enums.RolesTypeCanInviteClient} + languages := []enumutils.Language{enumutils.LanguageEn} return &domain.StaffUserProfile{ User: &domain.User{ ID: &ID, @@ -162,6 +164,7 @@ func NewPostgresMock() *PostgresMock { FailedLoginCount: "0", TermsAccepted: true, AcceptedTermsID: ID, + Languages: languages, }, Staff: &domain.StaffProfile{ ID: &ID, @@ -179,6 +182,7 @@ func NewPostgresMock() *PostgresMock { Active: true, }, }, + Roles: roles, }, }, nil }, diff --git a/pkg/onboarding/infrastructure/database/postgres/pg_create.go b/pkg/onboarding/infrastructure/database/postgres/pg_create.go index afddcf39..e023cba9 100644 --- a/pkg/onboarding/infrastructure/database/postgres/pg_create.go +++ b/pkg/onboarding/infrastructure/database/postgres/pg_create.go @@ -114,10 +114,20 @@ func (d *OnboardingDb) RegisterStaffUser(ctx context.Context, user *dto.UserInpu } } + roles := []string{} + for _, r := range staff.Roles { + if !r.IsValid() { + return nil, fmt.Errorf("role %s is not valid", r) + } + + roles = append(roles, r.String()) + } + staffObject := &gorm.StaffProfile{ StaffNumber: staff.StaffNumber, DefaultFacilityID: staff.DefaultFacilityID, Addresses: addresses, + Roles: roles, } userStaffProfile, err := d.create.RegisterStaffUser(ctx, userObject, staffObject) diff --git a/pkg/onboarding/infrastructure/database/postgres/pg_create_test.go b/pkg/onboarding/infrastructure/database/postgres/pg_create_test.go index e92526fb..6c3409b5 100644 --- a/pkg/onboarding/infrastructure/database/postgres/pg_create_test.go +++ b/pkg/onboarding/infrastructure/database/postgres/pg_create_test.go @@ -243,6 +243,7 @@ func TestOnboardingDb_RegisterStaffUser(t *testing.T) { testUserID := uuid.New().String() testTime := time.Now() testID := uuid.New().String() + rolesInput := []enums.RolesType{enums.RolesTypeCanInviteClient} type args struct { ctx context.Context @@ -283,6 +284,7 @@ func TestOnboardingDb_RegisterStaffUser(t *testing.T) { Active: true, }, }, + Roles: rolesInput, } staffNoFacilityIDInput := &dto.StaffProfileInput{ StaffNumber: "s123", @@ -375,6 +377,7 @@ func TestOnboardingDb_RegisterStaffUser(t *testing.T) { Active: true, }, }, + Roles: []string{enums.RolesTypeCanInviteClient.String()}, }, }, nil } diff --git a/pkg/onboarding/presentation/graph/enums.graphql b/pkg/onboarding/presentation/graph/enums.graphql index 29d0607c..fbcc628e 100644 --- a/pkg/onboarding/presentation/graph/enums.graphql +++ b/pkg/onboarding/presentation/graph/enums.graphql @@ -1,3 +1,19 @@ +enum RolesType { + CAN_REGISTER_STAFF + CAN_INVITE_STAFF + CAN_SUSPEND_STAFF + CAN_ACTIVATE_STAFF + CAN_DELETE_STAFF + CAN_INACTIVATE_STAFF + + CAN_REGISTER_CLIENT + CAN_INVITE_CLIENT + CAN_SUSPEND_CLIENT + CAN_ACTIVATE_CLIENT + CAN_DELETE_CLIENT + CAN_INACTIVATE_CLIENT +} + enum ClientType { PMTCT OVC diff --git a/pkg/onboarding/presentation/graph/generated/generated.go b/pkg/onboarding/presentation/graph/generated/generated.go index abbecf9e..66da48c1 100644 --- a/pkg/onboarding/presentation/graph/generated/generated.go +++ b/pkg/onboarding/presentation/graph/generated/generated.go @@ -288,6 +288,7 @@ type ComplexityRoot struct { Addresses func(childComplexity int) int DefaultFacilityID func(childComplexity int) int ID func(childComplexity int) int + Roles func(childComplexity int) int StaffNumber func(childComplexity int) int UserID func(childComplexity int) int } @@ -1793,6 +1794,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.StaffProfile.ID(childComplexity), true + case "StaffProfile.roles": + if e.complexity.StaffProfile.Roles == nil { + break + } + + return e.complexity.StaffProfile.Roles(childComplexity), true + case "StaffProfile.staffNumber": if e.complexity.StaffProfile.StaffNumber == nil { break @@ -2249,7 +2257,23 @@ var sources = []*ast.Source{ ): Identifier! } `, BuiltIn: false}, - {Name: "pkg/onboarding/presentation/graph/enums.graphql", Input: `enum ClientType { + {Name: "pkg/onboarding/presentation/graph/enums.graphql", Input: `enum RolesType { + CAN_REGISTER_STAFF + CAN_INVITE_STAFF + CAN_SUSPEND_STAFF + CAN_ACTIVATE_STAFF + CAN_DELETE_STAFF + CAN_INACTIVATE_STAFF + + CAN_REGISTER_CLIENT + CAN_INVITE_CLIENT + CAN_SUSPEND_CLIENT + CAN_ACTIVATE_CLIENT + CAN_DELETE_CLIENT + CAN_INACTIVATE_CLIENT +} + +enum ClientType { PMTCT OVC } @@ -2383,8 +2407,8 @@ input StaffProfileInput { staffNumber: String! # facilities: [FacilityInput!] defaultFacilityID: String! - # roles: [RoleType] # TODO: roles are an enum (controlled list), known to both FE and BE addresses: [AddressesInput!]! + roles: [RolesType] # TODO: roles are an enum (controlled list), known to both FE and BE } input ContactInput { @@ -2475,8 +2499,8 @@ type StaffProfile { staffNumber: String! # facilities: [Facility!] defaultFacilityID: String! - # roles: [String!] # TODO: roles are an enum (controlled list), known to both FE and BE addresses: [Addresses!] + roles: [RolesType!] } type StaffUserProfile { @@ -9776,6 +9800,38 @@ func (ec *executionContext) _StaffProfile_addresses(ctx context.Context, field g return ec.marshalOAddresses2ᚕᚖgithubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋdomainᚐAddressesᚄ(ctx, field.Selections, res) } +func (ec *executionContext) _StaffProfile_roles(ctx context.Context, field graphql.CollectedField, obj *domain1.StaffProfile) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "StaffProfile", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Roles, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]enums.RolesType) + fc.Result = res + return ec.marshalORolesType2ᚕgithubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesTypeᚄ(ctx, field.Selections, res) +} + func (ec *executionContext) _StaffUserProfile_user(ctx context.Context, field graphql.CollectedField, obj *domain1.StaffUserProfile) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -13171,6 +13227,14 @@ func (ec *executionContext) unmarshalInputStaffProfileInput(ctx context.Context, if err != nil { return it, err } + case "roles": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("roles")) + it.Roles, err = ec.unmarshalORolesType2ᚕgithubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx, v) + if err != nil { + return it, err + } } } @@ -14776,6 +14840,8 @@ func (ec *executionContext) _StaffProfile(ctx context.Context, sel ast.Selection } case "addresses": out.Values[i] = ec._StaffProfile_addresses(ctx, field, obj) + case "roles": + out.Values[i] = ec._StaffProfile_roles(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -16094,6 +16160,22 @@ func (ec *executionContext) unmarshalNRolePermissionInput2githubᚗcomᚋsavanna return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNRolesType2githubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx context.Context, v interface{}) (enums.RolesType, error) { + tmp, err := graphql.UnmarshalString(v) + res := enums.RolesType(tmp) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNRolesType2githubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx context.Context, sel ast.SelectionSet, v enums.RolesType) graphql.Marshaler { + res := graphql.MarshalString(string(v)) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + } + return res +} + func (ec *executionContext) unmarshalNSortOrder2githubᚗcomᚋsavannahghiᚋenumutilsᚐSortOrder(ctx context.Context, v interface{}) (enumutils.SortOrder, error) { var res enumutils.SortOrder err := res.UnmarshalGQL(v) @@ -17360,6 +17442,144 @@ func (ec *executionContext) marshalORoleOutput2ᚖgithubᚗcomᚋsavannahghiᚋo return ec._RoleOutput(ctx, sel, v) } +func (ec *executionContext) unmarshalORolesType2githubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx context.Context, v interface{}) (enums.RolesType, error) { + tmp, err := graphql.UnmarshalString(v) + res := enums.RolesType(tmp) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalORolesType2githubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx context.Context, sel ast.SelectionSet, v enums.RolesType) graphql.Marshaler { + return graphql.MarshalString(string(v)) +} + +func (ec *executionContext) unmarshalORolesType2ᚕgithubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx context.Context, v interface{}) ([]enums.RolesType, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]enums.RolesType, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalORolesType2githubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalORolesType2ᚕgithubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx context.Context, sel ast.SelectionSet, v []enums.RolesType) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalORolesType2githubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) unmarshalORolesType2ᚕgithubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesTypeᚄ(ctx context.Context, v interface{}) ([]enums.RolesType, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + if tmp1, ok := v.([]interface{}); ok { + vSlice = tmp1 + } else { + vSlice = []interface{}{v} + } + } + var err error + res := make([]enums.RolesType, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNRolesType2githubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalORolesType2ᚕgithubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []enums.RolesType) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNRolesType2githubᚗcomᚋsavannahghiᚋonboardingᚑserviceᚋpkgᚋonboardingᚋapplicationᚋenumsᚐRolesType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + func (ec *executionContext) unmarshalOSortParam2ᚕᚖgithubᚗcomᚋsavannahghiᚋfirebasetoolsᚐSortParam(ctx context.Context, v interface{}) ([]*firebasetools.SortParam, error) { if v == nil { return nil, nil diff --git a/pkg/onboarding/presentation/graph/input.graphql b/pkg/onboarding/presentation/graph/input.graphql index 2b9f75e2..bbc49c22 100644 --- a/pkg/onboarding/presentation/graph/input.graphql +++ b/pkg/onboarding/presentation/graph/input.graphql @@ -30,8 +30,8 @@ input StaffProfileInput { staffNumber: String! # facilities: [FacilityInput!] defaultFacilityID: String! - # roles: [RoleType] # TODO: roles are an enum (controlled list), known to both FE and BE addresses: [AddressesInput!]! + roles: [RolesType] # TODO: roles are an enum (controlled list), known to both FE and BE } input ContactInput { diff --git a/pkg/onboarding/presentation/graph/types.graphql b/pkg/onboarding/presentation/graph/types.graphql index d7958b87..7653158a 100644 --- a/pkg/onboarding/presentation/graph/types.graphql +++ b/pkg/onboarding/presentation/graph/types.graphql @@ -52,8 +52,8 @@ type StaffProfile { staffNumber: String! # facilities: [Facility!] defaultFacilityID: String! - # roles: [String!] # TODO: roles are an enum (controlled list), known to both FE and BE addresses: [Addresses!] + roles: [RolesType!] } type StaffUserProfile { diff --git a/pkg/onboarding/usecases/mock/usecase_mock.go b/pkg/onboarding/usecases/mock/usecase_mock.go index 76c9d6e9..667eb9f7 100644 --- a/pkg/onboarding/usecases/mock/usecase_mock.go +++ b/pkg/onboarding/usecases/mock/usecase_mock.go @@ -88,6 +88,8 @@ func NewCreateMock() *CreateMock { RegisterStaffUserFn: func(ctx context.Context, user *dto.UserInput, staff *dto.StaffProfileInput) (*domain.StaffUserProfile, error) { ID := uuid.New().String() testTime := time.Now() + roles := []enums.RolesType{enums.RolesTypeCanInviteClient} + languages := []enumutils.Language{enumutils.LanguageEn} return &domain.StaffUserProfile{ User: &domain.User{ ID: &ID, @@ -103,6 +105,7 @@ func NewCreateMock() *CreateMock { FailedLoginCount: "0", TermsAccepted: true, AcceptedTermsID: ID, + Languages: languages, }, Staff: &domain.StaffProfile{ ID: &ID, @@ -120,6 +123,7 @@ func NewCreateMock() *CreateMock { Active: true, }, }, + Roles: roles, }, }, nil }, diff --git a/pkg/onboarding/usecases/staff/staff_integration_test.go b/pkg/onboarding/usecases/staff/staff_integration_test.go index c81ddbaa..53f2965e 100644 --- a/pkg/onboarding/usecases/staff/staff_integration_test.go +++ b/pkg/onboarding/usecases/staff/staff_integration_test.go @@ -70,6 +70,7 @@ func TestUseCaseStaffProfileImpl_RegisterStaffUser(t *testing.T) { Active: true, }, }, + Roles: []enums.RolesType{enums.RolesTypeCanInviteClient}, } // Second set of valid Inputs @@ -107,6 +108,7 @@ func TestUseCaseStaffProfileImpl_RegisterStaffUser(t *testing.T) { Active: true, }, }, + Roles: []enums.RolesType{enums.RolesTypeCanInviteClient}, } // Invalid facility id @@ -131,6 +133,13 @@ func TestUseCaseStaffProfileImpl_RegisterStaffUser(t *testing.T) { }, } + // Invalid role + staffInputInvalidRole := &dto.StaffProfileInput{ + StaffNumber: ksuid.New().String(), + DefaultFacilityID: &testFacilityID, + Roles: []enums.RolesType{"invalid"}, + } + // Invalid county input staffInputInvalidCounty := &dto.StaffProfileInput{ StaffNumber: staffID2, @@ -164,6 +173,16 @@ func TestUseCaseStaffProfileImpl_RegisterStaffUser(t *testing.T) { // TODO:add case where county is valid but does not belong to country after another country is available + // invalid: non existent facility assignment + useStaffProfile, err = f.RegisterStaffUser(ctx, userInput, staffInputNoFacility) + assert.Nil(t, useStaffProfile) + assert.NotNil(t, err) + + // invalid: invalid tole provided + useStaffProfile, err = f.RegisterStaffUser(ctx, userInput, staffInputInvalidRole) + assert.Nil(t, useStaffProfile) + assert.NotNil(t, err) + //valid: create a staff user with valid parameters useStaffProfile, err = f.RegisterStaffUser(ctx, userInput, staffInput) assert.Nil(t, err) diff --git a/pkg/onboarding/usecases/staff/staff_unit_test.go b/pkg/onboarding/usecases/staff/staff_unit_test.go index 6dbbe038..aaeab044 100644 --- a/pkg/onboarding/usecases/staff/staff_unit_test.go +++ b/pkg/onboarding/usecases/staff/staff_unit_test.go @@ -47,6 +47,7 @@ func TestOnboardingDb_RegisterStaffUser(t *testing.T) { staffInput := &dto.StaffProfileInput{ StaffNumber: "s123", DefaultFacilityID: &testFacilityID, + Roles: []enums.RolesType{enums.RolesTypeCanInviteClient}, } staffNoFacilityInput := &dto.StaffProfileInput{ @@ -144,6 +145,7 @@ func TestOnboardingDb_RegisterStaffUser(t *testing.T) { Active: true, }, }, + Roles: []enums.RolesType{enums.RolesTypeCanInviteClient}, }, }, nil }