Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed SubscriberApi.UpdatePreferences #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions lib/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ const (
)

const (
EMAIL ChannelType = "EMAIL"
SMS ChannelType = "SMS"
DIRECT ChannelType = "DIRECT"
INAPP ChannelType = "in_app"
EMAIL ChannelType = "email"
SMS ChannelType = "sms"
CHAT ChannelType = "chat"
PUSH ChannelType = "push"
)

const (
Expand Down Expand Up @@ -157,11 +159,11 @@ type Preference struct {
}

type Channel struct {
Email bool `json:"email"`
Sms bool `json:"sms"`
Chat bool `json:"chat"`
InApp bool `json:"in_app"`
Push bool `json:"push"`
Email *bool `json:"email,omitempty"`
Sms *bool `json:"sms,omitempty"`
Chat *bool `json:"chat,omitempty"`
InApp *bool `json:"in_app,omitempty"`
Push *bool `json:"push,omitempty"`
}

type SubscriberPreferencesResponse struct {
Expand All @@ -171,14 +173,21 @@ type SubscriberPreferencesResponse struct {
} `json:"data"`
}

type UpdateSubscriberPreferencesResponse struct {
Data struct {
Template Template `json:"template"`
Preference Preference `json:"preference"`
} `json:"data"`
}

type UpdateSubscriberPreferencesChannel struct {
Type ChannelType `json:"type"`
Enabled bool `json:"enabled"`
}

type UpdateSubscriberPreferencesOptions struct {
Channel []UpdateSubscriberPreferencesChannel `json:"channel,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Channel *UpdateSubscriberPreferencesChannel `json:"channel,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}

type ListTopicsResponse struct {
Expand Down
6 changes: 3 additions & 3 deletions lib/subscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ISubscribers interface {
GetUnseenCount(ctx context.Context, subscriberID string, opts *SubscriberUnseenCountOptions) (*SubscriberUnseenCountResponse, error)
MarkMessageSeen(ctx context.Context, subscriberID string, opts SubscriberMarkMessageSeenOptions) (*SubscriberNotificationFeedResponse, error)
GetPreferences(ctx context.Context, subscriberID string) (*SubscriberPreferencesResponse, error)
UpdatePreferences(ctx context.Context, subscriberID string, templateId string, opts *UpdateSubscriberPreferencesOptions) (*SubscriberPreferencesResponse, error)
UpdatePreferences(ctx context.Context, subscriberID string, templateId string, opts *UpdateSubscriberPreferencesOptions) (*UpdateSubscriberPreferencesResponse, error)
}

type SubscriberService service
Expand Down Expand Up @@ -234,8 +234,8 @@ func (s *SubscriberService) GetUnseenCount(ctx context.Context, subscriberID str
return &resp, nil
}

func (s *SubscriberService) UpdatePreferences(ctx context.Context, subscriberID string, templateId string, opts *UpdateSubscriberPreferencesOptions) (*SubscriberPreferencesResponse, error) {
var resp SubscriberPreferencesResponse
func (s *SubscriberService) UpdatePreferences(ctx context.Context, subscriberID string, templateId string, opts *UpdateSubscriberPreferencesOptions) (*UpdateSubscriberPreferencesResponse, error) {
var resp UpdateSubscriberPreferencesResponse
URL := s.client.config.BackendURL.JoinPath("subscribers", subscriberID, "preferences", templateId)

var reqBody io.Reader = http.NoBody
Expand Down
11 changes: 5 additions & 6 deletions lib/subscribers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,12 @@ func TestSubscriberService_UpdatePreferences_Success(t *testing.T) {
var expectedResponse *lib.SubscriberPreferencesResponse
fileToStruct(filepath.Join("../testdata", "subscriber_preferences_response.json"), &expectedResponse)

enabled := true
var opts *lib.UpdateSubscriberPreferencesOptions = &lib.UpdateSubscriberPreferencesOptions{
Enabled: true,
Channel: []lib.UpdateSubscriberPreferencesChannel{
{
Type: "email",
Enabled: true,
},
Enabled: &enabled,
Channel: &lib.UpdateSubscriberPreferencesChannel{
Type: "email",
Enabled: true,
},
}
httpServer := createTestServer(t, TestServerOptions[*lib.UpdateSubscriberPreferencesOptions, *lib.SubscriberPreferencesResponse]{
Expand Down