Skip to content

Commit

Permalink
Merge pull request #16 from savannahghi/update-activate-subscriptions…
Browse files Browse the repository at this point in the history
…-api-endpoint

Feat: Update Activate Subscriber API Endpoint
  • Loading branch information
Muchogoc committed Aug 11, 2023
2 parents 9c4d5b5 + 0c0e4f5 commit 76a5e46
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,17 @@ func (l CommsLib) SendPremiumSMS(ctx context.Context, message, msisdn, subscript
// ActivateSubscription is used activate a subscription to an offer on SILCOMMS.
// msisdn - phone number to be to activate a subscription to an offer.
// offer - offercode used to create a subscription.
func (l CommsLib) ActivateSubscription(ctx context.Context, offer string, msisdn string) (bool, error) {
// activate - boolean value to determine whether activation should happen on SDP
func (l CommsLib) ActivateSubscription(ctx context.Context, offer string, msisdn string, activate bool) (bool, error) {
path := "/v1/sms/subscriptions/"
payload := struct {
Offer string `json:"offer"`
Msisdn string `json:"msisdn"`
Activate bool `json:"activate"`
}{
Offer: offer,
Msisdn: msisdn,
Activate: activate,
}

response, err := l.client.MakeRequest(ctx, http.MethodPost, path, nil, payload, true)
Expand Down
28 changes: 27 additions & 1 deletion sms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func TestSILCommsLib_ActivateSubscription(t *testing.T) {
ctx context.Context
offer string
msisdn string
activate bool
}
tests := []struct {
name string
Expand All @@ -272,6 +273,16 @@ func TestSILCommsLib_ActivateSubscription(t *testing.T) {
},
wantErr: false,
},
{
name: "Happy case: activate subscription bypass sdp",
args: args{
ctx: ctx,
offer: "01262626626",
msisdn: gofakeit.Phone(),
activate: false,
},
wantErr: false,
},
{
name: "Sad case: invalid status code",
args: args{
Expand Down Expand Up @@ -305,13 +316,28 @@ func TestSILCommsLib_ActivateSubscription(t *testing.T) {
})
}

if tt.name == "Happy case: activate subscription bypass sdp" {
httpmock.RegisterResponder(http.MethodPost, fmt.Sprintf("%s/v1/sms/subscriptions/", silcomms.BaseURL), func(r *http.Request) (*http.Response, error) {
resp := silcomms.APIResponse{
Status: silcomms.StatusSuccess,
Message: "success",
Data: map[string]interface{}{
"guid": "123456",
"offer": "123456",
"msisdn": "123456",
},
}
return httpmock.NewJsonResponse(http.StatusOK, resp)
})
}

if tt.name == "Sad case: invalid status code" {
httpmock.RegisterResponder(http.MethodPost, fmt.Sprintf("%s/v1/sms/subscriptions/", silcomms.BaseURL), func(r *http.Request) (*http.Response, error) {
return httpmock.NewJsonResponse(http.StatusUnauthorized, nil)
})
}

got, err := l.ActivateSubscription(tt.args.ctx, tt.args.offer, tt.args.msisdn)
got, err := l.ActivateSubscription(tt.args.ctx, tt.args.offer, tt.args.msisdn, tt.args.activate)
if (err != nil) != tt.wantErr {
t.Errorf("SILCommsLib.ActivateSubscription() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit 76a5e46

Please sign in to comment.