Skip to content

Commit

Permalink
Change the data structure of chat response according to the updates f…
Browse files Browse the repository at this point in the history
…rom Ozon (#102)
  • Loading branch information
Pireirik authored Sep 9, 2024
1 parent ccd3610 commit 895ef8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
25 changes: 10 additions & 15 deletions ozon/chats.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ListChatsResponse struct {
core.CommonResponse

// Chats data
Chats []ListChatsChat `json:"chats"`
Chats []ListChatsChatData `json:"chats"`

// Total number of chats
TotalChatsCount int64 `json:"total_chats_count"`
Expand All @@ -48,20 +48,6 @@ type ListChatsResponse struct {
TotalUnreadCount int64 `json:"total_unread_count"`
}

type ListChatsChat struct {
// Chat data
Chat ListChatsChatData `json:"chat"`

// Identifier of the first unread chat message
FirstUnreadMessageId uint64 `json:"first_unread_message_id"`

// Identifier of the last message in the chat
LastMessageId uint64 `json:"last_message_id"`

// Number of unread messages in the chat
UnreadCount int64 `json:"unread_count"`
}

type ListChatsChatData struct {
// Chat identifier
ChatId string `json:"chat_id"`
Expand All @@ -79,6 +65,15 @@ type ListChatsChatData struct {

// Chat creation date
CreatedAt time.Time `json:"created_at"`

// Identifier of the first unread chat message
FirstUnreadMessageId uint64 `json:"first_unread_message_id"`

// Identifier of the last message in the chat
LastMessageId uint64 `json:"last_message_id"`

// Number of unread messages in the chat
UnreadCount int64 `json:"unread_count"`
}

// Returns information about chats by specified filters
Expand Down
20 changes: 9 additions & 11 deletions ozon/chats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ func TestListChats(t *testing.T) {
`{
"chats": [
{
"chat": {
"created_at": "2022-07-22T08:07:19.581Z",
"chat_id": "5e767w03-b400-4y1b-a841-75319ca8a5c8",
"chat_status": "Opened",
"chat_type": "Seller_Support"
},
"first_unread_message_id": 3000000000118021931,
"last_message_id": 3000000000128004274,
"unread_count": 1
"chat_id": "5e767w03-b400-4y1b-a841-75319ca8a5c8",
"chat_status": "Opened",
"chat_type": "Seller_Support",
"created_at": "2022-07-22T08:07:19.581Z",
"unread_count": 1,
"last_message_id": 3000000000128004274,
"first_unread_message_id": 3000000000118021931
}
],
"total_chats_count": 25,
Expand Down Expand Up @@ -77,10 +75,10 @@ func TestListChats(t *testing.T) {

if resp.StatusCode == http.StatusOK {
if len(resp.Chats) > 0 {
if resp.Chats[0].Chat.ChatStatus == "" {
if resp.Chats[0].ChatStatus == "" {
t.Errorf("Chat status cannot be empty")
}
if resp.Chats[0].Chat.ChatType == "" {
if resp.Chats[0].ChatType == "" {
t.Errorf("Chat type cannot be empty")
}
}
Expand Down

0 comments on commit 895ef8b

Please sign in to comment.