From a1ee703fa5e7ba5804617726e27b2ed51879dae1 Mon Sep 17 00:00:00 2001 From: Alexander Kulinich Date: Wed, 3 Feb 2021 14:27:53 +0300 Subject: [PATCH] Update ChannelSettings (#37) --- v1/client_test.go | 126 +++++++++++++++++++++++++++++++++++++++++----- v1/types.go | 52 +++++++++++++++++-- 2 files changed, 162 insertions(+), 16 deletions(-) diff --git a/v1/client_test.go b/v1/client_test.go index 28eb454..4ce0457 100644 --- a/v1/client_test.go +++ b/v1/client_test.go @@ -86,21 +86,123 @@ func TestMgClient_Channels(t *testing.T) { gock.New(mgURL). Get("/api/bot/v1/channels"). Reply(200). - BodyString(`[{"id": 1, "type":"test_type", "name": "Test Bot", "created_at": "2018-01-01T00:00:00.000000Z", "is_active": true}]`) - - req := ChannelsRequest{Active: 1} - - data, status, err := c.Channels(req) - if err != nil { - t.Errorf("%d %v", status, err) - } + BodyString(`[ + { + "id": 1, + "type": "custom", + "name": "Test custom channel", + "settings": { + "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.NotEmpty(t, data) + assert.Equal(t, 200, status) + assert.Len(t, channels, 1) - for _, channel := range data { - assert.NotEmpty(t, channel.Type) - } + ch := channels[0] + 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) { diff --git a/v1/types.go b/v1/types.go index 1773a02..68d0533 100644 --- a/v1/types.go +++ b/v1/types.go @@ -573,16 +573,28 @@ type ( // Channel settings 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 { - Creating string `json:"creating"` - Editing string `json:"editing"` - Quoting string `json:"quoting"` - Deleting string `json:"deleting"` + CRUDChannelSettings + Quoting string `json:"quoting"` // none, receive, send, both + MaxCharsCount uint16 `json:"max_chars_count"` } ChannelSettings struct { 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 { Delivered string `json:"delivered"` Read string `json:"read"` @@ -590,6 +602,38 @@ type ( 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 { Text string `json:"text"` Phone string `json:"phone"`