Fix CreateInviteLink;EditInviteLink;RevokeInviteLink functions. Add tests.

pull/436/head
shindakioku 3 years ago
parent 3f7ecbd8a8
commit ad5b4c3f8a

@ -6,6 +6,11 @@ import (
"time"
)
// ChatInviteLinkResult object represents an invite for a chat
type ChatInviteLinkResult struct {
Result ChatInviteLink `json:"result"`
}
// ChatInviteLink object represents an invite for a chat.
type ChatInviteLink struct {
// The invite link.

@ -1703,12 +1703,12 @@ func (b *Bot) CreateInviteLink(chat *Chat, link *ChatInviteLink) (*ChatInviteLin
return nil, err
}
var resp ChatInviteLink
var resp ChatInviteLinkResult
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp, nil
return &resp.Result, nil
}
// EditInviteLink edits a non-primary invite link created by the bot.
@ -1727,19 +1727,19 @@ func (b *Bot) EditInviteLink(chat *Chat, link *ChatInviteLink) (*ChatInviteLink,
return nil, err
}
var resp ChatInviteLink
var resp ChatInviteLinkResult
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp, nil
return &resp.Result, nil
}
// RevokeInviteLink revokes an invite link created by the bot.
func (b *Bot) RevokeInviteLink(chat *Chat, link string) (*ChatInviteLink, error) {
params := map[string]string{
"chat_id": chat.Recipient(),
"link": link,
"invite_link": link,
}
data, err := b.Raw("revokeChatInviteLink", params)
@ -1747,10 +1747,10 @@ func (b *Bot) RevokeInviteLink(chat *Chat, link string) (*ChatInviteLink, error)
return nil, err
}
var resp ChatInviteLink
var resp ChatInviteLinkResult
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp, nil
return &resp.Result, nil
}

@ -480,4 +480,30 @@ func TestBot(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, orig, cmds)
})
t.Run("CreateInviteLink", func(t *testing.T) {
inviteLink, err := b.CreateInviteLink(&Chat{ID: chatID}, nil)
assert.Nil(t, err)
assert.True(t, len(inviteLink.InviteLink) > 0)
})
t.Run("EditInviteLink", func(t *testing.T) {
inviteLink, err := b.CreateInviteLink(&Chat{ID: chatID}, nil)
assert.Nil(t, err)
assert.True(t, len(inviteLink.InviteLink) > 0)
response, err := b.EditInviteLink(&Chat{ID: chatID}, &ChatInviteLink{InviteLink: inviteLink.InviteLink})
assert.Nil(t, err)
assert.True(t, len(response.InviteLink) > 0)
})
t.Run("RevokeInviteLink", func(t *testing.T) {
inviteLink, err := b.CreateInviteLink(&Chat{ID: chatID}, nil)
assert.Nil(t, err)
assert.True(t, len(inviteLink.InviteLink) > 0)
response, err := b.RevokeInviteLink(&Chat{ID: chatID}, inviteLink.InviteLink)
assert.Nil(t, err)
assert.True(t, len(response.InviteLink) > 0)
})
}

Loading…
Cancel
Save