Update ChannelSettings (#37)

This commit is contained in:
Alexander Kulinich 2021-02-03 14:27:53 +03:00 committed by GitHub
parent 859d4c2d06
commit a1ee703fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 162 additions and 16 deletions

View File

@ -86,21 +86,123 @@ func TestMgClient_Channels(t *testing.T) {
gock.New(mgURL). gock.New(mgURL).
Get("/api/bot/v1/channels"). Get("/api/bot/v1/channels").
Reply(200). Reply(200).
BodyString(`[{"id": 1, "type":"test_type", "name": "Test Bot", "created_at": "2018-01-01T00:00:00.000000Z", "is_active": true}]`) BodyString(`[
{
req := ChannelsRequest{Active: 1} "id": 1,
"type": "custom",
data, status, err := c.Channels(req) "name": "Test custom channel",
if err != nil { "settings": {
t.Errorf("%d %v", status, err) "customer_external_id": "phone",
} "sending_policy": {
"new_customer": "no",
"after_reply_timeout": "template"
},
"status": {
"delivered": "both",
"read": "receive"
},
"text": {
"creating": "both",
"editing": "receive",
"quoting": "send",
"deleting": "receive",
"max_chars_count": 777
},
"product": {
"creating": "receive",
"editing": "receive",
"deleting": "receive"
},
"order": {
"creating": "receive",
"editing": "receive",
"deleting": "receive"
},
"image": {
"creating": "both",
"quoting": "receive",
"editing": "none",
"deleting": "receive",
"max_items_count": 1,
"note_max_chars_count": 777
},
"file": {
"creating": "both",
"quoting": "receive",
"editing": "none",
"deleting": "receive",
"max_items_count": 1,
"note_max_chars_count": 777
},
"suggestions": {
"text": "receive",
"email": "receive",
"phone": "receive"
}
},
"created_at": "2018-01-01T00:00:00.000000Z",
"updated_at": null,
"activated_at": "2018-01-01T00:00:00.000000Z",
"deactivated_at": null,
"is_active": true
}
]`)
channels, status, err := c.Channels(ChannelsRequest{Active: 1})
assert.NoError(t, err) assert.NoError(t, err)
assert.NotEmpty(t, data) assert.Equal(t, 200, status)
assert.Len(t, channels, 1)
for _, channel := range data { ch := channels[0]
assert.NotEmpty(t, channel.Type) assert.Equal(t, uint64(1), ch.ID)
} assert.Equal(t, ChannelTypeCustom, ch.Type)
assert.Equal(t, "Test custom channel", ch.Name)
assert.Equal(t, "2018-01-01T00:00:00.000000Z", ch.CreatedAt)
assert.Empty(t, ch.UpdatedAt)
assert.Equal(t, "2018-01-01T00:00:00.000000Z", ch.ActivatedAt)
assert.Empty(t, ch.DeactivatedAt)
assert.True(t, ch.IsActive)
chs := ch.Settings
assert.Equal(t, "phone", chs.CustomerExternalID)
assert.Equal(t, "no", chs.SendingPolicy.NewCustomer)
assert.Equal(t, "template", chs.SendingPolicy.AfterReplyTimeout)
assert.Equal(t, ChannelFeatureBoth, chs.Status.Delivered)
assert.Equal(t, ChannelFeatureReceive, chs.Status.Read)
assert.Equal(t, ChannelFeatureBoth, chs.Text.Creating)
assert.Equal(t, ChannelFeatureReceive, chs.Text.Editing)
assert.Equal(t, ChannelFeatureSend, chs.Text.Quoting)
assert.Equal(t, ChannelFeatureReceive, chs.Text.Deleting)
assert.Equal(t, uint16(777), chs.Text.MaxCharsCount)
assert.Equal(t, ChannelFeatureReceive, chs.Product.Creating)
assert.Equal(t, ChannelFeatureReceive, chs.Product.Editing)
assert.Equal(t, ChannelFeatureReceive, chs.Product.Deleting)
assert.Equal(t, ChannelFeatureReceive, chs.Order.Creating)
assert.Equal(t, ChannelFeatureReceive, chs.Order.Editing)
assert.Equal(t, ChannelFeatureReceive, chs.Order.Deleting)
assert.Equal(t, ChannelFeatureBoth, chs.Image.Creating)
assert.Equal(t, ChannelFeatureNone, chs.Image.Editing)
assert.Equal(t, ChannelFeatureReceive, chs.Image.Quoting)
assert.Equal(t, ChannelFeatureReceive, chs.Image.Deleting)
assert.Equal(t, 1, chs.Image.MaxItemsCount)
assert.Equal(t, uint16(777), chs.Image.NoteMaxCharsCount)
assert.Equal(t, ChannelFeatureBoth, chs.File.Creating)
assert.Equal(t, ChannelFeatureNone, chs.File.Editing)
assert.Equal(t, ChannelFeatureReceive, chs.File.Quoting)
assert.Equal(t, ChannelFeatureReceive, chs.File.Deleting)
assert.Equal(t, 1, chs.File.MaxItemsCount)
assert.Equal(t, uint16(777), chs.File.NoteMaxCharsCount)
assert.Equal(t, ChannelFeatureReceive, chs.Suggestions.Text)
assert.Equal(t, ChannelFeatureReceive, chs.Suggestions.Email)
assert.Equal(t, ChannelFeatureReceive, chs.Suggestions.Phone)
} }
func TestMgClient_Users(t *testing.T) { func TestMgClient_Users(t *testing.T) {

View File

@ -573,16 +573,28 @@ type (
// Channel settings // Channel settings
type ( type (
CRUDChannelSettings struct {
Creating string `json:"creating"` // none, receive, send, both
Editing string `json:"editing"` // none, receive, send, both
Deleting string `json:"deleting"` // none, receive, send, both
}
ChannelSettingsText struct { ChannelSettingsText struct {
Creating string `json:"creating"` CRUDChannelSettings
Editing string `json:"editing"` Quoting string `json:"quoting"` // none, receive, send, both
Quoting string `json:"quoting"` MaxCharsCount uint16 `json:"max_chars_count"`
Deleting string `json:"deleting"`
} }
ChannelSettings struct { ChannelSettings struct {
SpamAllowed bool `json:"spam_allowed"` SpamAllowed bool `json:"spam_allowed"`
CustomerExternalID string `json:"customer_external_id"`
SendingPolicy struct {
NewCustomer string `json:"new_customer"`
AfterReplyTimeout string `json:"after_reply_timeout"`
} `json:"sending_policy"`
Status struct { Status struct {
Delivered string `json:"delivered"` Delivered string `json:"delivered"`
Read string `json:"read"` Read string `json:"read"`
@ -590,6 +602,38 @@ type (
Text ChannelSettingsText `json:"text"` Text ChannelSettingsText `json:"text"`
Product struct {
CRUDChannelSettings
} `json:"product"`
Order struct {
CRUDChannelSettings
} `json:"order"`
Image struct {
CRUDChannelSettings
Quoting string `json:"quoting"`
MaxItemsCount int `json:"max_items_count"`
NoteMaxCharsCount uint16 `json:"note_max_chars_count"`
} `json:"image"`
File struct {
CRUDChannelSettings
Quoting string `json:"quoting"`
MaxItemsCount int `json:"max_items_count"`
NoteMaxCharsCount uint16 `json:"note_max_chars_count"`
} `json:"file"`
Audio struct {
Creating string `json:"creating"`
Quoting string `json:"quoting"`
Deleting string `json:"deleting"`
MaxItemsCount int `json:"max_items_count"`
} `json:"audio"`
Suggestions struct { Suggestions struct {
Text string `json:"text"` Text string `json:"text"`
Phone string `json:"phone"` Phone string `json:"phone"`