Skip to content

Commit

Permalink
chore:remove ussd
Browse files Browse the repository at this point in the history
  • Loading branch information
victorine.osewe authored and VicOsewe committed Aug 25, 2021
1 parent 7fe370e commit 8d65495
Show file tree
Hide file tree
Showing 41 changed files with 7 additions and 5,959 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -14,5 +14,4 @@ coverage.html
coverage.json
coverage_report.txt
install-misspell.sh
.vscode/
/pkg/onboarding/usecases/ussd/profile_integration_test.go
.vscode/
12 changes: 2 additions & 10 deletions pkg/onboarding/application/dto/input.go
Expand Up @@ -335,15 +335,6 @@ type SupplierPubSubMessagePayload struct {
UID string `json:"uid"`
}

// USSDEvent records any USSD event(e.g. entering firstname, lastname etc.) that happens for every session and the time
type USSDEvent struct {
SessionID string `firestore:"sessionID"`
PhoneNumber string `firestore:"phoneNumber"`
USSDEventDateTime *time.Time `firestore:"ussdEventDateTime"`
Level int `firestore:"level"`
USSDEventName string `firestore:"ussdEventName"`
}

// AssignRolePayload is the payload used to assign a role to a user
type AssignRolePayload struct {
UserID string `json:"userID"`
Expand All @@ -352,7 +343,8 @@ type AssignRolePayload struct {

// DeleteRolePayload is the payload used to delete a role
type DeleteRolePayload struct {
Name string `json:"name"`
Name string `json:"name"`

RoleID string `json:"roleID"`
}

Expand Down
9 changes: 0 additions & 9 deletions pkg/onboarding/application/dto/ussd.go

This file was deleted.

9 changes: 0 additions & 9 deletions pkg/onboarding/application/exceptions/custom_errors.go
Expand Up @@ -440,15 +440,6 @@ func RecordDoesNotExistError(err error) error {
}
}

// SessionIDError return an error when a ussd sessionId is not provided
func SessionIDError(err error) error {
return &errorcodeutil.CustomError{
Err: err,
Message: SessionIDErrMsg,
Code: int(errorcodeutil.Internal),
}
}

// RoleNotValid return an error when a user does not have the required role
func RoleNotValid(err error) error {
return &errorcodeutil.CustomError{
Expand Down
4 changes: 0 additions & 4 deletions pkg/onboarding/application/exceptions/error_messages.go
Expand Up @@ -163,10 +163,6 @@ const (
// the database
RecordDoesNotExistErrMsg = "the record cannot be found in the database"

//SessionIDErrMsg is an error message displayed when a sessionId is not provided in
// in the USSD details
SessionIDErrMsg = "sessionID not provided"

//RoleNotValidMsg is an error message displayed when the provided role is not valid
// and the user doesn't have permissions to perform an action
RoleNotValidMsg = "user role is not valid"
Expand Down
10 changes: 0 additions & 10 deletions pkg/onboarding/application/utils/helpers.go
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"regexp"
"strconv"

"github.com/savannahghi/converterandformatter"
"github.com/savannahghi/feedlib"
Expand Down Expand Up @@ -131,15 +130,6 @@ func FindItem(slice []string, value string) (int, bool) {
return -1, false
}

// ParseUSSDDateInput ...
func ParseUSSDDateInput(date string) string {
dayEntered, _ := strconv.Atoi(date[0:2])
monthEntered, _ := strconv.Atoi(date[2:4])
yearEntered, _ := strconv.Atoi(date[4:8])

return fmt.Sprintf("%v-%v-%v", dayEntered, monthEntered, yearEntered)
}

// UniquePermissionsArray removes duplicate permissions in an array of permissions
func UniquePermissionsArray(arr []profileutils.PermissionType) []profileutils.PermissionType {
occurred := map[profileutils.PermissionType]bool{}
Expand Down
55 changes: 0 additions & 55 deletions pkg/onboarding/application/utils/validators.go
Expand Up @@ -112,52 +112,6 @@ func ValidateAficasTalkingSMSData(input *dto.AfricasTalkingMessage) (*dto.Africa
}, nil
}

//ValidateUSSDEvent validates a USSD event
func ValidateUSSDEvent(input *dto.USSDEvent) (*dto.USSDEvent, error) {
if input.SessionID == "" {
return nil, fmt.Errorf("ussd event's session id cannot be empty")
}

if input.PhoneNumber == "" {
return nil, fmt.Errorf("ussd event's phone number cannot be empty")
}

if input.USSDEventDateTime == nil {
return nil, fmt.Errorf("ussd event's date and time cannot be empty")
}

if input.USSDEventName == "" {
return nil, fmt.Errorf("ussd event's name cannot be empty")
}

return &dto.USSDEvent{
SessionID: input.SessionID,
PhoneNumber: input.PhoneNumber,
USSDEventDateTime: input.USSDEventDateTime,
Level: input.Level,
USSDEventName: input.USSDEventName,
}, nil
}

//ValidateUSSDDetails checks if the phonenumber supplied is valid , that a session ID is provided
// and returns valid USSD session details.
func ValidateUSSDDetails(payload *dto.SessionDetails) (*dto.SessionDetails, error) {
phone, err := converterandformatter.NormalizeMSISDN(*payload.PhoneNumber)
if err != nil {
return nil, exceptions.NormalizeMSISDNError(err)
}
if payload.SessionID == "" {
err := fmt.Errorf("expected sessionid to be defined")
return nil, exceptions.SessionIDError(err)
}
return &dto.SessionDetails{
PhoneNumber: phone,
SessionID: payload.SessionID,
Level: payload.Level,
Text: payload.Text,
}, nil
}

// ValidatePIN ...
func ValidatePIN(pin string) error {
validatePINErr := ValidatePINLength(pin)
Expand All @@ -181,15 +135,6 @@ func ValidatePINLength(pin string) error {
return nil
}

// ValidateUSSDInput ...
func ValidateUSSDInput(text string) error {
if text == "" {
return fmt.Errorf("invalid input")
}

return nil
}

// IsLetter ...
func IsLetter(s string) bool {
for _, r := range s {
Expand Down
80 changes: 0 additions & 80 deletions pkg/onboarding/application/utils/validators_test.go
Expand Up @@ -269,83 +269,3 @@ func TestValidateSMSData(t *testing.T) {
})
}
}

func TestValidateUSSDDetails(t *testing.T) {
phone := "+254711223344"
sessionId := "1235678"
text := ""

alphanumericPhone := "+254-not-valid-123"
emptySessionId := ""
badPhone := "+254712"

type args struct {
input *dto.SessionDetails
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "success: return a valid output",
args: args{
input: &dto.SessionDetails{
PhoneNumber: &phone,
SessionID: sessionId,
Text: text,
},
},
wantErr: false,
},
{
name: "failure: bad phone number provided",
args: args{
input: &dto.SessionDetails{
PhoneNumber: &badPhone,
SessionID: sessionId,
Text: text,
},
},
wantErr: true,
},
{
name: "failure: alphanumeric phone number provided",
args: args{
input: &dto.SessionDetails{
PhoneNumber: &alphanumericPhone,
SessionID: sessionId,
Text: text,
},
},
wantErr: true,
},
{
name: "failure: empty Ussd SessionId",
args: args{
input: &dto.SessionDetails{
PhoneNumber: &phone,
SessionID: emptySessionId,
Text: text,
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
validInput, err := utils.ValidateUSSDDetails(tt.args.input)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateUSSDDetails() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err != nil && validInput != nil {
t.Errorf("expected a nil valid input since an error :%v occurred", err)
}

if err == nil && validInput == nil {
t.Errorf("expected a valid input %v since no error occurred", validInput)
}
})
}
}
4 changes: 1 addition & 3 deletions pkg/onboarding/domain/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions pkg/onboarding/domain/models.go
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/savannahghi/enumutils"
"github.com/savannahghi/firebasetools"
"github.com/savannahghi/profileutils"
"github.com/savannahghi/scalarutils"
)

// Branch represents a Slade 360 Charge Master branch
Expand Down Expand Up @@ -101,21 +100,6 @@ type NHIFDetails struct {
NHIFCardPhotoID string `json:"nhifCardPhotoID" firestore:"nhifCardPhotoID"`
}

//USSDLeadDetails represents ussd user session details
type USSDLeadDetails struct {
ID string `json:"id" firestore:"id"`
Level int `json:"level" firestore:"level"`
PhoneNumber string `json:"phoneNumber" firestore:"phoneNumber"`
SessionID string `json:"sessionID" firestore:"sessionID"`
FirstName string `json:"firstName" firestore:"firstName"`
LastName string `json:"lastName" firestore:"lastName"`
DateOfBirth scalarutils.Date `json:"dob" firestore:"dob"`
IsRegistered bool `json:"isRegistered" firestore:"isRegistered"`
ContactChannel string `json:"contactChannel" firestore:"contactChannel"`
WantCover bool `json:"wantCover" firestore:"wantCover"`
PIN string `json:"pin" firestore:"pin"`
}

// CRMContact represents a stored CRM contact
type CRMContact struct {
FirstName string `json:"first_name,omitempty"`
Expand Down

0 comments on commit 8d65495

Please sign in to comment.