Skip to content

Commit

Permalink
Revert "feat: add sending temporary pin to users on demand (#54)"
Browse files Browse the repository at this point in the history
This reverts commit 1ff99b7.
  • Loading branch information
NYARAS committed Aug 23, 2021
1 parent 1ff99b7 commit bc29793
Show file tree
Hide file tree
Showing 12 changed files with 1 addition and 624 deletions.
8 changes: 0 additions & 8 deletions pkg/onboarding/application/dto/output.go
Expand Up @@ -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"`
}
55 changes: 0 additions & 55 deletions pkg/onboarding/domain/enum.go
Expand Up @@ -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()))
}
162 changes: 0 additions & 162 deletions pkg/onboarding/domain/enum_test.go
Expand Up @@ -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)
}
})
}
}
Expand Up @@ -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 ...
Expand Down Expand Up @@ -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)
}
17 changes: 0 additions & 17 deletions pkg/onboarding/infrastructure/services/engagement/service.go
Expand Up @@ -39,8 +39,6 @@ const (
VerifyOTPEndPoint = "internal/verify_otp/"

sendSMS = "internal/send_sms"

temporaryPIN = "internal/send_temporary_pin"
)

// ServiceEngagement represents engagement usecases
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Up @@ -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)
}
})
}
}
6 changes: 0 additions & 6 deletions pkg/onboarding/presentation/graph/enums.graphql
Expand Up @@ -174,9 +174,3 @@ enum PermissionGroup {
Consumers
Patients
}

enum Channel {
WhatsApp
SMS
Email
}

0 comments on commit bc29793

Please sign in to comment.