Skip to content

Commit

Permalink
chore: refactor navigation actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ochom committed Sep 9, 2021
1 parent 41d4a21 commit cf334fd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 90 deletions.
33 changes: 3 additions & 30 deletions pkg/onboarding/application/utils/actions_test.go
Expand Up @@ -190,23 +190,6 @@ func TestGroupPriority(t *testing.T) {
Title: "Home",
SequenceNumber: 1,
}
navAction2 := domain.NavigationAction{
Group: domain.AgentGroup,
Title: "Agent",
SequenceNumber: 2,
Nested: []interface{}{
domain.NavigationAction{
Group: domain.AgentGroup,
Title: "Child 1",
HasParent: true,
},
domain.NavigationAction{
Group: domain.AgentGroup,
Title: "Child 2",
HasParent: true,
},
},
}
navAction3 := domain.NavigationAction{
Group: domain.PatientGroup,
Title: "Patients",
Expand All @@ -227,19 +210,12 @@ func TestGroupPriority(t *testing.T) {
Title: "Consumers",
SequenceNumber: 6,
}
navAction7 := domain.NavigationAction{
Group: domain.EmployeeGroup,
Title: "Employee",
SequenceNumber: 7,
}

actions = append(actions, navAction1)
actions = append(actions, navAction2)
actions = append(actions, navAction3)
actions = append(actions, navAction4)
actions = append(actions, navAction5)
actions = append(actions, navAction6)
actions = append(actions, navAction7)

tests := []struct {
name string
Expand All @@ -259,9 +235,7 @@ func TestGroupPriority(t *testing.T) {
navAction5,
},
wantSecondary: []domain.NavigationAction{
navAction2,
navAction6,
navAction7,
},
},
}
Expand Down Expand Up @@ -290,11 +264,10 @@ func TestGetUserPermissions(t *testing.T) {
{
name: "happy got the right permissions",
args: args{[]profileutils.Role{
{Name: "Agent Role", Scopes: []string{"agent.register", "agent.view"}, Active: true},
{Name: "Agent Role", Scopes: []string{"patient.create", "agent.view"}, Active: true},
{Name: "Agent Role", Scopes: []string{"role.view", "role.create"}, Active: false},
{Name: "Test Role", Scopes: []string{"patient.create", "role.view"}, Active: true},
{Name: "Tester Role", Scopes: []string{"role.view", "role.create"}, Active: false},
}},
want: []string{"agent.register", "agent.view", "patient.create"},
want: []string{"patient.create", "role.view"},
},
}
for _, tt := range tests {
Expand Down
67 changes: 13 additions & 54 deletions pkg/onboarding/domain/actions.go
Expand Up @@ -25,15 +25,10 @@ const (
PatientRegistrationRoute = "/addPatient"
PatientIdentificationRoute = "/patients"
GetHelpRouteRoute = "/helpCenter"

// Has KYC and Covers
RequestsRoute = "/admin"

RoleViewRoute = "/viewCreatedRolesPage"
RoleCreationRoute = "/createRoleStepOne"

EmployeeRegistrationRoute = "/employeeRegistration"
EmployeeIdentificationRoute = "/employeeIdentification"
RequestsRoute = "/admin"
RoleViewRoute = "/viewCreatedRolesPage"
RoleCreationRoute = "/createRoleStepOne"
RoleAssignmentRoute = "/bewellUserIdentification"
)

// Navigation actions
Expand All @@ -47,6 +42,7 @@ const (
RoleNavActionTitle = "Role Management"
RoleViewActionTitle = "View Roles"
RoleCreationActionTitle = "Create Role"
RoleAssignActionTitle = "Assign Role"

PatientNavActionTitle = "Patients"
PatientNavActionDescription = "Patient Navigation action"
Expand All @@ -56,11 +52,6 @@ const (
RequestsNavActionTitle = "Requests"
RequestsNavActionDescription = "Requests Navigation action"

EmployeeNavActionTitle = "Employees"
EmployeeNavActionDescription = "Employee Navigation action"
EmployeeRegistrationActionTitle = "Register Employee"
EmployeeIdentificationActionTitle = "View Employees"

ConsumerNavActionTitle = "Consumers"
ConsumerNavActionDescription = "Consumer Navigation action"

Expand All @@ -78,18 +69,9 @@ const (
//HelpGroup groups all actions under the help resource
HelpGroup NavigationGroup = "help"

//AgentGroup groups all actions under the agent resource
AgentGroup NavigationGroup = "agents"

//KYCGroup groups all actions under the kyc resource
KYCGroup NavigationGroup = "kyc"

//EmployeeGroup groups all actions under the employees resource
EmployeeGroup NavigationGroup = "employees"

//CoversGroup groups all actions under the covers resource
CoversGroup NavigationGroup = "covers"

//PatientGroup groups all actions under the patient resource
PatientGroup NavigationGroup = "patient"

Expand All @@ -111,6 +93,7 @@ const (
RoleNavActionSequence
RoleCreationNavActionSequence
RoleViewingNavActionSequence
RoleAssignNavActionSequence

RequestsNavActionSequence

Expand Down Expand Up @@ -217,37 +200,15 @@ var (
HasParent: true,
SequenceNumber: RoleViewingNavActionSequence,
}
)

var (
//EmployeeNavActions this is the parent navigation action for agent resource
// it has nested navigation actions below
EmployeeNavActions = NavigationAction{
Group: EmployeeGroup,
Title: EmployeeNavActionTitle,
Icon: EmployeeNavActionIcon,
RequiredPermission: &profileutils.CanViewEmployee,
SequenceNumber: EmployeeNavActionSequence,
}

//EmployeeRegistrationNavAction a child of the EmployeeNavActions
EmployeeRegistrationNavAction = NavigationAction{
Group: EmployeeGroup,
Title: EmployeeRegistrationActionTitle,
OnTapRoute: EmployeeRegistrationRoute,
RequiredPermission: &profileutils.CanCreateEmployee,
HasParent: true,
SequenceNumber: EmployeeRegistrationActionSequence,
}

//EmployeeidentificationNavAction a child of the EmployeeNavActions
EmployeeidentificationNavAction = NavigationAction{
Group: EmployeeGroup,
Title: EmployeeIdentificationActionTitle,
OnTapRoute: EmployeeIdentificationRoute,
RequiredPermission: &profileutils.CanViewEmployee,
//RoleAssignNavAction a child of the RoleNavActions
RoleAssignNavAction = NavigationAction{
Group: RoleGroup,
Title: RoleAssignActionTitle,
OnTapRoute: RoleAssignmentRoute,
RequiredPermission: &profileutils.CanAssignRole,
HasParent: true,
SequenceNumber: EmployeeSearchNavActionSequence,
SequenceNumber: RoleAssignNavActionSequence,
}
)

Expand Down Expand Up @@ -289,8 +250,6 @@ var AllNavigationActions = []NavigationAction{

KYCNavActions, PartnerNavActions, ConsumerNavActions,

EmployeeNavActions, EmployeeRegistrationNavAction, EmployeeidentificationNavAction,

PatientNavActions, PatientRegistrationNavAction, PatientIdentificationNavAction,

RoleNavActions, RoleCreationNavAction, RoleViewNavAction,
Expand Down
4 changes: 2 additions & 2 deletions pkg/onboarding/usecases/login_unit_test.go
Expand Up @@ -336,7 +336,7 @@ func TestProfileUseCaseImpl_LoginByPhone(t *testing.T) {
CustomToken: &customToken,
IDToken: &idToken,
RefreshToken: refreshToken,
Scopes: []string{"patient.create", "agent.create"},
Scopes: []string{"patient.create"},
}, nil
}

Expand All @@ -359,7 +359,7 @@ func TestProfileUseCaseImpl_LoginByPhone(t *testing.T) {
},
{
ID: uuid.NewString(),
Scopes: []string{"patient.create", "agent.create"},
Scopes: []string{"patient.create"},
Active: true,
},
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/onboarding/usecases/profile_unit_test.go
Expand Up @@ -4075,9 +4075,7 @@ func TestProfileUseCaseImpl_GetNavigationActions(t *testing.T) {
return &profileutils.UserProfile{}, nil
}
fakeRepo.GetRolesByIDsFn = func(ctx context.Context, roleIDs []string) (*[]profileutils.Role, error) {
return &[]profileutils.Role{
{Scopes: []string{"agent.view", "agent.register"}, Active: true},
}, nil
return &[]profileutils.Role{}, nil
}
}
got, err := i.Onboarding.GetNavigationActions(tt.args.ctx)
Expand Down
2 changes: 1 addition & 1 deletion pkg/onboarding/usecases/roles_unit_test.go
Expand Up @@ -1008,7 +1008,7 @@ func TestRoleUseCaseImpl_RevokeRolePermissions(t *testing.T) {
ctx: ctx,
inputData: dto.RolePermissionInput{
RoleID: "123",
Scopes: []string{"agent.create"},
Scopes: []string{"role.create"},
},
}

Expand Down

0 comments on commit cf334fd

Please sign in to comment.