Skip to content

Commit

Permalink
Merge pull request #501 from FelixTing/issue-500
Browse files Browse the repository at this point in the history
fix(v2): Refine the ReplaceSubscriptionModelFieldsWithDTO func
  • Loading branch information
cloudxxx8 authored Feb 9, 2021
2 parents 32bd43a + 5f87525 commit 69eff89
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions v2/dtos/requests/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func ReplaceSubscriptionModelFieldsWithDTO(s *models.Subscription, patch dtos.Up
if patch.Receiver != nil {
s.Receiver = *patch.Receiver
}
if patch.ResendLimit != nil {
s.ResendLimit = *patch.ResendLimit
}
if patch.ResendInterval != nil {
s.ResendInterval = *patch.ResendInterval
}
}

func NewAddSubscriptionRequest(dto dtos.Subscription) AddSubscriptionRequest {
Expand Down
18 changes: 18 additions & 0 deletions v2/dtos/requests/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,21 @@ func TestUpdateSubscriptionRequest_UnmarshalJSON(t *testing.T) {
})
}
}

func TestReplaceSubscriptionModelFieldsWithDTO(t *testing.T) {
subscription := models.Subscription{
Id: "7a1707f0-166f-4c4b-bc9d-1d54c74e0137",
Name: "name",
}
patch := updateSubscriptionData()

ReplaceSubscriptionModelFieldsWithDTO(&subscription, patch)

assert.Equal(t, dtos.ToCategoryModels(testSubscriptionCategories), subscription.Categories)
assert.Equal(t, testSubscriptionLabels, subscription.Labels)
assert.Equal(t, dtos.ToChannelModels(testSubscriptionChannels), subscription.Channels)
assert.Equal(t, testSubscriptionDescription, subscription.Description)
assert.Equal(t, testSubscriptionReceiver, subscription.Receiver)
assert.Equal(t, testSubscriptionResendLimit, subscription.ResendLimit)
assert.Equal(t, testSubscriptionResendInterval, subscription.ResendInterval)
}

0 comments on commit 69eff89

Please sign in to comment.