diff --git a/pkg/onboarding/application/dto/output.go b/pkg/onboarding/application/dto/output.go index dbe6c685..cfe3e24c 100644 --- a/pkg/onboarding/application/dto/output.go +++ b/pkg/onboarding/application/dto/output.go @@ -161,11 +161,3 @@ type GroupedNavigationActions struct { Primary []domain.NavigationAction `json:"primary,omitempty"` Secondary []domain.NavigationAction `json:"secondary,omitempty"` } - -// TemporaryPIN used to carry information about temporary pin -type TemporaryPIN struct { - PhoneNumber string `json:"phoneNumber,omitempty"` - FirstName string `json:"firstName,omitempty"` - PIN string `json:"pin,omitempty"` - Channel int `json:"channel,omitempty"` -} diff --git a/pkg/onboarding/domain/enum.go b/pkg/onboarding/domain/enum.go index 5a12e672..080452da 100644 --- a/pkg/onboarding/domain/enum.go +++ b/pkg/onboarding/domain/enum.go @@ -405,58 +405,3 @@ func (e *AgentType) UnmarshalGQL(v interface{}) error { func (e AgentType) MarshalGQL(w io.Writer) { fmt.Fprint(w, strconv.Quote(e.String())) } - -// Channel can be SMS, Whatsapp, Email etc -type Channel string - -//Possible valid channels -const ( - WhatsAppChannel Channel = "WhatsApp" - SMSChannel Channel = "SMS" - EmailChannel Channel = "Email" -) - -//IsValid ... -func (c Channel) IsValid() bool { - switch c { - case WhatsAppChannel, SMSChannel, EmailChannel: - return true - } - return false -} - -//String ... -func (c Channel) String() string { - return string(c) -} - -//Int ... -func (c Channel) Int() int { - switch c { - case WhatsAppChannel: - return 1 - case SMSChannel: - return 2 - case EmailChannel: - return 3 - } - return 0 -} - -// UnmarshalGQL .. -func (c *Channel) UnmarshalGQL(v interface{}) error { - str, ok := v.(string) - if !ok { - return fmt.Errorf("enums must be strings") - } - *c = Channel(str) - if !c.IsValid() { - return fmt.Errorf("%s is not a valid Channel", str) - } - return nil -} - -// MarshalGQL .. -func (c Channel) MarshalGQL(w io.Writer) { - fmt.Fprint(w, strconv.Quote(c.String())) -} diff --git a/pkg/onboarding/domain/enum_test.go b/pkg/onboarding/domain/enum_test.go index 575485aa..f371c9be 100644 --- a/pkg/onboarding/domain/enum_test.go +++ b/pkg/onboarding/domain/enum_test.go @@ -749,165 +749,3 @@ func TestAgentType_MarshalGQL(t *testing.T) { }) } } - -func TestChannel_IsValid(t *testing.T) { - tests := []struct { - name string - c domain.Channel - want bool - }{ - { - name: "valid", - c: domain.WhatsAppChannel, - want: true, - }, - { - name: "invalid", - c: domain.Channel("this is not real"), - want: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := tt.c.IsValid(); got != tt.want { - t.Errorf("Channel.IsValid() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestChannel_String(t *testing.T) { - tests := []struct { - name string - c domain.Channel - want string - }{ - { - name: "whatsapp", - c: domain.WhatsAppChannel, - want: "WhatsApp", - }, - { - name: "sms", - c: domain.SMSChannel, - want: "SMS", - }, - { - name: "email", - c: domain.EmailChannel, - want: "Email", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := tt.c.String(); got != tt.want { - t.Errorf("Channel.String() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestChannel_Int(t *testing.T) { - tests := []struct { - name string - c domain.Channel - want int - }{ - { - name: "whatsapp", - c: domain.WhatsAppChannel, - want: 1, - }, - { - name: "sms", - c: domain.SMSChannel, - want: 2, - }, - { - name: "email", - c: domain.EmailChannel, - want: 3, - }, - { - name: "test", - c: domain.Channel("test"), - want: 0, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := tt.c.Int(); got != tt.want { - t.Errorf("Channel.Int() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestChannel_UnmarshalGQL(t *testing.T) { - valid := domain.WhatsAppChannel - invalid := domain.Channel("test") - type args struct { - v interface{} - } - tests := []struct { - name string - c *domain.Channel - args args - wantErr bool - }{ - { - name: "valid", - c: &valid, - args: args{ - v: "WhatsApp", - }, - wantErr: false, - }, - { - name: "invalid", - c: &invalid, - args: args{ - v: "test", - }, - wantErr: true, - }, - { - name: "non string", - c: &invalid, - args: args{ - v: 1, - }, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := tt.c.UnmarshalGQL(tt.args.v); (err != nil) != tt.wantErr { - t.Errorf("Channel.UnmarshalGQL() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestChannel_MarshalGQL(t *testing.T) { - tests := []struct { - name string - c domain.Channel - wantW string - }{ - { - name: "valid", - c: domain.WhatsAppChannel, - wantW: strconv.Quote("WhatsApp"), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - w := &bytes.Buffer{} - tt.c.MarshalGQL(w) - if gotW := w.String(); gotW != tt.wantW { - t.Errorf("Channel.MarshalGQL() = %v, want %v", gotW, tt.wantW) - } - }) - } -} diff --git a/pkg/onboarding/infrastructure/services/engagement/mock/service_mock.go b/pkg/onboarding/infrastructure/services/engagement/mock/service_mock.go index d8f9e8e5..ce5d4a8d 100644 --- a/pkg/onboarding/infrastructure/services/engagement/mock/service_mock.go +++ b/pkg/onboarding/infrastructure/services/engagement/mock/service_mock.go @@ -35,8 +35,7 @@ type FakeServiceEngagement struct { VerifyEmailOTPFn func(ctx context.Context, email, OTP string) (bool, error) - SendSMSFn func(ctx context.Context, phoneNumbers []string, message string) error - SendTemporaryPINFn func(ctx context.Context, payload dto.TemporaryPIN) error + SendSMSFn func(ctx context.Context, phoneNumbers []string, message string) error } // PublishKYCNudge ... @@ -130,8 +129,3 @@ func (f *FakeServiceEngagement) NotifySupplierOnSuspension(ctx context.Context, func (f *FakeServiceEngagement) SendSMS(ctx context.Context, phoneNumbers []string, message string) error { return f.SendSMSFn(ctx, phoneNumbers, message) } - -// SendTemporaryPIN ... -func (f *FakeServiceEngagement) SendTemporaryPIN(ctx context.Context, payload dto.TemporaryPIN) error { - return f.SendTemporaryPINFn(ctx, payload) -} diff --git a/pkg/onboarding/infrastructure/services/engagement/service.go b/pkg/onboarding/infrastructure/services/engagement/service.go index 8a6dc3d4..aa444393 100644 --- a/pkg/onboarding/infrastructure/services/engagement/service.go +++ b/pkg/onboarding/infrastructure/services/engagement/service.go @@ -39,8 +39,6 @@ const ( VerifyOTPEndPoint = "internal/verify_otp/" sendSMS = "internal/send_sms" - - temporaryPIN = "internal/send_temporary_pin" ) // ServiceEngagement represents engagement usecases @@ -95,8 +93,6 @@ type ServiceEngagement interface { VerifyEmailOTP(ctx context.Context, email, OTP string) (bool, error) SendSMS(ctx context.Context, phoneNumbers []string, message string) error - - SendTemporaryPIN(ctx context.Context, payload dto.TemporaryPIN) error } // ServiceEngagementImpl represents engagement usecases @@ -508,16 +504,3 @@ func (en *ServiceEngagementImpl) SendSMS(ctx context.Context, phoneNumbers []str return nil } - -// SendTemporaryPIN sends an already generated PIN to user -func (en *ServiceEngagementImpl) SendTemporaryPIN(ctx context.Context, payload dto.TemporaryPIN) error { - resp, err := en.Engage.MakeRequest(ctx, http.MethodPost, temporaryPIN, payload) - if err != nil { - return fmt.Errorf("unable to send pin: %v", err) - } - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("unable to send pin, with status code %v", resp.StatusCode) - } - - return nil -} diff --git a/pkg/onboarding/infrastructure/services/engagement/service_unit_test.go b/pkg/onboarding/infrastructure/services/engagement/service_unit_test.go index a7960c74..f1c21480 100644 --- a/pkg/onboarding/infrastructure/services/engagement/service_unit_test.go +++ b/pkg/onboarding/infrastructure/services/engagement/service_unit_test.go @@ -1377,65 +1377,3 @@ func TestServiceEngagementImpl_NotifyAdmins(t *testing.T) { }) } } - -func TestServiceEngagementImpl_SendTemporaryPIN(t *testing.T) { - e := engagement.NewServiceEngagementImpl(engClient, baseExt) - payload := dto.TemporaryPIN{ - PhoneNumber: interserviceclient.TestUserPhoneNumber, - } - - type args struct { - ctx context.Context - payload dto.TemporaryPIN - } - tests := []struct { - name string - args args - wantErr bool - }{ - { - name: "sad: unable to send temporary pin", - args: args{ctx: context.Background(), - payload: payload, - }, - wantErr: true, - }, - { - name: "sad: send pin failed with status code", - args: args{ctx: context.Background(), - payload: payload, - }, - wantErr: true, - }, - { - name: "happy: sent temporary pin", - args: args{ctx: context.Background(), - payload: payload, - }, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.name == "sad: unable to send temporary pin" { - fakeISCExt.MakeRequestFn = func(ctx context.Context, method, path string, body interface{}) (*http.Response, error) { - return nil, fmt.Errorf("error request failed") - } - } - if tt.name == "sad: send pin failed with status code" { - fakeISCExt.MakeRequestFn = func(ctx context.Context, method, path string, body interface{}) (*http.Response, error) { - return &http.Response{StatusCode: http.StatusBadRequest}, nil - } - } - - if tt.name == "happy: sent temporary pin" { - fakeISCExt.MakeRequestFn = func(ctx context.Context, method, path string, body interface{}) (*http.Response, error) { - return &http.Response{StatusCode: http.StatusOK}, nil - } - } - if err := e.SendTemporaryPIN(tt.args.ctx, tt.args.payload); (err != nil) != tt.wantErr { - t.Errorf("ServiceEngagementImpl.SendTemporaryPIN() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} diff --git a/pkg/onboarding/presentation/graph/enums.graphql b/pkg/onboarding/presentation/graph/enums.graphql index 52939bb6..3f2bc36e 100644 --- a/pkg/onboarding/presentation/graph/enums.graphql +++ b/pkg/onboarding/presentation/graph/enums.graphql @@ -174,9 +174,3 @@ enum PermissionGroup { Consumers Patients } - -enum Channel { - WhatsApp - SMS - Email -} diff --git a/pkg/onboarding/presentation/graph/generated/generated.go b/pkg/onboarding/presentation/graph/generated/generated.go index 9ebe190d..900bbcc3 100644 --- a/pkg/onboarding/presentation/graph/generated/generated.go +++ b/pkg/onboarding/presentation/graph/generated/generated.go @@ -298,7 +298,6 @@ type ComplexityRoot struct { RegisterAgent func(childComplexity int, input dto.RegisterAgentInput) int RegisterMicroservice func(childComplexity int, input domain.Microservice) int RegisterPushToken func(childComplexity int, token string) int - ResendTemporaryPin func(childComplexity int, profileID string, channel domain.Channel) int RetireKYCProcessingRequest func(childComplexity int) int RetireSecondaryEmailAddresses func(childComplexity int, emails []string) int RetireSecondaryPhoneNumbers func(childComplexity int, phones []string) int @@ -657,7 +656,6 @@ type MutationResolver interface { RevokeRole(ctx context.Context, userID string, roleID string, reason string) (bool, error) ActivateRole(ctx context.Context, roleID string) (*dto.RoleOutput, error) DeactivateRole(ctx context.Context, roleID string) (*dto.RoleOutput, error) - ResendTemporaryPin(ctx context.Context, profileID string, channel domain.Channel) (bool, error) } type QueryResolver interface { DummyQuery(ctx context.Context) (*bool, error) @@ -2063,18 +2061,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.RegisterPushToken(childComplexity, args["token"].(string)), true - case "Mutation.ResendTemporaryPIN": - if e.complexity.Mutation.ResendTemporaryPin == nil { - break - } - - args, err := ec.field_Mutation_ResendTemporaryPIN_args(context.TODO(), rawArgs) - if err != nil { - return 0, false - } - - return e.complexity.Mutation.ResendTemporaryPin(childComplexity, args["profileID"].(string), args["channel"].(domain.Channel)), true - case "Mutation.retireKYCProcessingRequest": if e.complexity.Mutation.RetireKYCProcessingRequest == nil { break @@ -3931,12 +3917,6 @@ enum PermissionGroup { Consumers Patients } - -enum Channel { - WhatsApp - SMS - Email -} `, BuiltIn: false}, {Name: "pkg/onboarding/presentation/graph/external.graphql", Input: `# supported content types enum ContentType { @@ -4590,8 +4570,6 @@ extend type Mutation { activateRole(roleID: ID!): RoleOutput! deactivateRole(roleID: ID!): RoleOutput! - - ResendTemporaryPIN(profileID: ID!, channel: Channel!): Boolean! } `, BuiltIn: false}, {Name: "pkg/onboarding/presentation/graph/types.graphql", Input: `scalar Date @@ -5201,30 +5179,6 @@ func (ec *executionContext) field_Entity_findUserProfileByID_args(ctx context.Co return args, nil } -func (ec *executionContext) field_Mutation_ResendTemporaryPIN_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { - var err error - args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["profileID"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("profileID")) - arg0, err = ec.unmarshalNID2string(ctx, tmp) - if err != nil { - return nil, err - } - } - args["profileID"] = arg0 - var arg1 domain.Channel - if tmp, ok := rawArgs["channel"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("channel")) - arg1, err = ec.unmarshalNChannel2githubᚗcomᚋsavannahghiᚋonboardingᚋpkgᚋonboardingᚋdomainᚐChannel(ctx, tmp) - if err != nil { - return nil, err - } - } - args["channel"] = arg1 - return args, nil -} - func (ec *executionContext) field_Mutation_activateAgent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -13022,48 +12976,6 @@ func (ec *executionContext) _Mutation_deactivateRole(ctx context.Context, field return ec.marshalNRoleOutput2ᚖgithubᚗcomᚋsavannahghiᚋonboardingᚋpkgᚋonboardingᚋapplicationᚋdtoᚐRoleOutput(ctx, field.Selections, res) } -func (ec *executionContext) _Mutation_ResendTemporaryPIN(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - fc := &graphql.FieldContext{ - Object: "Mutation", - Field: field, - Args: nil, - IsMethod: true, - IsResolver: true, - } - - ctx = graphql.WithFieldContext(ctx, fc) - rawArgs := field.ArgumentMap(ec.Variables) - args, err := ec.field_Mutation_ResendTemporaryPIN_args(ctx, rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - fc.Args = args - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().ResendTemporaryPin(rctx, args["profileID"].(string), args["channel"].(domain.Channel)) - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(bool) - fc.Result = res - return ec.marshalNBoolean2bool(ctx, field.Selections, res) -} - func (ec *executionContext) _NHIFDetails_id(ctx context.Context, field graphql.CollectedField, obj *domain.NHIFDetails) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -24160,11 +24072,6 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { invalids++ } - case "ResendTemporaryPIN": - out.Values[i] = ec._Mutation_ResendTemporaryPIN(ctx, field) - if out.Values[i] == graphql.Null { - invalids++ - } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -26109,16 +26016,6 @@ func (ec *executionContext) marshalNBusinessPartnerConnection2ᚖgithubᚗcomᚋ return ec._BusinessPartnerConnection(ctx, sel, v) } -func (ec *executionContext) unmarshalNChannel2githubᚗcomᚋsavannahghiᚋonboardingᚋpkgᚋonboardingᚋdomainᚐChannel(ctx context.Context, v interface{}) (domain.Channel, error) { - var res domain.Channel - err := res.UnmarshalGQL(v) - return res, graphql.ErrorOnPath(ctx, err) -} - -func (ec *executionContext) marshalNChannel2githubᚗcomᚋsavannahghiᚋonboardingᚋpkgᚋonboardingᚋdomainᚐChannel(ctx context.Context, sel ast.SelectionSet, v domain.Channel) graphql.Marshaler { - return v -} - func (ec *executionContext) unmarshalNDate2githubᚗcomᚋsavannahghiᚋscalarutilsᚐDate(ctx context.Context, v interface{}) (scalarutils.Date, error) { var res scalarutils.Date err := res.UnmarshalGQL(v) diff --git a/pkg/onboarding/presentation/graph/profile.graphql b/pkg/onboarding/presentation/graph/profile.graphql index 8c9bf6c9..70bf64b2 100644 --- a/pkg/onboarding/presentation/graph/profile.graphql +++ b/pkg/onboarding/presentation/graph/profile.graphql @@ -190,6 +190,4 @@ extend type Mutation { activateRole(roleID: ID!): RoleOutput! deactivateRole(roleID: ID!): RoleOutput! - - ResendTemporaryPIN(profileID: ID!, channel: Channel!): Boolean! } diff --git a/pkg/onboarding/presentation/graph/profile.resolvers.go b/pkg/onboarding/presentation/graph/profile.resolvers.go index a1d9272e..143a81a7 100644 --- a/pkg/onboarding/presentation/graph/profile.resolvers.go +++ b/pkg/onboarding/presentation/graph/profile.resolvers.go @@ -690,15 +690,6 @@ func (r *mutationResolver) DeactivateRole(ctx context.Context, roleID string) (* return role, err } -func (r *mutationResolver) ResendTemporaryPin(ctx context.Context, profileID string, channel domain.Channel) (bool, error) { - startTime := time.Now() - - success, err := r.interactor.UserPIN.ResendTemporaryPIN(ctx, profileID, channel) - defer serverutils.RecordGraphqlResolverMetrics(ctx, startTime, "resendTemporaryPin", err) - - return success, err -} - func (r *queryResolver) DummyQuery(ctx context.Context) (*bool, error) { dummy := true return &dummy, nil diff --git a/pkg/onboarding/usecases/user_pin.go b/pkg/onboarding/usecases/user_pin.go index f7989018..11755800 100644 --- a/pkg/onboarding/usecases/user_pin.go +++ b/pkg/onboarding/usecases/user_pin.go @@ -6,7 +6,6 @@ import ( "github.com/google/uuid" "github.com/savannahghi/errorcodeutil" - "github.com/savannahghi/onboarding/pkg/onboarding/application/dto" "github.com/savannahghi/onboarding/pkg/onboarding/application/exceptions" "github.com/savannahghi/onboarding/pkg/onboarding/application/extension" "github.com/savannahghi/onboarding/pkg/onboarding/application/utils" @@ -30,7 +29,6 @@ type UserPINUseCases interface { ChangeUserPIN(ctx context.Context, phone string, pin string) (bool, error) RequestPINReset(ctx context.Context, phone string, appID *string) (*profileutils.OtpResponse, error) CheckHasPIN(ctx context.Context, profileID string) (bool, error) - ResendTemporaryPIN(ctx context.Context, profileID string, channel domain.Channel) (bool, error) } // UserPinUseCaseImpl represents usecase implementation object @@ -289,37 +287,3 @@ func (u *UserPinUseCaseImpl) SetUserTempPIN(ctx context.Context, profileID strin return pin, nil } - -// ResendTemporaryPIN send a new temporary PIN for users who may have -// forgotten their PIN -func (u *UserPinUseCaseImpl) ResendTemporaryPIN(ctx context.Context, profileID string, channel domain.Channel) (bool, error) { - ctx, span := tracer.Start(ctx, "ResendTemporaryPIN") - defer span.End() - - profile, err := u.onboardingRepository.GetUserProfileByID(ctx, profileID, false) - if err != nil { - utils.RecordSpanError(span, err) - return false, exceptions.GeneratePinError(err) - } - - pin, err := u.SetUserTempPIN(ctx, profile.ID) - if err != nil { - utils.RecordSpanError(span, err) - return false, exceptions.GeneratePinError(err) - } - - output := dto.TemporaryPIN{ - PhoneNumber: *profile.PrimaryPhone, - FirstName: *profile.UserBioData.FirstName, - PIN: pin, - Channel: channel.Int(), - } - - err = u.engagement.SendTemporaryPIN(ctx, output) - if err != nil { - utils.RecordSpanError(span, err) - return false, exceptions.GeneratePinError(err) - } - return true, nil - -} diff --git a/pkg/onboarding/usecases/user_pin_test.go b/pkg/onboarding/usecases/user_pin_test.go index 23ec7ee8..05809b46 100644 --- a/pkg/onboarding/usecases/user_pin_test.go +++ b/pkg/onboarding/usecases/user_pin_test.go @@ -7,7 +7,6 @@ import ( "github.com/google/uuid" "github.com/savannahghi/interserviceclient" - "github.com/savannahghi/onboarding/pkg/onboarding/application/dto" "github.com/savannahghi/onboarding/pkg/onboarding/application/extension" "github.com/savannahghi/onboarding/pkg/onboarding/domain" "github.com/savannahghi/profileutils" @@ -897,159 +896,3 @@ func TestUserPinUseCaseImpl_SetUserTempPIN(t *testing.T) { }) } } - -func TestUserPinUseCaseImpl_ResendTemporaryPIN(t *testing.T) { - ctx := context.Background() - i, err := InitializeFakeOnboardingInteractor() - if err != nil { - t.Errorf("failed to fake initialize onboarding interactor: %v", - err, - ) - return - } - - id := uuid.New().String() - phone := interserviceclient.TestUserPhoneNumber - fName := "Test" - validProfile := profileutils.UserProfile{ - ID: id, PrimaryPhone: &phone, - UserBioData: profileutils.BioData{ - FirstName: &fName, - }, - } - type args struct { - ctx context.Context - profileID string - channel domain.Channel - } - tests := []struct { - name string - args args - want bool - wantErr bool - }{ - { - name: "sad: unable to get user profile", - args: args{ - ctx: ctx, - profileID: id, - channel: domain.WhatsAppChannel, - }, - want: false, - wantErr: true, - }, - { - name: "sad: unable to generate temp pin", - args: args{ - ctx: ctx, - profileID: id, - channel: domain.WhatsAppChannel, - }, - want: false, - wantErr: true, - }, - { - name: "sad: unable to save pin", - args: args{ - ctx: ctx, - profileID: id, - channel: domain.WhatsAppChannel, - }, - want: false, - wantErr: true, - }, - { - name: "sad: unable to send pin", - args: args{ - ctx: ctx, - profileID: id, - channel: domain.WhatsAppChannel, - }, - want: false, - wantErr: true, - }, - { - name: "happy: sent temporary pin", - args: args{ - ctx: ctx, - profileID: id, - channel: domain.WhatsAppChannel, - }, - want: true, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.name == "sad: unable to get user profile" { - fakeRepo.GetUserProfileByIDFn = func(ctx context.Context, id string, suspended bool) (*profileutils.UserProfile, error) { - return nil, fmt.Errorf("error unable to get user profile") - } - } - if tt.name == "sad: unable to generate temp pin" { - fakeRepo.GetUserProfileByIDFn = func(ctx context.Context, id string, suspended bool) (*profileutils.UserProfile, error) { - return &validProfile, nil - } - fakePinExt.GenerateTempPINFn = func(ctx context.Context) (string, error) { - return "", fmt.Errorf("unable to generate pin") - } - } - if tt.name == "sad: unable to save pin" { - fakeRepo.GetUserProfileByIDFn = func(ctx context.Context, id string, suspended bool) (*profileutils.UserProfile, error) { - return &validProfile, nil - } - fakePinExt.GenerateTempPINFn = func(ctx context.Context) (string, error) { - return "1234", nil - } - fakePinExt.EncryptPINFn = func(rawPwd string, options *extension.Options) (string, string) { - return "1234", "sha" - } - fakeRepo.SavePINFn = func(ctx context.Context, pin *domain.PIN) (bool, error) { - return false, fmt.Errorf("unable to save pin") - } - } - if tt.name == "sad: unable to send pin" { - fakeRepo.GetUserProfileByIDFn = func(ctx context.Context, id string, suspended bool) (*profileutils.UserProfile, error) { - return &validProfile, nil - } - fakePinExt.GenerateTempPINFn = func(ctx context.Context) (string, error) { - return "1234", nil - } - fakePinExt.EncryptPINFn = func(rawPwd string, options *extension.Options) (string, string) { - return "1234", "sha" - } - fakeRepo.SavePINFn = func(ctx context.Context, pin *domain.PIN) (bool, error) { - return true, nil - } - fakeEngagementSvs.SendTemporaryPINFn = func(ctx context.Context, payload dto.TemporaryPIN) error { - return fmt.Errorf("unable to send pin") - } - } - if tt.name == "happy: sent temporary pin" { - fakeRepo.GetUserProfileByIDFn = func(ctx context.Context, id string, suspended bool) (*profileutils.UserProfile, error) { - return &validProfile, nil - } - fakePinExt.GenerateTempPINFn = func(ctx context.Context) (string, error) { - return "1234", nil - } - fakePinExt.EncryptPINFn = func(rawPwd string, options *extension.Options) (string, string) { - return "1234", "sha" - } - fakeRepo.SavePINFn = func(ctx context.Context, pin *domain.PIN) (bool, error) { - return true, nil - } - fakeEngagementSvs.SendTemporaryPINFn = func(ctx context.Context, payload dto.TemporaryPIN) error { - return nil - } - } - got, err := i.UserPIN.ResendTemporaryPIN(tt.args.ctx, tt.args.profileID, tt.args.channel) - if (err != nil) != tt.wantErr { - t.Errorf("UserPinUseCaseImpl.ResendTemporaryPIN() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("UserPinUseCaseImpl.ResendTemporaryPIN() = %v, want %v", got, tt.want) - } - }) - } -}